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;
}
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());
}
}
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;
}
Aggregations