use of net.minecraft.network.play.server.S1DPacketEntityEffect in project Galacticraft by micdoodle8.
the class WorldUtil method teleportEntity.
private static Entity teleportEntity(World worldNew, Entity entity, int dimID, ITeleportType type, boolean transferInv, EntityAutoRocket ridingRocket) {
Entity otherRiddenEntity = null;
if (entity.ridingEntity != null) {
if (entity.ridingEntity instanceof EntitySpaceshipBase) {
entity.mountEntity(entity.ridingEntity);
} else if (entity.ridingEntity instanceof EntityCelestialFake) {
entity.ridingEntity.setDead();
entity.mountEntity(null);
} else {
otherRiddenEntity = entity.ridingEntity;
entity.mountEntity(null);
}
}
boolean dimChange = entity.worldObj != worldNew;
// Make sure the entity is added to the correct chunk in the OLD world so that it will be properly removed later if it needs to be unloaded from that world
entity.worldObj.updateEntityWithOptionalForce(entity, false);
EntityPlayerMP player = null;
Vector3 spawnPos = null;
int oldDimID = GCCoreUtil.getDimensionID(entity.worldObj);
if (ridingRocket != null) {
ArrayList<TileEntityTelemetry> tList = ridingRocket.getTelemetry();
NBTTagCompound nbt = new NBTTagCompound();
ridingRocket.isDead = false;
ridingRocket.riddenByEntity = null;
ridingRocket.writeToNBTOptional(nbt);
((WorldServer) ridingRocket.worldObj).getEntityTracker().untrackEntity(ridingRocket);
removeEntityFromWorld(ridingRocket.worldObj, ridingRocket, true);
ridingRocket = (EntityAutoRocket) EntityList.createEntityFromNBT(nbt, worldNew);
if (ridingRocket != null) {
ridingRocket.setWaitForPlayer(true);
if (ridingRocket instanceof IWorldTransferCallback) {
((IWorldTransferCallback) ridingRocket).onWorldTransferred(worldNew);
}
}
}
if (dimChange) {
if (entity instanceof EntityPlayerMP) {
player = (EntityPlayerMP) entity;
World worldOld = player.worldObj;
GCPlayerStats stats = GCPlayerStats.get(player);
stats.setUsingPlanetSelectionGui(false);
player.dimension = dimID;
if (ConfigManagerCore.enableDebug) {
GCLog.info("DEBUG: Sending respawn packet to player for dim " + dimID);
}
player.playerNetServerHandler.sendPacket(new S07PacketRespawn(dimID, player.worldObj.getDifficulty(), player.worldObj.getWorldInfo().getTerrainType(), player.theItemInWorldManager.getGameType()));
if (worldNew.provider instanceof WorldProviderSpaceStation) {
if (WorldUtil.registeredSpaceStations.containsKey(dimID)) // TODO This has never been effective before due to the earlier bug - what does it actually do?
{
NBTTagCompound var2 = new NBTTagCompound();
SpaceStationWorldData.getStationData(worldNew, dimID, player).writeToNBT(var2);
GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_UPDATE_SPACESTATION_DATA, GCCoreUtil.getDimensionID(player.worldObj), new Object[] { dimID, var2 }), player);
}
}
removeEntityFromWorld(worldOld, player, true);
if (ridingRocket != null) {
spawnPos = new Vector3(ridingRocket);
} else {
spawnPos = type.getPlayerSpawnLocation((WorldServer) worldNew, player);
}
forceMoveEntityToPos(entity, (WorldServer) worldNew, spawnPos, true);
GCLog.info("Server attempting to transfer player " + PlayerUtil.getName(player) + " to dimension " + GCCoreUtil.getDimensionID(worldNew));
if (worldNew.provider instanceof WorldProviderSpaceStation) {
GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_RESET_THIRD_PERSON, GCCoreUtil.getDimensionID(worldNew), new Object[] {}), player);
}
player.capabilities.isFlying = false;
player.mcServer.getConfigurationManager().preparePlayer(player, (WorldServer) worldOld);
player.theItemInWorldManager.setWorld((WorldServer) worldNew);
player.mcServer.getConfigurationManager().updateTimeAndWeatherForPlayer(player, (WorldServer) worldNew);
player.mcServer.getConfigurationManager().syncPlayerInventory(player);
for (Object o : player.getActivePotionEffects()) {
PotionEffect var10 = (PotionEffect) o;
player.playerNetServerHandler.sendPacket(new S1DPacketEntityEffect(player.getEntityId(), var10));
}
player.playerNetServerHandler.sendPacket(new S1FPacketSetExperience(player.experience, player.experienceTotal, player.experienceLevel));
} else // Non-player entity transfer i.e. it's an EntityCargoRocket or an empty rocket
{
ArrayList<TileEntityTelemetry> tList = null;
if (entity instanceof EntitySpaceshipBase) {
tList = ((EntitySpaceshipBase) entity).getTelemetry();
}
WorldUtil.removeEntityFromWorld(entity.worldObj, entity, true);
NBTTagCompound nbt = new NBTTagCompound();
entity.isDead = false;
entity.writeToNBTOptional(nbt);
entity = EntityList.createEntityFromNBT(nbt, worldNew);
if (entity == null) {
return null;
}
if (entity instanceof IWorldTransferCallback) {
((IWorldTransferCallback) entity).onWorldTransferred(worldNew);
}
forceMoveEntityToPos(entity, (WorldServer) worldNew, new Vector3(entity), true);
if (tList != null && tList.size() > 0) {
for (TileEntityTelemetry t : tList) {
t.addTrackedEntity(entity);
}
}
}
} else {
// Same dimension player transfer
if (entity instanceof EntityPlayerMP) {
player = (EntityPlayerMP) entity;
player.closeScreen();
GCPlayerStats stats = GCPlayerStats.get(player);
stats.setUsingPlanetSelectionGui(false);
if (ridingRocket != null) {
spawnPos = new Vector3(ridingRocket);
} else {
spawnPos = type.getPlayerSpawnLocation((WorldServer) entity.worldObj, (EntityPlayerMP) entity);
}
forceMoveEntityToPos(entity, (WorldServer) worldNew, spawnPos, false);
GCLog.info("Server attempting to transfer player " + PlayerUtil.getName(player) + " within same dimension " + GCCoreUtil.getDimensionID(worldNew));
if (worldNew.provider instanceof WorldProviderSpaceStation) {
GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_RESET_THIRD_PERSON, GCCoreUtil.getDimensionID(worldNew), new Object[] {}), player);
}
player.capabilities.isFlying = false;
}
// Cargo rocket does not needs its location setting here, it will do that itself
}
// Update PlayerStatsGC
if (player != null) {
GCPlayerStats stats = GCPlayerStats.get(player);
if (ridingRocket == null && type.useParachute() && stats.getExtendedInventory().getStackInSlot(4) != null && stats.getExtendedInventory().getStackInSlot(4).getItem() instanceof ItemParaChute) {
GCPlayerHandler.setUsingParachute(player, stats, true);
} else {
GCPlayerHandler.setUsingParachute(player, stats, false);
}
if (stats.getRocketStacks() != null && stats.getRocketStacks().length > 0) {
for (int stack = 0; stack < stats.getRocketStacks().length; stack++) {
if (transferInv) {
if (stats.getRocketStacks()[stack] == null) {
if (stack == stats.getRocketStacks().length - 1) {
if (stats.getRocketItem() != null) {
stats.getRocketStacks()[stack] = new ItemStack(stats.getRocketItem(), 1, stats.getRocketType());
}
} else if (stack == stats.getRocketStacks().length - 2) {
stats.getRocketStacks()[stack] = stats.getLaunchpadStack();
stats.setLaunchpadStack(null);
}
}
} else {
stats.getRocketStacks()[stack] = null;
}
}
}
if (transferInv && stats.getChestSpawnCooldown() == 0) {
stats.setChestSpawnVector(type.getParaChestSpawnLocation((WorldServer) entity.worldObj, player, new Random()));
stats.setChestSpawnCooldown(200);
}
}
if (ridingRocket != null) {
ridingRocket.forceSpawn = true;
worldNew.spawnEntityInWorld(ridingRocket);
ridingRocket.setWorld(worldNew);
worldNew.updateEntityWithOptionalForce(ridingRocket, true);
entity.mountEntity(ridingRocket);
GCLog.debug("Entering rocket at : " + entity.posX + "," + entity.posZ + " rocket at: " + ridingRocket.posX + "," + ridingRocket.posZ);
} else if (otherRiddenEntity != null) {
if (dimChange) {
World worldOld = otherRiddenEntity.worldObj;
NBTTagCompound nbt = new NBTTagCompound();
otherRiddenEntity.writeToNBTOptional(nbt);
removeEntityFromWorld(worldOld, otherRiddenEntity, true);
otherRiddenEntity = EntityList.createEntityFromNBT(nbt, worldNew);
worldNew.spawnEntityInWorld(otherRiddenEntity);
otherRiddenEntity.setWorld(worldNew);
}
otherRiddenEntity.setPositionAndRotation(entity.posX, entity.posY - 10, entity.posZ, otherRiddenEntity.rotationYaw, otherRiddenEntity.rotationPitch);
worldNew.updateEntityWithOptionalForce(otherRiddenEntity, true);
}
if (entity instanceof EntityPlayerMP) {
if (dimChange)
FMLCommonHandler.instance().firePlayerChangedDimensionEvent((EntityPlayerMP) entity, oldDimID, dimID);
// Spawn in a lander if appropriate
type.onSpaceDimensionChanged(worldNew, (EntityPlayerMP) entity, ridingRocket != null);
}
return entity;
}
use of net.minecraft.network.play.server.S1DPacketEntityEffect in project Galacticraft by micdoodle8.
the class WorldUtil method teleportEntitySimple.
public static Entity teleportEntitySimple(World worldNew, int dimID, EntityPlayerMP player, Vector3 spawnPos) {
if (player.ridingEntity != null) {
player.ridingEntity.setDead();
player.mountEntity(null);
}
World worldOld = player.worldObj;
int oldDimID = GCCoreUtil.getDimensionID(worldOld);
boolean dimChange = worldOld != worldNew;
// Make sure the entity is added to the correct chunk in the OLD world so that it will be properly removed later if it needs to be unloaded from that world
worldOld.updateEntityWithOptionalForce(player, false);
if (dimChange) {
player.dimension = dimID;
if (ConfigManagerCore.enableDebug) {
GCLog.info("DEBUG: Sending respawn packet to player for dim " + dimID);
}
player.playerNetServerHandler.sendPacket(new S07PacketRespawn(dimID, player.worldObj.getDifficulty(), player.worldObj.getWorldInfo().getTerrainType(), player.theItemInWorldManager.getGameType()));
if (worldNew.provider instanceof WorldProviderSpaceStation) {
if (WorldUtil.registeredSpaceStations.containsKey(dimID)) // TODO This has never been effective before due to the earlier bug - what does it actually do?
{
NBTTagCompound var2 = new NBTTagCompound();
SpaceStationWorldData.getStationData(worldNew, dimID, player).writeToNBT(var2);
GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_UPDATE_SPACESTATION_DATA, GCCoreUtil.getDimensionID(player.worldObj), new Object[] { dimID, var2 }), player);
}
}
removeEntityFromWorld(worldOld, player, true);
forceMoveEntityToPos(player, (WorldServer) worldNew, spawnPos, true);
GCLog.info("Server attempting to transfer player " + PlayerUtil.getName(player) + " to dimension " + GCCoreUtil.getDimensionID(worldNew));
player.mcServer.getConfigurationManager().preparePlayer(player, (WorldServer) worldOld);
player.theItemInWorldManager.setWorld((WorldServer) worldNew);
player.mcServer.getConfigurationManager().updateTimeAndWeatherForPlayer(player, (WorldServer) worldNew);
player.mcServer.getConfigurationManager().syncPlayerInventory(player);
for (Object o : player.getActivePotionEffects()) {
PotionEffect var10 = (PotionEffect) o;
player.playerNetServerHandler.sendPacket(new S1DPacketEntityEffect(player.getEntityId(), var10));
}
player.playerNetServerHandler.sendPacket(new S1FPacketSetExperience(player.experience, player.experienceTotal, player.experienceLevel));
FMLCommonHandler.instance().firePlayerChangedDimensionEvent((EntityPlayerMP) player, oldDimID, dimID);
} else {
forceMoveEntityToPos(player, (WorldServer) worldNew, spawnPos, false);
GCLog.info("Server attempting to transfer player " + PlayerUtil.getName(player) + " within same dimension " + GCCoreUtil.getDimensionID(worldNew));
}
player.capabilities.isFlying = false;
GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_RESET_THIRD_PERSON, GCCoreUtil.getDimensionID(player.worldObj), new Object[] {}), player);
// Update PlayerStatsGC
GCPlayerStats stats = GCPlayerStats.get(player);
GCPlayerHandler.setUsingParachute(player, stats, false);
return player;
}
Aggregations