Java 类net.minecraft.network.play.server.SPacketRespawn 实例源码

项目:harshencastle    文件:HarshenUtils.java   
public static void transferPlayerToDimension(EntityPlayerMP player, int dimensionIn, BlockPos pos, IBlockState state)
{
    int i = player.dimension;
    WorldServer worldserver = player.mcServer.getWorld(player.dimension);
    player.dimension = dimensionIn;
    WorldServer worldserver1 = player.mcServer.getWorld(player.dimension);
    player.connection.sendPacket(new SPacketRespawn(player.dimension, worldserver1.getDifficulty(), worldserver1.getWorldInfo().getTerrainType(), player.interactionManager.getGameType()));
    player.mcServer.getPlayerList().updatePermissionLevel(player);
    worldserver.removeEntityDangerously(player);
    player.isDead = false;
    transferPlayerToWorld(player, i, worldserver, worldserver1, pos, state);
    player.mcServer.getPlayerList().preparePlayer(player, worldserver);
    player.connection.setPlayerLocation(player.posX, player.posY, player.posZ, player.rotationYaw, player.rotationPitch);
    player.interactionManager.setWorld(worldserver1);
    player.connection.sendPacket(new SPacketPlayerAbilities(player.capabilities));
    player.mcServer.getPlayerList().updateTimeAndWeatherForPlayer(player, worldserver1);
    player.mcServer.getPlayerList().syncPlayerInventory(player);

    for (PotionEffect potioneffect : player.getActivePotionEffects())
    {
        player.connection.sendPacket(new SPacketEntityEffect(player.getEntityId(), potioneffect));
    }
    net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerChangedDimensionEvent(player, i, dimensionIn);
}
项目:Zombe-Modpack    文件:NetHandlerPlayClient.java   
public void handleRespawn(SPacketRespawn packetIn)
{
    PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.gameController);

    if (packetIn.getDimensionID() != this.gameController.player.dimension)
    {
        this.doneLoadingTerrain = false;
        Scoreboard scoreboard = this.clientWorldController.getScoreboard();
        this.clientWorldController = new WorldClient(this, new WorldSettings(0L, packetIn.getGameType(), false, this.gameController.world.getWorldInfo().isHardcoreModeEnabled(), packetIn.getWorldType()), packetIn.getDimensionID(), packetIn.getDifficulty(), this.gameController.mcProfiler);
        this.clientWorldController.setWorldScoreboard(scoreboard);
        this.gameController.loadWorld(this.clientWorldController);
        this.gameController.player.dimension = packetIn.getDimensionID();
        this.gameController.displayGuiScreen(new GuiDownloadTerrain(this));
    }

    this.gameController.setDimensionAndSpawnPlayer(packetIn.getDimensionID());
    this.gameController.playerController.setGameType(packetIn.getGameType());
}
项目:Backmemed    文件:NetHandlerPlayClient.java   
public void handleRespawn(SPacketRespawn packetIn)
{
    PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.gameController);

    if (packetIn.getDimensionID() != this.gameController.player.dimension)
    {
        this.doneLoadingTerrain = false;
        Scoreboard scoreboard = this.clientWorldController.getScoreboard();
        this.clientWorldController = new WorldClient(this, new WorldSettings(0L, packetIn.getGameType(), false, this.gameController.world.getWorldInfo().isHardcoreModeEnabled(), packetIn.getWorldType()), packetIn.getDimensionID(), packetIn.getDifficulty(), this.gameController.mcProfiler);
        this.clientWorldController.setWorldScoreboard(scoreboard);
        this.gameController.loadWorld(this.clientWorldController);
        this.gameController.player.dimension = packetIn.getDimensionID();
        this.gameController.displayGuiScreen(new GuiDownloadTerrain(this));
    }

    this.gameController.setDimensionAndSpawnPlayer(packetIn.getDimensionID());
    this.gameController.playerController.setGameType(packetIn.getGameType());
}
项目:Backmemed    文件:PlayerList.java   
public void changePlayerDimension(EntityPlayerMP player, int dimensionIn)
{
    int i = player.dimension;
    WorldServer worldserver = this.mcServer.worldServerForDimension(player.dimension);
    player.dimension = dimensionIn;
    WorldServer worldserver1 = this.mcServer.worldServerForDimension(player.dimension);
    player.connection.sendPacket(new SPacketRespawn(player.dimension, player.world.getDifficulty(), player.world.getWorldInfo().getTerrainType(), player.interactionManager.getGameType()));
    this.updatePermissionLevel(player);
    worldserver.removeEntityDangerously(player);
    player.isDead = false;
    this.transferEntityToWorld(player, i, worldserver, worldserver1);
    this.preparePlayer(player, worldserver);
    player.connection.setPlayerLocation(player.posX, player.posY, player.posZ, player.rotationYaw, player.rotationPitch);
    player.interactionManager.setWorld(worldserver1);
    player.connection.sendPacket(new SPacketPlayerAbilities(player.capabilities));
    this.updateTimeAndWeatherForPlayer(player, worldserver1);
    this.syncPlayerInventory(player);

    for (PotionEffect potioneffect : player.getActivePotionEffects())
    {
        player.connection.sendPacket(new SPacketEntityEffect(player.getEntityId(), potioneffect));
    }
}
项目:CustomWorldGen    文件:NetHandlerPlayClient.java   
public void handleRespawn(SPacketRespawn packetIn)
{
    PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.gameController);

    if (packetIn.getDimensionID() != this.gameController.thePlayer.dimension)
    {
        this.doneLoadingTerrain = false;
        Scoreboard scoreboard = this.clientWorldController.getScoreboard();
        this.clientWorldController = new WorldClient(this, new WorldSettings(0L, packetIn.getGameType(), false, this.gameController.theWorld.getWorldInfo().isHardcoreModeEnabled(), packetIn.getWorldType()), packetIn.getDimensionID(), packetIn.getDifficulty(), this.gameController.mcProfiler);
        this.clientWorldController.setWorldScoreboard(scoreboard);
        this.gameController.loadWorld(this.clientWorldController);
        this.gameController.thePlayer.dimension = packetIn.getDimensionID();
        this.gameController.displayGuiScreen(new GuiDownloadTerrain(this));
    }

    this.gameController.setDimensionAndSpawnPlayer(packetIn.getDimensionID());
    this.gameController.playerController.setGameType(packetIn.getGameType());
}
项目:CustomWorldGen    文件:PlayerList.java   
public void transferPlayerToDimension(EntityPlayerMP player, int dimensionIn, net.minecraft.world.Teleporter teleporter)
{
    int i = player.dimension;
    WorldServer worldserver = this.mcServer.worldServerForDimension(player.dimension);
    player.dimension = dimensionIn;
    WorldServer worldserver1 = this.mcServer.worldServerForDimension(player.dimension);
    player.connection.sendPacket(new SPacketRespawn(player.dimension, worldserver1.getDifficulty(), worldserver1.getWorldInfo().getTerrainType(), player.interactionManager.getGameType()));
    this.updatePermissionLevel(player);
    worldserver.removeEntityDangerously(player);
    player.isDead = false;
    this.transferEntityToWorld(player, i, worldserver, worldserver1, teleporter);
    this.preparePlayer(player, worldserver);
    player.connection.setPlayerLocation(player.posX, player.posY, player.posZ, player.rotationYaw, player.rotationPitch);
    player.interactionManager.setWorld(worldserver1);
    player.connection.sendPacket(new SPacketPlayerAbilities(player.capabilities));
    this.updateTimeAndWeatherForPlayer(player, worldserver1);
    this.syncPlayerInventory(player);

    for (PotionEffect potioneffect : player.getActivePotionEffects())
    {
        player.connection.sendPacket(new SPacketEntityEffect(player.getEntityId(), potioneffect));
    }
    net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerChangedDimensionEvent(player, i, dimensionIn);
}
项目:ExpandedRailsMod    文件:NetHandlerPlayClient.java   
public void handleRespawn(SPacketRespawn packetIn)
{
    PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.gameController);

    if (packetIn.getDimensionID() != this.gameController.thePlayer.dimension)
    {
        this.doneLoadingTerrain = false;
        Scoreboard scoreboard = this.clientWorldController.getScoreboard();
        this.clientWorldController = new WorldClient(this, new WorldSettings(0L, packetIn.getGameType(), false, this.gameController.theWorld.getWorldInfo().isHardcoreModeEnabled(), packetIn.getWorldType()), packetIn.getDimensionID(), packetIn.getDifficulty(), this.gameController.mcProfiler);
        this.clientWorldController.setWorldScoreboard(scoreboard);
        this.gameController.loadWorld(this.clientWorldController);
        this.gameController.thePlayer.dimension = packetIn.getDimensionID();
        this.gameController.displayGuiScreen(new GuiDownloadTerrain(this));
    }

    this.gameController.setDimensionAndSpawnPlayer(packetIn.getDimensionID());
    this.gameController.playerController.setGameType(packetIn.getGameType());
}
项目:LittleThings-old    文件:CommandDimTeleport.java   
private Entity teleportPlayerToDim(World oldWorld, int newWorldID, double d, double e, double f, Entity entity)
{
    MinecraftServer server = entity.getServer();
    WorldServer oldWorldServer = server.worldServerForDimension(entity.dimension);
    WorldServer newWorldServer = server.worldServerForDimension(newWorldID);
    if (entity instanceof EntityPlayer) {
        EntityPlayerMP player = (EntityPlayerMP) entity;
        if (!player.worldObj.isRemote) {
            player.worldObj.theProfiler.startSection("portal");
            player.worldObj.theProfiler.startSection("changeDimension");
            PlayerList config = player.mcServer.getPlayerList();
            player.closeScreen();
            player.dimension = newWorldServer.provider.getDimension();
            player.playerNetServerHandler.sendPacket(new SPacketRespawn(player.dimension, player.worldObj.getDifficulty(), newWorldServer.getWorldInfo().getTerrainType(), player.interactionManager.getGameType()));
            oldWorldServer.removeEntity(player);
            player.isDead = false;
            player.setLocationAndAngles(d, e, f, player.rotationYaw, player.rotationPitch);
            newWorldServer.spawnEntityInWorld(player);
            player.setWorld(newWorldServer);
            config.preparePlayer(player, oldWorldServer);
            player.playerNetServerHandler.setPlayerLocation(d, e, f, entity.rotationYaw, entity.rotationPitch);
            player.interactionManager.setWorld(newWorldServer);
            config.updateTimeAndWeatherForPlayer(player, newWorldServer);
            config.syncPlayerInventory(player);
            player.worldObj.theProfiler.endSection();
            oldWorldServer.resetUpdateEntityTick();
            newWorldServer.resetUpdateEntityTick();
            player.worldObj.theProfiler.endSection();
            for (PotionEffect potionEffect : player.getActivePotionEffects()) {
                player.playerNetServerHandler.sendPacket(new SPacketEntityEffect(player.getEntityId(), potionEffect));
            }
            player.playerNetServerHandler.sendPacket(new SPacketSetExperience(player.experience, player.experienceTotal, player.experienceLevel));
            FMLCommonHandler.instance().firePlayerChangedDimensionEvent(player, oldWorldServer.provider.getDimension(), player.dimension);
        }
        player.worldObj.theProfiler.endSection();
        return player;
    }
    return null;
}
项目:morecommands    文件:PatchEntityPlayerMP.java   
private static void transferPlayerToDimension(PlayerList playerList, net.minecraft.entity.player.EntityPlayerMP player, int dimension, Teleporter teleporter) {
    int i = player.dimension;
    WorldServer worldserver = playerList.getServerInstance().getWorld(player.dimension);
    player.dimension = dimension;
    WorldServer worldserver1 = playerList.getServerInstance().getWorld(player.dimension);
    player.connection.sendPacket(new SPacketRespawn(player.dimension, worldserver1.getDifficulty(), worldserver1.getWorldInfo().getTerrainType(), player.interactionManager.getGameType()));

    //MoreCommands Bug fix: client world has wrong spawn position, because WorldClient is recreated after receiving S07PacketRespawn
    //with default spawn coordinates 8, 64, 8. This causes e.g. the compass to point to a wrong direction. A possible solution is sending a S05PacketSpawnPosition.
    //Fixes https://bugs.mojang.com/browse/MC-679
    player.connection.sendPacket(new SPacketSpawnPosition(new BlockPos(worldserver1.getWorldInfo().getSpawnX(), worldserver1.getWorldInfo().getSpawnY(), worldserver1.getWorldInfo().getSpawnZ())));

    playerList.updatePermissionLevel(player);
    worldserver.removeEntityDangerously(player);
    player.isDead = false;
    playerList.transferEntityToWorld(player, i, worldserver, worldserver1, teleporter);
    playerList.preparePlayer(player, worldserver);
    player.connection.setPlayerLocation(player.posX, player.posY, player.posZ, player.rotationYaw, player.rotationPitch);
    player.interactionManager.setWorld(worldserver1);
    player.connection.sendPacket(new SPacketPlayerAbilities(player.capabilities));
    playerList.updateTimeAndWeatherForPlayer(player, worldserver1);
    playerList.syncPlayerInventory(player);

    for (PotionEffect potioneffect : player.getActivePotionEffects())
    {
        player.connection.sendPacket(new SPacketEntityEffect(player.getEntityId(), potioneffect));
    }
    net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerChangedDimensionEvent(player, i, dimension);
}
项目:UniversalRemote    文件:RespawnInterceptor.java   
@Override
protected void channelRead0(ChannelHandlerContext ctx, SPacketRespawn msg) throws Exception {
       if (ctx.channel().isOpen())
       {
           try
           {

            try {

                NetHandlerPlayClient handler = (NetHandlerPlayClient) m_manager.getNetHandler();

                Minecraft scheduler = InjectionHandler.readFieldOfType(handler, Minecraft.class);

                if (!scheduler.isCallingFromMinecraftThread())
                {
                    scheduler.addScheduledTask(new Runnable()
                    {
                        @Override
                        public void run()
                        {
                            invoke(msg);
                        }
                    });
                    throw ThreadQuickExitException.INSTANCE;
                } else {
                    invoke(msg);
                }

            } catch (Exception e) {

                if (e instanceof ThreadQuickExitException) throw e;

                Util.logger.logException("Unable to get scheduler!", e);

                // we died - let vanilla take over!
                ctx.fireChannelRead(msg);
                return;
            }

           }
           catch (ThreadQuickExitException var4)
           {
               ;
           }
       }
}
项目:Zombe-Modpack    文件:NetHandlerPlayServer.java   
public void handleSpectate(CPacketSpectate packetIn)
{
    PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerWorld());

    if (this.playerEntity.isSpectator())
    {
        Entity entity = null;

        for (WorldServer worldserver : this.serverController.worldServers)
        {
            if (worldserver != null)
            {
                entity = packetIn.getEntity(worldserver);

                if (entity != null)
                {
                    break;
                }
            }
        }

        if (entity != null)
        {
            this.playerEntity.setSpectatingEntity(this.playerEntity);
            this.playerEntity.dismountRidingEntity();

            if (entity.world == this.playerEntity.world)
            {
                this.playerEntity.setPositionAndUpdate(entity.posX, entity.posY, entity.posZ);
            }
            else
            {
                WorldServer worldserver1 = this.playerEntity.getServerWorld();
                WorldServer worldserver2 = (WorldServer)entity.world;
                this.playerEntity.dimension = entity.dimension;
                this.sendPacket(new SPacketRespawn(this.playerEntity.dimension, worldserver1.getDifficulty(), worldserver1.getWorldInfo().getTerrainType(), this.playerEntity.interactionManager.getGameType()));
                this.serverController.getPlayerList().updatePermissionLevel(this.playerEntity);
                worldserver1.removeEntityDangerously(this.playerEntity);
                this.playerEntity.isDead = false;
                this.playerEntity.setLocationAndAngles(entity.posX, entity.posY, entity.posZ, entity.rotationYaw, entity.rotationPitch);

                if (this.playerEntity.isEntityAlive())
                {
                    worldserver1.updateEntityWithOptionalForce(this.playerEntity, false);
                    worldserver2.spawnEntityInWorld(this.playerEntity);
                    worldserver2.updateEntityWithOptionalForce(this.playerEntity, false);
                }

                this.playerEntity.setWorld(worldserver2);
                this.serverController.getPlayerList().preparePlayer(this.playerEntity, worldserver1);
                this.playerEntity.setPositionAndUpdate(entity.posX, entity.posY, entity.posZ);
                this.playerEntity.interactionManager.setWorld(worldserver2);
                this.serverController.getPlayerList().updateTimeAndWeatherForPlayer(this.playerEntity, worldserver2);
                this.serverController.getPlayerList().syncPlayerInventory(this.playerEntity);
            }
        }
    }
}
项目:Backmemed    文件:NetHandlerPlayServer.java   
public void handleSpectate(CPacketSpectate packetIn)
{
    PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerWorld());

    if (this.playerEntity.isSpectator())
    {
        Entity entity = null;

        for (WorldServer worldserver : this.serverController.worldServers)
        {
            if (worldserver != null)
            {
                entity = packetIn.getEntity(worldserver);

                if (entity != null)
                {
                    break;
                }
            }
        }

        if (entity != null)
        {
            this.playerEntity.setSpectatingEntity(this.playerEntity);
            this.playerEntity.dismountRidingEntity();

            if (entity.world == this.playerEntity.world)
            {
                this.playerEntity.setPositionAndUpdate(entity.posX, entity.posY, entity.posZ);
            }
            else
            {
                WorldServer worldserver1 = this.playerEntity.getServerWorld();
                WorldServer worldserver2 = (WorldServer)entity.world;
                this.playerEntity.dimension = entity.dimension;
                this.sendPacket(new SPacketRespawn(this.playerEntity.dimension, worldserver1.getDifficulty(), worldserver1.getWorldInfo().getTerrainType(), this.playerEntity.interactionManager.getGameType()));
                this.serverController.getPlayerList().updatePermissionLevel(this.playerEntity);
                worldserver1.removeEntityDangerously(this.playerEntity);
                this.playerEntity.isDead = false;
                this.playerEntity.setLocationAndAngles(entity.posX, entity.posY, entity.posZ, entity.rotationYaw, entity.rotationPitch);

                if (this.playerEntity.isEntityAlive())
                {
                    worldserver1.updateEntityWithOptionalForce(this.playerEntity, false);
                    worldserver2.spawnEntityInWorld(this.playerEntity);
                    worldserver2.updateEntityWithOptionalForce(this.playerEntity, false);
                }

                this.playerEntity.setWorld(worldserver2);
                this.serverController.getPlayerList().preparePlayer(this.playerEntity, worldserver1);
                this.playerEntity.setPositionAndUpdate(entity.posX, entity.posY, entity.posZ);
                this.playerEntity.interactionManager.setWorld(worldserver2);
                this.serverController.getPlayerList().updateTimeAndWeatherForPlayer(this.playerEntity, worldserver2);
                this.serverController.getPlayerList().syncPlayerInventory(this.playerEntity);
            }
        }
    }
}
项目:CustomWorldGen    文件:NetHandlerPlayServer.java   
public void handleSpectate(CPacketSpectate packetIn)
{
    PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerWorld());

    if (this.playerEntity.isSpectator())
    {
        Entity entity = null;

        for (WorldServer worldserver : this.serverController.worldServers)
        {
            if (worldserver != null)
            {
                entity = packetIn.getEntity(worldserver);

                if (entity != null)
                {
                    break;
                }
            }
        }

        if (entity != null)
        {
            this.playerEntity.setSpectatingEntity(this.playerEntity);
            this.playerEntity.dismountRidingEntity();

            if (entity.worldObj == this.playerEntity.worldObj)
            {
                this.playerEntity.setPositionAndUpdate(entity.posX, entity.posY, entity.posZ);
            }
            else
            {
                WorldServer worldserver1 = this.playerEntity.getServerWorld();
                WorldServer worldserver2 = (WorldServer)entity.worldObj;
                this.playerEntity.dimension = entity.dimension;
                this.sendPacket(new SPacketRespawn(this.playerEntity.dimension, worldserver1.getDifficulty(), worldserver1.getWorldInfo().getTerrainType(), this.playerEntity.interactionManager.getGameType()));
                this.serverController.getPlayerList().updatePermissionLevel(this.playerEntity);
                worldserver1.removeEntityDangerously(this.playerEntity);
                this.playerEntity.isDead = false;
                this.playerEntity.setLocationAndAngles(entity.posX, entity.posY, entity.posZ, entity.rotationYaw, entity.rotationPitch);

                if (this.playerEntity.isEntityAlive())
                {
                    worldserver1.updateEntityWithOptionalForce(this.playerEntity, false);
                    worldserver2.spawnEntityInWorld(this.playerEntity);
                    worldserver2.updateEntityWithOptionalForce(this.playerEntity, false);
                }

                this.playerEntity.setWorld(worldserver2);
                this.serverController.getPlayerList().preparePlayer(this.playerEntity, worldserver1);
                this.playerEntity.setPositionAndUpdate(entity.posX, entity.posY, entity.posZ);
                this.playerEntity.interactionManager.setWorld(worldserver2);
                this.serverController.getPlayerList().updateTimeAndWeatherForPlayer(this.playerEntity, worldserver2);
                this.serverController.getPlayerList().syncPlayerInventory(this.playerEntity);
            }
        }
    }
}
项目:minecraft-territorialdealings    文件:Transition.java   
static void transferPlayerToDimension(EntityPlayerMP player, int dimensionTo, int targetHeight)
  {
if (!net.minecraftforge.common.ForgeHooks.onTravelToDimension(player, dimensionTo)) { return; } // Moving that here, to consolidate these functions.

net.minecraft.world.Teleporter teleporter = player.mcServer.worldServerForDimension(dimensionTo).getDefaultTeleporter();
PlayerList playerList = player.mcServer.getPlayerList();

      int dimensionFrom = player.dimension;

      // Changing dimensions...
      WorldServer wsPrev = player.mcServer.worldServerForDimension(player.dimension);

      player.dimension = dimensionTo;

      WorldServer wsNew = player.mcServer.worldServerForDimension(player.dimension);

      // Respawn? Used to recreate the player entity.
      player.connection.sendPacket(new SPacketRespawn(player.dimension, wsNew.getDifficulty(), wsNew.getWorldInfo().getTerrainType(), player.interactionManager.getGameType()));

      // Capabilities...
      playerList.updatePermissionLevel(player);

      // Begone from the old world?
      wsPrev.removeEntity(player);

      // Safety, I suppose.
      player.isDead = false;

      // We haven't reached the "set portal" level yet. Going deeper.
      transferEntityToWorld(player, dimensionFrom, wsPrev, wsNew, teleporter, targetHeight);

      // Getting chunks ready?
      playerList.preparePlayer(player, wsPrev);

      // Inserting their new position here? May not be necessary, since this is called by the drop and transfer, which sets the position beforehand and afterwards.
      player.connection.setPlayerLocation(player.posX, player.posY, player.posZ, player.rotationYaw, player.rotationPitch);

      // More formalities...
      player.interactionManager.setWorld(wsNew);
      player.connection.sendPacket(new SPacketPlayerAbilities(player.capabilities));

      playerList.updateTimeAndWeatherForPlayer(player, wsNew);
      playerList.syncPlayerInventory(player);

      // Reapplying potion effects
      for (PotionEffect potioneffect : player.getActivePotionEffects())
      {
          player.connection.sendPacket(new SPacketEntityEffect(player.getEntityId(), potioneffect));
      }

      // We're done.
      net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerChangedDimensionEvent(player, dimensionFrom, dimensionTo);
  }
项目:CrystalMod    文件:TeleportUtil.java   
private static EntityPlayer teleportPlayerToDim(EntityPlayerMP player, MinecraftServer server, int sourceDim, int targetDim, double xCoord, double yCoord, double zCoord, float yaw, float pitch, Vector3d motion) {
    WorldServer sourceWorld = server.worldServerForDimension(sourceDim);
    WorldServer targetWorld = server.worldServerForDimension(targetDim);
    PlayerList playerList = server.getPlayerList();

    player.dimension = targetDim;
    player.connection.sendPacket(new SPacketRespawn(player.dimension, targetWorld.getDifficulty(), targetWorld.getWorldInfo().getTerrainType(), player.interactionManager.getGameType()));
    playerList.updatePermissionLevel(player);
    sourceWorld.removeEntityDangerously(player);
    player.isDead = false;

    //region Transfer to world

    player.setLocationAndAngles(xCoord, yCoord, zCoord, yaw, pitch);
    player.connection.setPlayerLocation(xCoord, yCoord, zCoord, yaw, pitch);
    targetWorld.spawnEntity(player);
    targetWorld.updateEntityWithOptionalForce(player, false);
    player.setWorld(targetWorld);

    //endregion

    playerList.preparePlayer(player, sourceWorld);
    player.connection.setPlayerLocation(xCoord, yCoord, zCoord, yaw, pitch);
    player.interactionManager.setWorld(targetWorld);
    player.connection.sendPacket(new SPacketPlayerAbilities(player.capabilities));

    playerList.updateTimeAndWeatherForPlayer(player, targetWorld);
    playerList.syncPlayerInventory(player);

    for (PotionEffect potioneffect : player.getActivePotionEffects()) {
        player.connection.sendPacket(new SPacketEntityEffect(player.getEntityId(), potioneffect));
    }
    net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerChangedDimensionEvent(player, sourceDim, targetDim);
    player.setLocationAndAngles(xCoord, yCoord, zCoord, yaw, pitch);

    player.motionX += motion.x; player.motionY += motion.y; player.motionZ += motion.z;
    NBTTagCompound nbt = new NBTTagCompound();
    nbt.setDouble("X", motion.x);
    nbt.setDouble("Y", motion.y);
    nbt.setDouble("Z", motion.z);
    CrystalModNetwork.sendToAll(new PacketEntityMessage(player, "AddMotion", nbt));

    return player;
}
项目:VanillaTeleporter    文件:TeleporterUtility.java   
/**
 * 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()
            )
        );

        srcWorld.removeEntity(player); // remove the original player entity
        player.isDead = false; // make sure the player isn't dead (removeEntity sets player as dead)

        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;
    }
}
项目:Bookshelf    文件:PlayerUtils.java   
/**
 * Changes the dimension a player is in, in a safe way. This will make sure the player is
 * teleported to the dimension and all the correct packets are sent to keep the client in
 * sync. It also gets around teleporter code which in some cases will crash the server.
 *
 * @param player The player to change the dimension of.
 * @param dimension The dimension to send the player to.
 * @param playerData The player data from the server.
 */
public static void changeDimension (EntityPlayerMP player, int dimension, PlayerList playerData) {

    if (!net.minecraftforge.common.ForgeHooks.onTravelToDimension(player, dimension)) {

        return;
    }

    final int oldDim = player.dimension;
    final boolean wasAlive = player.isEntityAlive();
    final WorldServer worldOld = playerData.getServerInstance().getWorld(player.dimension);
    final WorldServer worldNew = playerData.getServerInstance().getWorld(dimension);

    if (player.isBeingRidden()) {

        player.removePassengers();
    }

    if (player.isRiding()) {

        player.dismountRidingEntity();
    }

    player.dimension = dimension;
    player.connection.sendPacket(new SPacketRespawn(player.dimension, player.world.getDifficulty(), player.world.getWorldInfo().getTerrainType(), player.interactionManager.getGameType()));
    worldOld.removeEntityDangerously(player);

    EntityUtils.changeWorld(player, worldOld, worldNew);
    playerData.preparePlayer(player, worldOld);
    player.connection.setPlayerLocation(player.posX, player.posY, player.posZ, player.rotationYaw, player.rotationPitch);
    player.interactionManager.setWorld(worldNew);
    playerData.updateTimeAndWeatherForPlayer(player, worldNew);
    playerData.syncPlayerInventory(player);

    if (player.isDead && wasAlive) {

        player.isDead = false;
    }

    for (final PotionEffect potioneffect : player.getActivePotionEffects()) {

        player.connection.sendPacket(new SPacketEntityEffect(player.getEntityId(), potioneffect));
    }

    FMLCommonHandler.instance().firePlayerChangedDimensionEvent(player, oldDim, dimension);
}
项目:ExpandedRailsMod    文件:NetHandlerPlayServer.java   
public void handleSpectate(CPacketSpectate packetIn)
{
    PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerWorld());

    if (this.playerEntity.isSpectator())
    {
        Entity entity = null;

        for (WorldServer worldserver : this.serverController.worldServers)
        {
            if (worldserver != null)
            {
                entity = packetIn.getEntity(worldserver);

                if (entity != null)
                {
                    break;
                }
            }
        }

        if (entity != null)
        {
            this.playerEntity.setSpectatingEntity(this.playerEntity);
            this.playerEntity.dismountRidingEntity();

            if (entity.worldObj == this.playerEntity.worldObj)
            {
                this.playerEntity.setPositionAndUpdate(entity.posX, entity.posY, entity.posZ);
            }
            else
            {
                WorldServer worldserver1 = this.playerEntity.getServerWorld();
                WorldServer worldserver2 = (WorldServer)entity.worldObj;
                this.playerEntity.dimension = entity.dimension;
                this.sendPacket(new SPacketRespawn(this.playerEntity.dimension, worldserver1.getDifficulty(), worldserver1.getWorldInfo().getTerrainType(), this.playerEntity.interactionManager.getGameType()));
                this.serverController.getPlayerList().updatePermissionLevel(this.playerEntity);
                worldserver1.removeEntityDangerously(this.playerEntity);
                this.playerEntity.isDead = false;
                this.playerEntity.setLocationAndAngles(entity.posX, entity.posY, entity.posZ, entity.rotationYaw, entity.rotationPitch);

                if (this.playerEntity.isEntityAlive())
                {
                    worldserver1.updateEntityWithOptionalForce(this.playerEntity, false);
                    worldserver2.spawnEntityInWorld(this.playerEntity);
                    worldserver2.updateEntityWithOptionalForce(this.playerEntity, false);
                }

                this.playerEntity.setWorld(worldserver2);
                this.serverController.getPlayerList().preparePlayer(this.playerEntity, worldserver1);
                this.playerEntity.setPositionAndUpdate(entity.posX, entity.posY, entity.posZ);
                this.playerEntity.interactionManager.setWorld(worldserver2);
                this.serverController.getPlayerList().updateTimeAndWeatherForPlayer(this.playerEntity, worldserver2);
                this.serverController.getPlayerList().syncPlayerInventory(this.playerEntity);
            }
        }
    }
}
项目:Backmemed    文件:INetHandlerPlayClient.java   
void handleRespawn(SPacketRespawn packetIn);
项目:CustomWorldGen    文件:INetHandlerPlayClient.java   
void handleRespawn(SPacketRespawn packetIn);