Search in sources :

Example 1 with IMixinWorldSettings

use of org.spongepowered.common.interfaces.world.IMixinWorldSettings in project SpongeCommon by SpongePowered.

the class SpongeWorldArchetypeBuilder method build.

@Override
public WorldArchetype build(String id, String name) throws IllegalArgumentException, CatalogTypeAlreadyRegisteredException {
    WorldArchetypeRegistryModule.getInstance().getById(id).ifPresent(w -> {
        throw new CatalogTypeAlreadyRegisteredException(id);
    });
    final WorldSettings settings = new WorldSettings(this.seed, (GameType) (Object) this.gameMode, this.mapFeaturesEnabled, this.hardcore, (WorldType) this.generatorType);
    IMixinWorldSettings spongeSettings = (IMixinWorldSettings) (Object) settings;
    spongeSettings.setId(id);
    spongeSettings.setName(name);
    spongeSettings.setDimensionType(this.dimensionType);
    spongeSettings.setDifficulty(this.difficulty);
    spongeSettings.setSerializationBehavior(this.serializationBehavior);
    spongeSettings.setGeneratorSettings(this.generatorSettings);
    spongeSettings.setGeneratorModifiers(this.generatorModifiers);
    spongeSettings.setEnabled(this.worldEnabled);
    spongeSettings.setLoadOnStartup(this.loadOnStartup);
    spongeSettings.setKeepSpawnLoaded(this.keepSpawnLoaded);
    spongeSettings.setGenerateSpawnOnLoad(this.generateSpawnOnLoad);
    spongeSettings.setPVPEnabled(this.pvpEnabled);
    spongeSettings.setCommandsAllowed(this.commandsAllowed);
    spongeSettings.setGenerateBonusChest(this.generateBonusChest);
    spongeSettings.fromBuilder(true);
    spongeSettings.setPortalAgentType(this.portalAgentType);
    spongeSettings.setRandomSeed(this.seedRandomized);
    SpongeImpl.getRegistry().register(WorldArchetype.class, (WorldArchetype) (Object) settings);
    return (WorldArchetype) (Object) settings;
}
Also used : WorldArchetype(org.spongepowered.api.world.WorldArchetype) IMixinWorldSettings(org.spongepowered.common.interfaces.world.IMixinWorldSettings) WorldSettings(net.minecraft.world.WorldSettings) IMixinWorldSettings(org.spongepowered.common.interfaces.world.IMixinWorldSettings) CatalogTypeAlreadyRegisteredException(org.spongepowered.api.registry.CatalogTypeAlreadyRegisteredException)

Example 2 with IMixinWorldSettings

use of org.spongepowered.common.interfaces.world.IMixinWorldSettings in project SpongeForge by SpongePowered.

the class MixinDimensionManager method initDimension.

/**
 * @author Zidane - June 2nd, 2016
 * @reason Forge's initDimension is very different from Sponge's multi-world. We basically rig it into our system so mods work.
 * @param dim The dimension to load
 */
@Overwrite
public static void initDimension(int dim) {
    // World is already loaded, bail
    if (WorldManager.getWorldByDimensionId(dim).isPresent()) {
        return;
    }
    if (dim == 0) {
        throw new RuntimeException("Attempt made to initialize overworld!");
    }
    WorldManager.getWorldByDimensionId(0).orElseThrow(() -> new RuntimeException("Attempt made to initialize " + "dimension before overworld is loaded!"));
    DimensionType dimensionType = WorldManager.getDimensionType(dim).orElse(null);
    if (dimensionType == null) {
        SpongeImpl.getLogger().warn("Attempt made to initialize dimension id {} which isn't registered!" + ", falling back to overworld.", dim);
        return;
    }
    final WorldProvider provider = dimensionType.createDimension();
    // make sure to set the dimension id to avoid getting a null save folder
    provider.setDimension(dim);
    String worldFolder = WorldManager.getWorldFolderByDimensionId(dim).orElse(provider.getSaveFolder());
    WorldProperties properties = WorldManager.getWorldProperties(worldFolder).orElse(null);
    final Path worldPath = WorldManager.getCurrentSavesDirectory().get().resolve(worldFolder);
    if (properties == null || !Files.isDirectory(worldPath)) {
        if (properties != null) {
            WorldManager.unregisterWorldProperties(properties, false);
        }
        String modId = StaticMixinForgeHelper.getModIdFromClass(provider.getClass());
        WorldArchetype archetype = Sponge.getRegistry().getType(WorldArchetype.class, modId + ":" + dimensionType.getName().toLowerCase()).orElse(null);
        if (archetype == null) {
            final WorldArchetype.Builder builder = WorldArchetype.builder().dimension((org.spongepowered.api.world.DimensionType) (Object) dimensionType).keepsSpawnLoaded(dimensionType.shouldLoadSpawn());
            archetype = builder.build(modId + ":" + dimensionType.getName().toLowerCase(), dimensionType.getName());
        }
        IMixinWorldSettings worldSettings = (IMixinWorldSettings) archetype;
        worldSettings.setDimensionType((org.spongepowered.api.world.DimensionType) (Object) dimensionType);
        worldSettings.setLoadOnStartup(false);
        properties = WorldManager.createWorldProperties(worldFolder, archetype, dim);
        ((IMixinWorldInfo) properties).setDimensionId(dim);
        ((IMixinWorldInfo) properties).setIsMod(true);
    }
    if (!properties.isEnabled()) {
        return;
    }
    Optional<WorldServer> optWorld = WorldManager.loadWorld(properties);
    if (!optWorld.isPresent()) {
        SpongeImpl.getLogger().error("Could not load world [{}]!", properties.getWorldName());
    }
}
Also used : Path(java.nio.file.Path) DimensionType(net.minecraft.world.DimensionType) IMixinWorldInfo(org.spongepowered.common.interfaces.world.IMixinWorldInfo) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) WorldServer(net.minecraft.world.WorldServer) WorldArchetype(org.spongepowered.api.world.WorldArchetype) WorldProvider(net.minecraft.world.WorldProvider) IMixinWorldSettings(org.spongepowered.common.interfaces.world.IMixinWorldSettings) WorldProperties(org.spongepowered.api.world.storage.WorldProperties) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 3 with IMixinWorldSettings

use of org.spongepowered.common.interfaces.world.IMixinWorldSettings in project SpongeCommon by SpongePowered.

the class WorldManager method createWorldInfoFromSettings.

public static WorldInfo createWorldInfoFromSettings(Path currentSaveRoot, org.spongepowered.api.world.DimensionType dimensionType, int dimensionId, String worldFolderName, WorldSettings worldSettings, String generatorOptions) {
    final MinecraftServer server = SpongeImpl.getServer();
    worldSettings.setGeneratorOptions(generatorOptions);
    ((IMixinWorldSettings) (Object) worldSettings).setDimensionType(dimensionType);
    ((IMixinWorldSettings) (Object) worldSettings).setGenerateSpawnOnLoad(((IMixinDimensionType) dimensionType).shouldGenerateSpawnOnLoad());
    final WorldInfo worldInfo = new WorldInfo(worldSettings, worldFolderName);
    setUuidOnProperties(dimensionId == 0 ? currentSaveRoot.getParent() : currentSaveRoot, (WorldProperties) worldInfo);
    ((IMixinWorldInfo) worldInfo).setDimensionId(dimensionId);
    SpongeImpl.postEvent(SpongeEventFactory.createConstructWorldPropertiesEvent(Sponge.getCauseStackManager().getCurrentCause(), (WorldArchetype) (Object) worldSettings, (WorldProperties) worldInfo));
    return worldInfo;
}
Also used : WorldArchetype(org.spongepowered.api.world.WorldArchetype) IMixinWorldInfo(org.spongepowered.common.interfaces.world.IMixinWorldInfo) WorldInfo(net.minecraft.world.storage.WorldInfo) IMixinWorldInfo(org.spongepowered.common.interfaces.world.IMixinWorldInfo) IMixinWorldSettings(org.spongepowered.common.interfaces.world.IMixinWorldSettings) WorldProperties(org.spongepowered.api.world.storage.WorldProperties) IMixinMinecraftServer(org.spongepowered.common.interfaces.IMixinMinecraftServer) MinecraftServer(net.minecraft.server.MinecraftServer)

Aggregations

WorldArchetype (org.spongepowered.api.world.WorldArchetype)3 IMixinWorldSettings (org.spongepowered.common.interfaces.world.IMixinWorldSettings)3 WorldProperties (org.spongepowered.api.world.storage.WorldProperties)2 IMixinWorldInfo (org.spongepowered.common.interfaces.world.IMixinWorldInfo)2 Path (java.nio.file.Path)1 MinecraftServer (net.minecraft.server.MinecraftServer)1 DimensionType (net.minecraft.world.DimensionType)1 WorldProvider (net.minecraft.world.WorldProvider)1 WorldServer (net.minecraft.world.WorldServer)1 WorldSettings (net.minecraft.world.WorldSettings)1 WorldInfo (net.minecraft.world.storage.WorldInfo)1 CatalogTypeAlreadyRegisteredException (org.spongepowered.api.registry.CatalogTypeAlreadyRegisteredException)1 Overwrite (org.spongepowered.asm.mixin.Overwrite)1 IMixinMinecraftServer (org.spongepowered.common.interfaces.IMixinMinecraftServer)1 IMixinWorldServer (org.spongepowered.common.interfaces.world.IMixinWorldServer)1