content: package net.minecraft.entity.projectile;
  
  import net.minecraft.block.Block;
  import net.minecraft.entity.Entity;
  import net.minecraft.entity.EntityLivingBase;
  import net.minecraft.entity.IProjectile;
  import net.minecraft.entity.player.EntityPlayer;
  import net.minecraft.init.Blocks;
  import net.minecraft.nbt.NBTTagCompound;
  import net.minecraft.util.*;
  import net.minecraft.world.World;
  import net.minecraft.world.WorldServer;
  
  import java.util.List;
  import java.util.UUID;
  
  public abstract class EntityThrowable extends Entity implements IProjectile {
      private int xTile = -1;
      private int yTile = -1;
      private int zTile = -1;
      private Block inTile;
      protected boolean inGround;
      public int throwableShake;
      private EntityLivingBase thrower;
      private String throwerName;
      private int ticksInGround;
      private int ticksInAir;
  
      public EntityThrowable(World worldIn) {
          super(worldIn);
          this.setSize(0.25F, 0.25F);
      }
  
      protected void entityInit() {
      }
  
      public boolean isInRangeToRenderDist(double distance) {
          double d0 = this.getEntityBoundingBox().getAverageEdgeLength() * 4.0D;
  
          if (Double.isNaN(d0)) {
              d0 = 4.0D;
          }
  
          d0 = d0 * 64.0D;
          return distance < d0 * d0;
      }
  
      public EntityThrowable(World worldIn, EntityLivingBase throwerIn) {
          super(worldIn);
          this.thrower = throwerIn;
          this.setSize(0.25F, 0.25F);
          this.setLocationAndAngles(throwerIn.posX, throwerIn.posY + (double) throwerIn.getEyeHeight(), throwerIn.posZ, throwerIn.rotationYaw, throwerIn.rotationPitch);
          this.posX -= MathHelper.cos(this.rotationYaw / 180.0F * (float) Math.PI) * 0.16F;
          this.posY -= 0.10000000149011612D;
          this.posZ -= MathHelper.sin(this.rotationYaw / 180.0F * (float) Math.PI) * 0.16F;
          this.setPosition(this.posX, this.posY, this.posZ);
          float f = 0.4F;
          this.motionX = -MathHelper.sin(this.rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(this.rotationPitch / 180.0F * (float) Math.PI) * f;
          this.motionZ = MathHelper.cos(this.rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(this.rotationPitch / 180.0F * (float) Math.PI) * f;
          this.motionY = -MathHelper.sin((this.rotationPitch + this.getInaccuracy()) / 180.0F * (float) Math.PI) * f;
          this.setThrowableHeading(this.motionX, this.motionY, this.motionZ, this.getVelocity(), 1.0F);
      }
  
      public EntityThrowable(World worldIn, double x, double y, double z) {
          super(worldIn);
          this.ticksInGround = 0;
          this.setSize(0.25F, 0.25F);
          this.setPosition(x, y, z);
      }
  
      protected float getVelocity() {
          return 1.5F;
      }
  
      protected float getInaccuracy() {
          return 0.0F;
      }
  
      public void setThrowableHeading(double x, double y, double z, float velocity, float inaccuracy) {
          float f = MathHelper.sqrt_double(x * x + y * y + z * z);
          x = x / (double) f;
          y = y / (double) f;
          z = z / (double) f;
          x = x + this.rand.nextGaussian() * 0.007499999832361937D * (double) inaccuracy;
          y = y + this.rand.nextGaussian() * 0.007499999832361937D * (double) inaccuracy;
          z = z + this.rand.nextGaussian() * 0.007499999832361937D * (double) inaccuracy;
          x = x * (double) velocity;
          y = y * (double) velocity;
          z = z * (double) velocity;
          this.motionX = x;
          this.motionY = y;
          this.motionZ = z;
          float f1 = MathHelper.sqrt_double(x * x + z * z);
          this.prevRotationYaw = this.rotationYaw = (float) (MathHelper.atan2(x, z) * 180.0D / Math.PI);
          this.prevRotationPitch = this.rotationPitch = (float) (MathHelper.atan2(y, f1) * 180.0D / Math.PI);
          this.ticksInGround = 0;
      }
  
      public void setVelocity(double x, double y, double z) {
          this.motionX = x;
          this.motionY = y;
          this.motionZ = z;
  
          if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F) {
              float f = MathHelper.sqrt_double(x * x + z * z);
              this.prevRotationYaw = this.rotationYaw = (float) (MathHelper.atan2(x, z) * 180.0D / Math.PI);
              this.prevRotationPitch = this.rotationPitch = (float) (MathHelper.atan2(y, f) * 180.0D / Math.PI);
          }
      }
  
      public void onUpdate() {
          this.lastTickPosX = this.posX;
          this.lastTickPosY = this.posY;
          this.lastTickPosZ = this.posZ;
          super.onUpdate();
  
          if (this.throwableShake > 0) {
              --this.throwableShake;
          }
  
          if (this.inGround) {
              if (this.worldObj.getBlockState(new BlockPos(this.xTile, this.yTile, this.zTile)).getBlock() == this.inTile) {
                  ++this.ticksInGround;
  
                  if (this.ticksInGround == 1200) {
                      this.setDead();
                  }
  
                  return;
              }
  
              this.inGround = false;
              this.motionX *= this.rand.nextFloat() * 0.2F;
              this.motionY *= this.rand.nextFloat() * 0.2F;
              this.motionZ *= this.rand.nextFloat() * 0.2F;
              this.ticksInGround = 0;
              this.ticksInAir = 0;
          } else {
              ++this.ticksInAir;
          }
  
          Vec3 vec3 = new Vec3(this.posX, this.posY, this.posZ);
          Vec3 vec31 = new Vec3(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
          MovingObjectPosition movingobjectposition = this.worldObj.rayTraceBlocks(vec3, vec31);
          vec3 = new Vec3(this.posX, this.posY, this.posZ);
          vec31 = new Vec3(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
  
          if (movingobjectposition != null) {
              vec31 = new Vec3(movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord);
          }
  
          if (!this.worldObj.isRemote) {
              Entity entity = null;
              List<Entity> list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().addCoord(this.motionX, this.motionY, this.motionZ).expand(1.0D, 1.0D, 1.0D));
              double d0 = 0.0D;
              EntityLivingBase entitylivingbase = this.getThrower();
  
              for (int j = 0; j < list.size(); ++j) {
                  Entity entity1 = list.get(j);
  
                  if (entity1.canBeCollidedWith() && (entity1 != entitylivingbase || this.ticksInAir >= 5)) {
                      float f = 0.3F;
                      AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().expand(f, f, f);
                      MovingObjectPosition movingobjectposition1 = axisalignedbb.calculateIntercept(vec3, vec31);
  
                      if (movingobjectposition1 != null) {
                          double d1 = vec3.squareDistanceTo(movingobjectposition1.hitVec);
  
                          if (d1 < d0 || d0 == 0.0D) {
                              entity = entity1;
                              d0 = d1;
                          }
                      }
                  }
              }
  
              if (entity != null) {
                  movingobjectposition = new MovingObjectPosition(entity);
              }
          }
  
          if (movingobjectposition != null) {
              if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK && this.worldObj.getBlockState(movingobjectposition.getBlockPos()).getBlock() == Blocks.portal) {
                  this.setPortal(movingobjectposition.getBlockPos());
              } else {
                  this.onImpact(movingobjectposition);
              }
          }
  
          this.posX += this.motionX;
          this.posY += this.motionY;
          this.posZ += this.motionZ;
          float f1 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
          this.rotationYaw = (float) (MathHelper.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
  
          for (this.rotationPitch = (float) (MathHelper.atan2(this.motionY, f1) * 180.0D / Math.PI); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F) {
          }
  
          while (this.rotationPitch - this.prevRotationPitch >= 180.0F) {
              this.prevRotationPitch += 360.0F;
          }
  
          while (this.rotationYaw - this.prevRotationYaw < -180.0F) {
              this.prevRotationYaw -= 360.0F;
          }
  
          while (this.rotationYaw - this.prevRotationYaw >= 180.0F) {
              this.prevRotationYaw += 360.0F;
          }
  
          this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;
          this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;
          float f2 = 0.99F;
          float f3 = this.getGravityVelocity();
  
          if (this.isInWater()) {
              for (int i = 0; i < 4; ++i) {
                  float f4 = 0.25F;
                  this.worldObj.spawnParticle(EnumParticleTypes.WATER_BUBBLE, this.posX - this.motionX * (double) f4, this.posY - this.motionY * (double) f4, this.posZ - this.motionZ * (double) f4, this.motionX, this.motionY, this.motionZ);
              }
  
              f2 = 0.8F;
          }
  
          this.motionX *= f2;
          this.motionY *= f2;
          this.motionZ *= f2;
          this.motionY -= f3;
          this.setPosition(this.posX, this.posY, this.posZ);
      }
  
      protected float getGravityVelocity() {
          return 0.03F;
      }
  
      protected abstract void onImpact(MovingObjectPosition p_70184_1_);
  
      public void writeEntityToNBT(NBTTagCompound tagCompound) {
          tagCompound.setShort("xTile", (short) this.xTile);
          tagCompound.setShort("yTile", (short) this.yTile);
          tagCompound.setShort("zTile", (short) this.zTile);
          ResourceLocation resourcelocation = Block.blockRegistry.getNameForObject(this.inTile);
          tagCompound.setString("inTile", resourcelocation == null ? "" : resourcelocation.toString());
          tagCompound.setByte("shake", (byte) this.throwableShake);
          tagCompound.setByte("inGround", (byte) (this.inGround ? 1 : 0));
  
          if ((this.throwerName == null || this.throwerName.length() == 0) && this.thrower instanceof EntityPlayer) {
              this.throwerName = this.thrower.getName();
          }
  
          tagCompound.setString("ownerName", this.throwerName == null ? "" : this.throwerName);
      }
  
      public void readEntityFromNBT(NBTTagCompound tagCompund) {
          this.xTile = tagCompund.getShort("xTile");
          this.yTile = tagCompund.getShort("yTile");
          this.zTile = tagCompund.getShort("zTile");
  
          if (tagCompund.hasKey("inTile", 8)) {
              this.inTile = Block.getBlockFromName(tagCompund.getString("inTile"));
          } else {
              this.inTile = Block.getBlockById(tagCompund.getByte("inTile") & 255);
          }
  
          this.throwableShake = tagCompund.getByte("shake") & 255;
          this.inGround = tagCompund.getByte("inGround") == 1;
          this.thrower = null;
          this.throwerName = tagCompund.getString("ownerName");
  
          if (this.throwerName != null && this.throwerName.length() == 0) {
              this.throwerName = null;
          }
  
          this.thrower = this.getThrower();
      }
  
      public EntityLivingBase getThrower() {
          if (this.thrower == null && this.throwerName != null && this.throwerName.length() > 0) {
              this.thrower = this.worldObj.getPlayerEntityByName(this.throwerName);
  
              if (this.thrower == null && this.worldObj instanceof WorldServer) {
                  try {
                      Entity entity = ((WorldServer) this.worldObj).getEntityFromUuid(UUID.fromString(this.throwerName));
  
                      if (entity instanceof EntityLivingBase) {
                          this.thrower = (EntityLivingBase) entity;
                      }
                  } catch (Throwable var2) {
                      this.thrower = null;
                  }
              }
          }
  
          return this.thrower;
      }
  }
  