Search in sources :

Example 31 with MinecraftServer

use of net.minecraft.server.MinecraftServer in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class ValkyrienWarfareMod method serverStart.

@EventHandler
public void serverStart(FMLServerStartingEvent event) {
    MinecraftServer server = event.getServer();
    ModCommands.registerCommands(server);
}
Also used : MinecraftServer(net.minecraft.server.MinecraftServer) EventHandler(net.minecraftforge.fml.common.Mod.EventHandler)

Example 32 with MinecraftServer

use of net.minecraft.server.MinecraftServer in project VanillaTeleporter by dyeo.

the class TeleporterUtility method transferPlayerToDimension.

/**
	 * Transfers a player to a different dimension and location, as if they were being teleported by a dimension portal
	 */
private static boolean transferPlayerToDimension(EntityPlayerMP player, double posX, double posY, double posZ, float yaw, float pitch, int dimension) {
    MinecraftServer minecraftServer = FMLCommonHandler.instance().getMinecraftServerInstance();
    WorldServer srcWorld = minecraftServer.worldServerForDimension(player.dimension);
    WorldServer dstWorld = minecraftServer.worldServerForDimension(dimension);
    if (dstWorld != null) {
        // fire player change dimension event and check that action is valid before continuing
        if (!net.minecraftforge.common.ForgeHooks.onTravelToDimension(player, dimension))
            return false;
        // (hard) set the player's dimension to the destination dimension
        player.dimension = dimension;
        // send a player respawn packet to the destination dimension so the player respawns there
        player.connection.sendPacket(new SPacketRespawn(player.dimension, player.world.getDifficulty(), player.world.getWorldInfo().getTerrainType(), player.interactionManager.getGameType()));
        // remove the original player entity
        srcWorld.removeEntity(player);
        // make sure the player isn't dead (removeEntity sets player as dead)
        player.isDead = false;
        PlayerList playerList = player.mcServer.getPlayerList();
        // set player's location (net server handler)
        setPlayerPosition(player, posX, posY, posZ, yaw, pitch);
        // spawn the player in the new world
        dstWorld.spawnEntity(player);
        // update the entity (do not force)
        dstWorld.updateEntityWithOptionalForce(player, false);
        // set the player's world to the new world
        player.setWorld(dstWorld);
        // add the player into the appropriate player list
        playerList.preparePlayer(player, srcWorld);
        // set item in world manager's world to the same as the player
        player.interactionManager.setWorld(dstWorld);
        // update time and weather for the player so that it's the same as the world
        playerList.updateTimeAndWeatherForPlayer(player, dstWorld);
        // sync the player's inventory
        playerList.syncPlayerInventory(player);
        // add no experience (syncs experience)
        player.addExperience(0);
        // update player's health
        player.setPlayerHealthUpdated();
        // fire the dimension changed event so that minecraft swithces dimensions properly
        FMLCommonHandler.instance().firePlayerChangedDimensionEvent(player, srcWorld.provider.getDimension(), dstWorld.provider.getDimension());
        return true;
    } else {
        return false;
    }
}
Also used : PlayerList(net.minecraft.server.management.PlayerList) WorldServer(net.minecraft.world.WorldServer) SPacketRespawn(net.minecraft.network.play.server.SPacketRespawn) MinecraftServer(net.minecraft.server.MinecraftServer)

Aggregations

MinecraftServer (net.minecraft.server.MinecraftServer)32 BlockPos (net.minecraft.util.math.BlockPos)13 Template (net.minecraft.world.gen.structure.template.Template)9 PlacementSettings (net.minecraft.world.gen.structure.template.PlacementSettings)8 World (net.minecraft.world.World)6 TemplateManager (net.minecraft.world.gen.structure.template.TemplateManager)6 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)5 Mirror (net.minecraft.util.Mirror)5 Rotation (net.minecraft.util.Rotation)5 WorldServer (net.minecraft.world.WorldServer)5 RCConfig (ivorius.reccomplex.RCConfig)4 RCExpect (ivorius.reccomplex.commands.parameters.RCExpect)4 RCParameters (ivorius.reccomplex.commands.parameters.RCParameters)4 ServerTranslations (ivorius.reccomplex.utils.ServerTranslations)4 List (java.util.List)4 Nullable (javax.annotation.Nullable)4 IBlockState (net.minecraft.block.state.IBlockState)4 CommandBase (net.minecraft.command.CommandBase)4 CommandException (net.minecraft.command.CommandException)4 ICommandSender (net.minecraft.command.ICommandSender)4