package net.minecraft.entity.item; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.projectile.EntityThrowable; import net.minecraft.util.DamageSource; import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.living.EnderTeleportEvent; public class EntityEnderPearl extends EntityThrowable { public EntityEnderPearl(World par1World) { super(par1World); } public EntityEnderPearl(World par1World, EntityLivingBase par2EntityLivingBase) { super(par1World, par2EntityLivingBase); } @SideOnly(Side.CLIENT) public EntityEnderPearl(World par1World, double par2, double par4, double par6) { super(par1World, par2, par4, par6); } /** * Called when this EntityThrowable hits a block or entity. */ protected void onImpact(MovingObjectPosition par1MovingObjectPosition) { if (par1MovingObjectPosition.entityHit != null) { par1MovingObjectPosition.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 0.0F); } for (int i = 0; i < 32; ++i) { this.worldObj.spawnParticle("portal", this.posX, this.posY + this.rand.nextDouble() * 2.0D, this.posZ, this.rand.nextGaussian(), 0.0D, this.rand.nextGaussian()); } if (!this.worldObj.isRemote) { if (this.getThrower() != null && this.getThrower() instanceof EntityPlayerMP) { EntityPlayerMP entityplayermp = (EntityPlayerMP) this.getThrower(); //--> modified code //iterates over the list of players in the world-Object to get the one thats referenced as the thrower of the enderpearl and updates the reference using the username EntityPlayerMP player = null; for(int i = 0; i < entityplayermp.worldObj.playerEntities.size(); i++) { if(((EntityPlayerMP)entityplayermp.worldObj.playerEntities.get(i)).username.equals(entityplayermp.username)) { player = (EntityPlayerMP) entityplayermp.worldObj.playerEntities.get(i); break; } } //actually updates the reference entityplayermp = player; //checks whether the player is older than the enderpearl. if so it teleports otherwise it just aborts if (entityplayermp != null && this.ticksExisted < entityplayermp.ticksExisted) { //Keep in mind that this fix only works as long as the chunk the enderpearl is in is loaded while the player is dead. //Otherwise the player could get older after respawning than the enderpearl so teleporting gets possible again. //To fix this the player and the enderpearl would need a timestamp to check the real age and not just the time they where loaded. //<-- modified code if (!entityplayermp.playerNetServerHandler.connectionClosed && entityplayermp.worldObj == this.worldObj) { EnderTeleportEvent event = new EnderTeleportEvent(entityplayermp, this.posX, this.posY, this.posZ, 5.0F); if (!MinecraftForge.EVENT_BUS.post(event)) { if (this.getThrower().isRiding()) { this.getThrower().mountEntity((Entity) null); } this.getThrower().setPositionAndUpdate(event.targetX, event.targetY, event.targetZ); this.getThrower().fallDistance = 0.0F; this.getThrower().attackEntityFrom(DamageSource.fall, event.attackDamage); } } } } this.setDead(); } } }