public void transferPlayerToDimension(EntityPlayerMP par1EntityPlayerMP, int par2) { int var3 = par1EntityPlayerMP.dimension; WorldServer var4 = this.mcServer.worldServerForDimension(par1EntityPlayerMP.dimension); par1EntityPlayerMP.dimension = par2; WorldServer var5 = this.mcServer.worldServerForDimension(par1EntityPlayerMP.dimension); par1EntityPlayerMP.playerNetServerHandler.sendPacketToPlayer( new Packet9Respawn( par1EntityPlayerMP.dimension, (byte) par1EntityPlayerMP.worldObj.difficultySetting, var5.getWorldInfo().getTerrainType(), var5.getHeight(), par1EntityPlayerMP.theItemInWorldManager.getGameType())); var4.removeEntity(par1EntityPlayerMP); par1EntityPlayerMP.isDead = false; this.transferEntityToWorld(par1EntityPlayerMP, var3, var4, var5); this.func_72375_a(par1EntityPlayerMP, var4); par1EntityPlayerMP.playerNetServerHandler.setPlayerLocation( par1EntityPlayerMP.posX, par1EntityPlayerMP.posY, par1EntityPlayerMP.posZ, par1EntityPlayerMP.rotationYaw, par1EntityPlayerMP.rotationPitch); par1EntityPlayerMP.theItemInWorldManager.setWorld(var5); this.updateTimeAndWeatherForPlayer(par1EntityPlayerMP, var5); this.syncPlayerInventory(par1EntityPlayerMP); Iterator var6 = par1EntityPlayerMP.getActivePotionEffects().iterator(); while (var6.hasNext()) { PotionEffect var7 = (PotionEffect) var6.next(); par1EntityPlayerMP.playerNetServerHandler.sendPacketToPlayer( new Packet41EntityEffect(par1EntityPlayerMP.entityId, var7)); } }
/** moves provided player from overworld to nether or vice versa */ public void transferPlayerToDimension(EntityPlayerMP playerIn, int dimension) { int var3 = playerIn.dimension; WorldServer var4 = this.mcServer.worldServerForDimension(playerIn.dimension); playerIn.dimension = dimension; WorldServer var5 = this.mcServer.worldServerForDimension(playerIn.dimension); playerIn.playerNetServerHandler.sendPacket( new S07PacketRespawn( playerIn.dimension, playerIn.worldObj.getDifficulty(), playerIn.worldObj.getWorldInfo().getTerrainType(), playerIn.theItemInWorldManager.getGameType())); var4.removePlayerEntityDangerously(playerIn); playerIn.isDead = false; this.transferEntityToWorld(playerIn, var3, var4, var5); this.func_72375_a(playerIn, var4); playerIn.playerNetServerHandler.setPlayerLocation( playerIn.posX, playerIn.posY, playerIn.posZ, playerIn.rotationYaw, playerIn.rotationPitch); playerIn.theItemInWorldManager.setWorld(var5); this.updateTimeAndWeatherForPlayer(playerIn, var5); this.syncPlayerInventory(playerIn); Iterator var6 = playerIn.getActivePotionEffects().iterator(); while (var6.hasNext()) { PotionEffect var7 = (PotionEffect) var6.next(); playerIn.playerNetServerHandler.sendPacket( new S1DPacketEntityEffect(playerIn.getEntityId(), var7)); } }
/** * @author blood - May 21st, 2016 * @reason - adjusted to support {@link DisplaceEntityEvent.Teleport.Portal} * @param playerIn The player teleporting to another dimension * @param targetDimensionId The id of target dimension. * @param teleporter The teleporter used to transport and create the portal */ public void transferPlayerToDimension( EntityPlayerMP playerIn, int targetDimensionId, net.minecraft.world.Teleporter teleporter) { DisplaceEntityEvent.Teleport.Portal event = SpongeCommonEventFactory.handleDisplaceEntityPortalEvent( playerIn, targetDimensionId, teleporter); if (event == null || event.isCancelled()) { return; } WorldServer fromWorld = (WorldServer) event.getFromTransform().getExtent(); WorldServer toWorld = (WorldServer) event.getToTransform().getExtent(); playerIn.dimension = toWorld.provider.getDimensionId(); // Support vanilla clients teleporting to custom dimensions int dimension = DimensionManager.getClientDimensionToSend( toWorld.provider.getDimensionId(), toWorld, playerIn); if (((IMixinEntityPlayerMP) playerIn).usesCustomClient()) { DimensionManager.sendDimensionRegistration(toWorld, playerIn, dimension); } playerIn.playerNetServerHandler.sendPacket( new S07PacketRespawn( playerIn.dimension, fromWorld.getDifficulty(), fromWorld.getWorldInfo().getTerrainType(), playerIn.theItemInWorldManager.getGameType())); fromWorld.removePlayerEntityDangerously(playerIn); playerIn.isDead = false; // we do not need to call transferEntityToWorld as we already have the correct transform and // created the portal in handleDisplaceEntityPortalEvent ((IMixinEntity) playerIn).setLocationAndAngles(event.getToTransform()); toWorld.spawnEntityInWorld(playerIn); toWorld.updateEntityWithOptionalForce(playerIn, false); playerIn.setWorld(toWorld); this.preparePlayer(playerIn, fromWorld); playerIn.playerNetServerHandler.setPlayerLocation( playerIn.posX, playerIn.posY, playerIn.posZ, playerIn.rotationYaw, playerIn.rotationPitch); playerIn.theItemInWorldManager.setWorld(toWorld); this.updateTimeAndWeatherForPlayer(playerIn, toWorld); this.syncPlayerInventory(playerIn); for (PotionEffect potioneffect : playerIn.getActivePotionEffects()) { playerIn.playerNetServerHandler.sendPacket( new S1DPacketEntityEffect(playerIn.getEntityId(), potioneffect)); } ((IMixinEntityPlayerMP) playerIn).refreshXpHealthAndFood(); // Forge needs to know when a player changes to new a dimension // This cannot be mapped to DisplaceEntityEvent.Teleport as this event must be called AFTER // transfer. net.minecraftforge.fml.common.FMLCommonHandler.instance() .firePlayerChangedDimensionEvent( playerIn, fromWorld.provider.getDimensionId(), toWorld.provider.getDimensionId()); }
private static Entity sendEntityToWorld( Entity entity, int newDimension, Vector3 newPos, Facing3 newLook) { MinecraftServer server = MinecraftServer.getServer(); Entity currentEntity = entity; if (entity.dimension != newDimension) { if (entity instanceof EntityPlayerMP) { EntityPlayerMP player = (EntityPlayerMP) entity; ServerConfigurationManager scm = server.getConfigurationManager(); int oldDimension = player.dimension; player.dimension = newDimension; WorldServer oldWorld = server.worldServerForDimension(oldDimension); WorldServer newWorld = server.worldServerForDimension(newDimension); DimensionRegisterMessage packet = new DimensionRegisterMessage( newDimension, DimensionManager.getProviderType(newDimension)); LCRuntime.runtime.network().getPreferredPipe().sendForgeMessageTo(packet, player); player.closeScreen(); player.playerNetServerHandler.sendPacket( new S07PacketRespawn( player.dimension, player.worldObj.difficultySetting, newWorld.getWorldInfo().getTerrainType(), player.theItemInWorldManager.getGameType())); oldWorld.removePlayerEntityDangerously(player); player.isDead = false; player.setLocationAndAngles( newPos.x, newPos.y, newPos.z, (float) newLook.yaw, (float) newLook.pitch); newWorld.spawnEntityInWorld(player); player.setWorld(newWorld); scm.func_72375_a(player, oldWorld); player.playerNetServerHandler.setPlayerLocation( newPos.x, newPos.y, newPos.z, (float) newLook.yaw, (float) newLook.pitch); player.theItemInWorldManager.setWorld(newWorld); scm.updateTimeAndWeatherForPlayer(player, newWorld); scm.syncPlayerInventory(player); Iterator<?> var6 = player.getActivePotionEffects().iterator(); while (var6.hasNext()) player.playerNetServerHandler.sendPacket( new S1DPacketEntityEffect(player.getEntityId(), (PotionEffect) var6.next())); player.playerNetServerHandler.sendPacket( new S1FPacketSetExperience( player.experience, player.experienceTotal, player.experienceLevel)); } else { int oldDimension = entity.dimension; WorldServer oldWorld = server.worldServerForDimension(oldDimension); WorldServer newWorld = server.worldServerForDimension(newDimension); entity.dimension = newDimension; entity.worldObj.removeEntity(entity); entity.isDead = false; server .getConfigurationManager() .transferEntityToWorld(entity, oldDimension, oldWorld, newWorld); currentEntity = EntityList.createEntityByName(EntityList.getEntityString(entity), newWorld); if (currentEntity != null) { currentEntity.copyDataFrom(entity, true); currentEntity.setLocationAndAngles( newPos.x, newPos.y, newPos.z, (float) newLook.yaw, (float) newLook.pitch); newWorld.spawnEntityInWorld(currentEntity); } entity.isDead = true; oldWorld.resetUpdateEntityTick(); newWorld.resetUpdateEntityTick(); } } else { currentEntity.setLocationAndAngles( newPos.x, newPos.y, newPos.z, (float) newLook.yaw, (float) newLook.pitch); if (currentEntity instanceof EntityPlayerMP) { EntityPlayerMP mpEnt = (EntityPlayerMP) currentEntity; mpEnt.rotationYaw = (float) newLook.yaw; mpEnt.setPositionAndUpdate(newPos.x, newPos.y, newPos.z); mpEnt.worldObj.updateEntityWithOptionalForce(entity, false); } } return currentEntity; }