Fixed the Teleporting methods C:
This commit is contained in:
parent
4db4b458da
commit
3ae7e2759f
|
@ -1,10 +1,12 @@
|
|||
package WayofTime.alchemicalWizardry.common.spell.complex.effect;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import WayofTime.alchemicalWizardry.AlchemicalWizardry;
|
||||
import WayofTime.alchemicalWizardry.api.alchemy.energy.IAlchemyGoggles;
|
||||
import WayofTime.alchemicalWizardry.api.items.interfaces.IReagentManipulator;
|
||||
import WayofTime.alchemicalWizardry.api.soulNetwork.SoulNetworkHandler;
|
||||
import WayofTime.alchemicalWizardry.api.spell.APISpellHelper;
|
||||
import WayofTime.alchemicalWizardry.common.NewPacketHandler;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockLiquid;
|
||||
import net.minecraft.entity.Entity;
|
||||
|
@ -20,10 +22,12 @@ import net.minecraft.item.ItemBlock;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.FurnaceRecipes;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.play.server.S06PacketUpdateHealth;
|
||||
import net.minecraft.network.play.server.S07PacketRespawn;
|
||||
import net.minecraft.network.play.server.S1DPacketEntityEffect;
|
||||
import net.minecraft.network.play.server.S1FPacketSetExperience;
|
||||
import net.minecraft.potion.PotionEffect;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.management.ServerConfigurationManager;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
|
@ -33,13 +37,11 @@ import net.minecraft.world.WorldServer;
|
|||
import net.minecraftforge.common.util.FakePlayer;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import WayofTime.alchemicalWizardry.AlchemicalWizardry;
|
||||
import WayofTime.alchemicalWizardry.api.alchemy.energy.IAlchemyGoggles;
|
||||
import WayofTime.alchemicalWizardry.api.items.interfaces.IReagentManipulator;
|
||||
import WayofTime.alchemicalWizardry.api.soulNetwork.SoulNetworkHandler;
|
||||
import WayofTime.alchemicalWizardry.api.spell.APISpellHelper;
|
||||
import WayofTime.alchemicalWizardry.common.NewPacketHandler;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class SpellHelper
|
||||
{
|
||||
|
@ -501,63 +503,104 @@ public class SpellHelper
|
|||
return false;
|
||||
}
|
||||
|
||||
//Adapated from Enhanced Portals 3 code
|
||||
public static Entity teleportEntityToDim(World oldWorld, World newWorld, int x, int y, int z, Entity entity)
|
||||
public static Entity teleportEntitySameDim(int x, int y, int z, Entity entity)
|
||||
{
|
||||
if (entity != null)
|
||||
{
|
||||
WorldServer oldWorldServer = (WorldServer) oldWorld;
|
||||
WorldServer newWorldServer = (WorldServer) newWorld;
|
||||
if (entity instanceof EntityPlayer)
|
||||
if (entity.timeUntilPortal <= 0)
|
||||
{
|
||||
EntityPlayerMP player = (EntityPlayerMP) entity;
|
||||
if (!player.worldObj.isRemote)
|
||||
if (entity instanceof EntityPlayer)
|
||||
{
|
||||
player.worldObj.theProfiler.startSection("portal");
|
||||
player.worldObj.theProfiler.startSection("changeDimension");
|
||||
ServerConfigurationManager config = player.mcServer.getConfigurationManager();
|
||||
player.closeScreen();
|
||||
player.dimension = newWorldServer.provider.dimensionId;
|
||||
player.playerNetServerHandler.sendPacket(new S07PacketRespawn(player.dimension, player.worldObj.difficultySetting, newWorldServer.getWorldInfo().getTerrainType(), player.theItemInWorldManager.getGameType()));
|
||||
oldWorldServer.removeEntity(player);
|
||||
player.isDead = false;
|
||||
player.setLocationAndAngles(x, y, z, player.rotationYaw, player.rotationPitch);
|
||||
newWorldServer.spawnEntityInWorld(player);
|
||||
player.setWorld(newWorldServer);
|
||||
config.func_72375_a(player, oldWorldServer);
|
||||
player.playerNetServerHandler.setPlayerLocation(x, y, z, entity.rotationYaw, entity.rotationPitch);
|
||||
player.theItemInWorldManager.setWorld(newWorldServer);
|
||||
config.updateTimeAndWeatherForPlayer(player, newWorldServer);
|
||||
config.syncPlayerInventory(player);
|
||||
EntityPlayerMP player = (EntityPlayerMP) entity;
|
||||
player.setPositionAndUpdate(x, y, z);
|
||||
player.worldObj.updateEntityWithOptionalForce(player, false);
|
||||
player.playerNetServerHandler.sendPacket(new S06PacketUpdateHealth(player.getHealth(), player.getFoodStats().getFoodLevel(), player.getFoodStats().getSaturationLevel()));
|
||||
player.timeUntilPortal = 150;
|
||||
player.worldObj.playSoundEffect(x, y, z, "mob.endermen.portal", 1.0F, 1.0F);
|
||||
return player;
|
||||
} else
|
||||
{
|
||||
WorldServer world = (WorldServer) entity.worldObj;
|
||||
if (entity != null)
|
||||
{
|
||||
entity.setPosition(x, y, z);
|
||||
entity.timeUntilPortal = 150;
|
||||
}
|
||||
world.resetUpdateEntityTick();
|
||||
entity.worldObj.playSoundEffect(x, y, z, "mob.endermen.portal", 1.0F, 1.0F);
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
//Adapated from Enhanced Portals 3 code
|
||||
public static Entity teleportEntityToDim(World oldWorld, int newWorldID, int x, int y, int z, Entity entity)
|
||||
{
|
||||
if (entity != null)
|
||||
{
|
||||
if (entity.timeUntilPortal <= 0)
|
||||
{
|
||||
WorldServer oldWorldServer = MinecraftServer.getServer().worldServerForDimension(entity.dimension);
|
||||
WorldServer newWorldServer = MinecraftServer.getServer().worldServerForDimension(newWorldID);
|
||||
if (entity instanceof EntityPlayer)
|
||||
{
|
||||
EntityPlayerMP player = (EntityPlayerMP) entity;
|
||||
if (!player.worldObj.isRemote)
|
||||
{
|
||||
player.worldObj.theProfiler.startSection("portal");
|
||||
player.worldObj.theProfiler.startSection("changeDimension");
|
||||
ServerConfigurationManager config = player.mcServer.getConfigurationManager();
|
||||
oldWorld.playSoundEffect(player.posX, player.posY, player.posZ, "mob.endermen.portal", 1.0F, 1.0F);
|
||||
player.closeScreen();
|
||||
player.dimension = newWorldServer.provider.dimensionId;
|
||||
player.playerNetServerHandler.sendPacket(new S07PacketRespawn(player.dimension, player.worldObj.difficultySetting, newWorldServer.getWorldInfo().getTerrainType(), player.theItemInWorldManager.getGameType()));
|
||||
oldWorldServer.removeEntity(player);
|
||||
player.isDead = false;
|
||||
player.setLocationAndAngles(x, y, z, player.rotationYaw, player.rotationPitch);
|
||||
newWorldServer.spawnEntityInWorld(player);
|
||||
player.setWorld(newWorldServer);
|
||||
config.func_72375_a(player, oldWorldServer);
|
||||
player.playerNetServerHandler.setPlayerLocation(x, y, z, entity.rotationYaw, entity.rotationPitch);
|
||||
player.theItemInWorldManager.setWorld(newWorldServer);
|
||||
config.updateTimeAndWeatherForPlayer(player, newWorldServer);
|
||||
config.syncPlayerInventory(player);
|
||||
player.worldObj.theProfiler.endSection();
|
||||
oldWorldServer.resetUpdateEntityTick();
|
||||
newWorldServer.resetUpdateEntityTick();
|
||||
player.worldObj.theProfiler.endSection();
|
||||
for (Iterator<PotionEffect> potion = player.getActivePotionEffects().iterator(); potion.hasNext(); )
|
||||
{
|
||||
player.playerNetServerHandler.sendPacket(new S1DPacketEntityEffect(player.getEntityId(), potion.next()));
|
||||
}
|
||||
player.playerNetServerHandler.sendPacket(new S1FPacketSetExperience(player.experience, player.experienceTotal, player.experienceLevel));
|
||||
FMLCommonHandler.instance().firePlayerChangedDimensionEvent(player, oldWorldServer.provider.dimensionId, player.dimension);
|
||||
player.timeUntilPortal = 150;
|
||||
}
|
||||
player.worldObj.theProfiler.endSection();
|
||||
newWorldServer.playSoundEffect(x, y, z, "mob.endermen.portal", 1.0F, 1.0F);
|
||||
return player;
|
||||
} else
|
||||
{
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
entity.writeToNBTOptional(tag);
|
||||
entity.setDead();
|
||||
oldWorld.playSoundEffect(entity.posX, entity.posY, entity.posZ, "mob.endermen.portal", 1.0F, 1.0F);
|
||||
Entity teleportedEntity = EntityList.createEntityFromNBT(tag, newWorldServer);
|
||||
if (teleportedEntity != null)
|
||||
{
|
||||
teleportedEntity.setLocationAndAngles(x, y, z, entity.rotationYaw, entity.rotationPitch);
|
||||
teleportedEntity.forceSpawn = true;
|
||||
newWorldServer.spawnEntityInWorld(teleportedEntity);
|
||||
teleportedEntity.setWorld(newWorldServer);
|
||||
teleportedEntity.timeUntilPortal = 150;
|
||||
}
|
||||
oldWorldServer.resetUpdateEntityTick();
|
||||
newWorldServer.resetUpdateEntityTick();
|
||||
player.worldObj.theProfiler.endSection();
|
||||
for (Iterator<PotionEffect> potion = player.getActivePotionEffects().iterator(); potion.hasNext(); )
|
||||
{
|
||||
player.playerNetServerHandler.sendPacket(new S1DPacketEntityEffect(player.getEntityId(), (PotionEffect) potion.next()));
|
||||
}
|
||||
player.playerNetServerHandler.sendPacket(new S1FPacketSetExperience(player.experience, player.experienceTotal, player.experienceLevel));
|
||||
FMLCommonHandler.instance().firePlayerChangedDimensionEvent(player, oldWorldServer.provider.dimensionId, player.dimension);
|
||||
newWorldServer.playSoundEffect(x, y, z, "mob.endermen.portal", 1.0F, 1.0F);
|
||||
return teleportedEntity;
|
||||
}
|
||||
player.worldObj.theProfiler.endSection();
|
||||
return player;
|
||||
}
|
||||
else
|
||||
{
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
entity.writeToNBTOptional(tag);
|
||||
entity.setDead();
|
||||
Entity teleportedEntity = EntityList.createEntityFromNBT(tag, newWorldServer);
|
||||
if (teleportedEntity != null) {
|
||||
teleportedEntity.setLocationAndAngles(x, y, z, entity.rotationYaw, entity.rotationPitch);
|
||||
teleportedEntity.forceSpawn = true;
|
||||
newWorldServer.spawnEntityInWorld(teleportedEntity);
|
||||
teleportedEntity.setWorld(newWorldServer);
|
||||
}
|
||||
oldWorldServer.resetUpdateEntityTick();
|
||||
oldWorldServer.resetUpdateEntityTick();
|
||||
return teleportedEntity;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
|
Loading…
Reference in a new issue