use of net.minecraft.world.ServerWorldEventHandler in project SpongeCommon by SpongePowered.
the class WorldManager method createWorldFromProperties.
private static WorldServer createWorldFromProperties(int dimensionId, ISaveHandler saveHandler, WorldInfo worldInfo, @Nullable WorldSettings worldSettings) {
final MinecraftServer server = SpongeImpl.getServer();
final WorldServer worldServer = new WorldServer(server, saveHandler, worldInfo, dimensionId, server.profiler);
worldServer.init();
// WorldSettings is only non-null here if this is a newly generated WorldInfo and therefore we need to initialize to calculate spawn.
if (worldSettings != null) {
worldServer.initialize(worldSettings);
}
worldServer.addEventListener(new ServerWorldEventHandler(server, worldServer));
// This code changes from Mojang's to account for per-world API-set GameModes.
if (!server.isSinglePlayer() && worldServer.getWorldInfo().getGameType().equals(GameType.NOT_SET)) {
worldServer.getWorldInfo().setGameType(server.getGameType());
}
worldByDimensionId.put(dimensionId, worldServer);
weakWorldByWorld.put(worldServer, worldServer);
((IMixinMinecraftServer) SpongeImpl.getServer()).putWorldTickTimes(dimensionId, new long[100]);
((IMixinChunkProviderServer) worldServer.getChunkProvider()).setForceChunkRequests(true);
WorldManager.reorderWorldsVanillaFirst();
SpongeImpl.postEvent(SpongeEventFactory.createLoadWorldEvent(Sponge.getCauseStackManager().getCurrentCause(), (org.spongepowered.api.world.World) worldServer));
((IMixinMinecraftServer) server).prepareSpawnArea(worldServer);
((IMixinChunkProviderServer) worldServer.getChunkProvider()).setForceChunkRequests(false);
return worldServer;
}
use of net.minecraft.world.ServerWorldEventHandler in project MinecraftForge by MinecraftForge.
the class DimensionManager method initDimension.
public static void initDimension(int dim) {
WorldServer overworld = getWorld(0);
if (overworld == null) {
throw new RuntimeException("Cannot Hotload Dim: Overworld is not Loaded!");
}
try {
DimensionManager.getProviderType(dim);
} catch (Exception e) {
System.err.println("Cannot Hotload Dim: " + e.getMessage());
// If a provider hasn't been registered then we can't hotload the dim
return;
}
MinecraftServer mcServer = overworld.getMinecraftServer();
ISaveHandler savehandler = overworld.getSaveHandler();
//WorldSettings worldSettings = new WorldSettings(overworld.getWorldInfo());
WorldServer world = (dim == 0 ? overworld : (WorldServer) (new WorldServerMulti(mcServer, savehandler, dim, overworld, mcServer.theProfiler).init()));
world.addEventListener(new ServerWorldEventHandler(mcServer, world));
MinecraftForge.EVENT_BUS.post(new WorldEvent.Load(world));
if (!mcServer.isSinglePlayer()) {
world.getWorldInfo().setGameType(mcServer.getGameType());
}
mcServer.setDifficultyForAllWorlds(mcServer.getDifficulty());
}
Aggregations