Search in sources :

Example 1 with ServerWorldEventHandler

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;
}
Also used : IMixinMinecraftServer(org.spongepowered.common.interfaces.IMixinMinecraftServer) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) WorldServer(net.minecraft.world.WorldServer) ServerWorldEventHandler(net.minecraft.world.ServerWorldEventHandler) IMixinWorld(org.spongepowered.common.interfaces.world.IMixinWorld) World(net.minecraft.world.World) IMixinChunkProviderServer(org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer) IMixinMinecraftServer(org.spongepowered.common.interfaces.IMixinMinecraftServer) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 2 with ServerWorldEventHandler

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());
}
Also used : ISaveHandler(net.minecraft.world.storage.ISaveHandler) WorldEvent(net.minecraftforge.event.world.WorldEvent) WorldServer(net.minecraft.world.WorldServer) ServerWorldEventHandler(net.minecraft.world.ServerWorldEventHandler) MinecraftException(net.minecraft.world.MinecraftException) WorldServerMulti(net.minecraft.world.WorldServerMulti) MinecraftServer(net.minecraft.server.MinecraftServer)

Aggregations

MinecraftServer (net.minecraft.server.MinecraftServer)2 ServerWorldEventHandler (net.minecraft.world.ServerWorldEventHandler)2 WorldServer (net.minecraft.world.WorldServer)2 MinecraftException (net.minecraft.world.MinecraftException)1 World (net.minecraft.world.World)1 WorldServerMulti (net.minecraft.world.WorldServerMulti)1 ISaveHandler (net.minecraft.world.storage.ISaveHandler)1 WorldEvent (net.minecraftforge.event.world.WorldEvent)1 IMixinMinecraftServer (org.spongepowered.common.interfaces.IMixinMinecraftServer)1 IMixinWorld (org.spongepowered.common.interfaces.world.IMixinWorld)1 IMixinWorldServer (org.spongepowered.common.interfaces.world.IMixinWorldServer)1 IMixinChunkProviderServer (org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer)1