graywolf69

Custom Arrow Entity

Apr 19th, 2015
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 25.84 KB | None | 0 0
  1. package com.wolfreign.entity;
  2.  
  3. import cpw.mods.fml.relauncher.Side;
  4. import cpw.mods.fml.relauncher.SideOnly;
  5.  
  6. import java.util.List;
  7.  
  8. import com.wolfreign.item.ItemMaterials;
  9. import com.wolfreign.item.wBow;
  10.  
  11. import net.minecraft.block.Block;
  12. import net.minecraft.block.material.Material;
  13. import net.minecraft.enchantment.EnchantmentHelper;
  14. import net.minecraft.entity.Entity;
  15. import net.minecraft.entity.EntityLivingBase;
  16. import net.minecraft.entity.IProjectile;
  17. import net.minecraft.entity.monster.EntityEnderman;
  18. import net.minecraft.entity.player.EntityPlayer;
  19. import net.minecraft.entity.player.EntityPlayerMP;
  20. import net.minecraft.entity.projectile.EntityArrow;
  21. import net.minecraft.init.Items;
  22. import net.minecraft.item.ItemStack;
  23. import net.minecraft.nbt.NBTTagCompound;
  24. import net.minecraft.network.play.server.S2BPacketChangeGameState;
  25. import net.minecraft.util.AxisAlignedBB;
  26. import net.minecraft.util.DamageSource;
  27. import net.minecraft.util.MathHelper;
  28. import net.minecraft.util.MovingObjectPosition;
  29. import net.minecraft.util.Vec3;
  30. import net.minecraft.world.World;
  31.  
  32. public class EntityWolftaniumArrow extends EntityArrow implements IProjectile
  33. {
  34.     private int field_145791_d = -1;
  35.     private int field_145792_e = -1;
  36.     private int field_145789_f = -1;
  37.     private Block field_145790_g;
  38.     private int inData;
  39.     private boolean inGround;
  40.     /** 1 if the player can pick up the arrow */
  41.     public int canBePickedUp;
  42.     /** Seems to be some sort of timer for animating an arrow. */
  43.     public int arrowShake;
  44.     /** The owner of this arrow. */
  45.     public Entity shootingEntity;
  46.     private int ticksInGround;
  47.     private int ticksInAir;
  48.     private double damage = 10.0D;
  49.     /** The amount of knockback an arrow applies when it hits a mob. */
  50.     private int knockbackStrength;
  51.     private static final String __OBFID = "CL_00001715";
  52.     public boolean explode = false;
  53.    
  54.     public EntityWolftaniumArrow(World p_i1753_1_)
  55.     {
  56.         super(p_i1753_1_);
  57.         this.renderDistanceWeight = 10.0D;
  58.         this.setSize(0.5F, 0.5F);
  59.     }
  60.  
  61.     public EntityWolftaniumArrow(World p_i1754_1_, double p_i1754_2_, double p_i1754_4_, double p_i1754_6_)
  62.     {
  63.         super(p_i1754_1_);
  64.         this.renderDistanceWeight = 10.0D;
  65.         this.setSize(0.5F, 0.5F);
  66.         this.setPosition(p_i1754_2_, p_i1754_4_, p_i1754_6_);
  67.         this.yOffset = 0.0F;
  68.     }
  69.  
  70.     public EntityWolftaniumArrow(World p_i1755_1_, EntityLivingBase p_i1755_2_, EntityLivingBase p_i1755_3_, float p_i1755_4_, float p_i1755_5_)
  71.     {
  72.         super(p_i1755_1_);
  73.         this.renderDistanceWeight = 10.0D;
  74.         this.shootingEntity = p_i1755_2_;
  75.  
  76.         if (p_i1755_2_ instanceof EntityPlayer)
  77.         {
  78.             this.canBePickedUp = 1;
  79.         }
  80.  
  81.         this.posY = p_i1755_2_.posY + (double)p_i1755_2_.getEyeHeight() - 0.10000000149011612D;
  82.         double d0 = p_i1755_3_.posX - p_i1755_2_.posX;
  83.         double d1 = p_i1755_3_.boundingBox.minY + (double)(p_i1755_3_.height / 3.0F) - this.posY;
  84.         double d2 = p_i1755_3_.posZ - p_i1755_2_.posZ;
  85.         double d3 = (double)MathHelper.sqrt_double(d0 * d0 + d2 * d2);
  86.  
  87.         if (d3 >= 1.0E-7D)
  88.         {
  89.             float f2 = (float)(Math.atan2(d2, d0) * 180.0D / Math.PI) - 90.0F;
  90.             float f3 = (float)(-(Math.atan2(d1, d3) * 180.0D / Math.PI));
  91.             double d4 = d0 / d3;
  92.             double d5 = d2 / d3;
  93.             this.setLocationAndAngles(p_i1755_2_.posX + d4, this.posY, p_i1755_2_.posZ + d5, f2, f3);
  94.             this.yOffset = 0.0F;
  95.             float f4 = (float)d3 * 0.2F;
  96.             this.setThrowableHeading(d0, d1 + (double)f4, d2, p_i1755_4_, p_i1755_5_);
  97.         }
  98.     }
  99.  
  100.     public EntityWolftaniumArrow(World p_i1756_1_, EntityLivingBase p_i1756_2_, float p_i1756_3_)
  101.     {
  102.         super(p_i1756_1_);
  103.         this.renderDistanceWeight = 10.0D;
  104.         this.shootingEntity = p_i1756_2_;
  105.  
  106.         if (p_i1756_2_ instanceof EntityPlayer)
  107.         {
  108.             this.canBePickedUp = 1;
  109.         }
  110.  
  111.         this.setSize(0.5F, 0.5F);
  112.         this.setLocationAndAngles(p_i1756_2_.posX, p_i1756_2_.posY + (double)p_i1756_2_.getEyeHeight(), p_i1756_2_.posZ, p_i1756_2_.rotationYaw, p_i1756_2_.rotationPitch);
  113.         this.posX -= (double)(MathHelper.cos(this.rotationYaw / 180.0F * (float)Math.PI) * 0.16F);
  114.         this.posY -= 0.10000000149011612D;
  115.         this.posZ -= (double)(MathHelper.sin(this.rotationYaw / 180.0F * (float)Math.PI) * 0.16F);
  116.         this.setPosition(this.posX, this.posY, this.posZ);
  117.         this.yOffset = 0.0F;
  118.         this.motionX = (double)(-MathHelper.sin(this.rotationYaw / 180.0F * (float)Math.PI) * MathHelper.cos(this.rotationPitch / 180.0F * (float)Math.PI));
  119.         this.motionZ = (double)(MathHelper.cos(this.rotationYaw / 180.0F * (float)Math.PI) * MathHelper.cos(this.rotationPitch / 180.0F * (float)Math.PI));
  120.         this.motionY = (double)(-MathHelper.sin(this.rotationPitch / 180.0F * (float)Math.PI));
  121.         this.setThrowableHeading(this.motionX, this.motionY, this.motionZ, p_i1756_3_ * 1.5F, 1.0F);
  122.     }
  123.  
  124.     protected void entityInit()
  125.     {
  126.         this.dataWatcher.addObject(16, Byte.valueOf((byte)0));
  127.     }
  128.  
  129.     /**
  130.      * Similar to setArrowHeading, it's point the throwable entity to a x, y, z direction.
  131.      */
  132.     public void setThrowableHeading(double p_70186_1_, double p_70186_3_, double p_70186_5_, float p_70186_7_, float p_70186_8_)
  133.     {
  134.         float f2 = MathHelper.sqrt_double(p_70186_1_ * p_70186_1_ + p_70186_3_ * p_70186_3_ + p_70186_5_ * p_70186_5_);
  135.         p_70186_1_ /= (double)f2;
  136.         p_70186_3_ /= (double)f2;
  137.         p_70186_5_ /= (double)f2;
  138.         p_70186_1_ += this.rand.nextGaussian() * (double)(this.rand.nextBoolean() ? -1 : 1) * 0.007499999832361937D * (double)p_70186_8_;
  139.         p_70186_3_ += this.rand.nextGaussian() * (double)(this.rand.nextBoolean() ? -1 : 1) * 0.007499999832361937D * (double)p_70186_8_;
  140.         p_70186_5_ += this.rand.nextGaussian() * (double)(this.rand.nextBoolean() ? -1 : 1) * 0.007499999832361937D * (double)p_70186_8_;
  141.         p_70186_1_ *= (double)p_70186_7_;
  142.         p_70186_3_ *= (double)p_70186_7_;
  143.         p_70186_5_ *= (double)p_70186_7_;
  144.         this.motionX = p_70186_1_;
  145.         this.motionY = p_70186_3_;
  146.         this.motionZ = p_70186_5_;
  147.         float f3 = MathHelper.sqrt_double(p_70186_1_ * p_70186_1_ + p_70186_5_ * p_70186_5_);
  148.         this.prevRotationYaw = this.rotationYaw = (float)(Math.atan2(p_70186_1_, p_70186_5_) * 180.0D / Math.PI);
  149.         this.prevRotationPitch = this.rotationPitch = (float)(Math.atan2(p_70186_3_, (double)f3) * 180.0D / Math.PI);
  150.         this.ticksInGround = 0;
  151.     }
  152.  
  153.     /**
  154.      * Sets the position and rotation. Only difference from the other one is no bounding on the rotation. Args: posX,
  155.      * posY, posZ, yaw, pitch
  156.      */
  157.     @SideOnly(Side.CLIENT)
  158.     public void setPositionAndRotation2(double p_70056_1_, double p_70056_3_, double p_70056_5_, float p_70056_7_, float p_70056_8_, int p_70056_9_)
  159.     {
  160.         this.setPosition(p_70056_1_, p_70056_3_, p_70056_5_);
  161.         this.setRotation(p_70056_7_, p_70056_8_);
  162.     }
  163.  
  164.     /**
  165.      * Sets the velocity to the args. Args: x, y, z
  166.      */
  167.     @SideOnly(Side.CLIENT)
  168.     public void setVelocity(double p_70016_1_, double p_70016_3_, double p_70016_5_)
  169.     {
  170.         this.motionX = p_70016_1_;
  171.         this.motionY = p_70016_3_;
  172.         this.motionZ = p_70016_5_;
  173.  
  174.         if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F)
  175.         {
  176.             float f = MathHelper.sqrt_double(p_70016_1_ * p_70016_1_ + p_70016_5_ * p_70016_5_);
  177.             this.prevRotationYaw = this.rotationYaw = (float)(Math.atan2(p_70016_1_, p_70016_5_) * 180.0D / Math.PI);
  178.             this.prevRotationPitch = this.rotationPitch = (float)(Math.atan2(p_70016_3_, (double)f) * 180.0D / Math.PI);
  179.             this.prevRotationPitch = this.rotationPitch;
  180.             this.prevRotationYaw = this.rotationYaw;
  181.             this.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch);
  182.             this.ticksInGround = 0;
  183.         }
  184.     }
  185.  
  186.     /**
  187.      * Called to update the entity's position/logic.
  188.      */
  189.     public void onUpdate()
  190.     {
  191.         super.onUpdate();
  192.  
  193.         if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F)
  194.         {
  195.             float f = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
  196.             this.prevRotationYaw = this.rotationYaw = (float)(Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
  197.             this.prevRotationPitch = this.rotationPitch = (float)(Math.atan2(this.motionY, (double)f) * 180.0D / Math.PI);
  198.         }
  199.  
  200.         Block block = this.worldObj.getBlock(this.field_145791_d, this.field_145792_e, this.field_145789_f);
  201.  
  202.         if (block.getMaterial() != Material.air)
  203.         {
  204.             block.setBlockBoundsBasedOnState(this.worldObj, this.field_145791_d, this.field_145792_e, this.field_145789_f);
  205.             AxisAlignedBB axisalignedbb = block.getCollisionBoundingBoxFromPool(this.worldObj, this.field_145791_d, this.field_145792_e, this.field_145789_f);
  206.  
  207.             if (axisalignedbb != null && axisalignedbb.isVecInside(Vec3.createVectorHelper(this.posX, this.posY, this.posZ)))
  208.             {
  209.                 this.inGround = true;
  210.                
  211.             }
  212.         }
  213.  
  214.         if (this.arrowShake > 0)
  215.         {
  216.             --this.arrowShake;
  217.         }
  218.  
  219.         if (this.inGround)
  220.         {
  221.             int j = this.worldObj.getBlockMetadata(this.field_145791_d, this.field_145792_e, this.field_145789_f);
  222.  
  223.             if (block == this.field_145790_g && j == this.inData)
  224.             {
  225.                 if(explode = false) {
  226.                
  227.                 ++this.ticksInGround;
  228.  
  229.                     if (this.ticksInGround == 1200) //set to 1 for explosion
  230.                     {
  231.                         this.setDead();
  232.                         //this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, 5.0F, true);
  233.                     }
  234.            
  235.                 }
  236.                 else {
  237.                     if (this.ticksInGround == 1) //set to 1 for explosion
  238.                     {
  239.                         this.setDead();
  240.                         this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, 5.0F, true);
  241.                     }
  242.                 }
  243.                    
  244.                
  245.         }
  246.             else
  247.             {
  248.                 this.inGround = false;
  249.                 this.motionX *= (double)(this.rand.nextFloat() * 0.2F);
  250.                 this.motionY *= (double)(this.rand.nextFloat() * 0.2F);
  251.                 this.motionZ *= (double)(this.rand.nextFloat() * 0.2F);
  252.                 this.ticksInGround = 0;
  253.                 this.ticksInAir = 0;
  254.             }
  255.         }
  256.         else
  257.         {
  258.             ++this.ticksInAir;
  259.             Vec3 vec31 = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
  260.             Vec3 vec3 = Vec3.createVectorHelper(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
  261.             MovingObjectPosition movingobjectposition = this.worldObj.func_147447_a(vec31, vec3, false, true, false);
  262.             vec31 = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
  263.             vec3 = Vec3.createVectorHelper(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
  264.  
  265.             if (movingobjectposition != null)
  266.             {
  267.                 vec3 = Vec3.createVectorHelper(movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord);
  268.             }
  269.  
  270.             Entity entity = null;
  271.             List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox.addCoord(this.motionX, this.motionY, this.motionZ).expand(1.0D, 1.0D, 1.0D));
  272.             double d0 = 0.0D;
  273.             int i;
  274.             float f1;
  275.  
  276.             for (i = 0; i < list.size(); ++i)
  277.             {
  278.                 Entity entity1 = (Entity)list.get(i);
  279.  
  280.                 if (entity1.canBeCollidedWith() && (entity1 != this.shootingEntity || this.ticksInAir >= 5))
  281.                 {
  282.                     f1 = 0.3F;
  283.                     AxisAlignedBB axisalignedbb1 = entity1.boundingBox.expand((double)f1, (double)f1, (double)f1);
  284.                     MovingObjectPosition movingobjectposition1 = axisalignedbb1.calculateIntercept(vec31, vec3);
  285.  
  286.                     if (movingobjectposition1 != null)
  287.                     {
  288.                         double d1 = vec31.distanceTo(movingobjectposition1.hitVec);
  289.  
  290.                         if (d1 < d0 || d0 == 0.0D)
  291.                         {
  292.                             entity = entity1;
  293.                             d0 = d1;
  294.                         }
  295.                     }
  296.                 }
  297.             }
  298.  
  299.             if (entity != null)
  300.             {
  301.                 movingobjectposition = new MovingObjectPosition(entity);
  302.             }
  303.  
  304.             if (movingobjectposition != null && movingobjectposition.entityHit != null && movingobjectposition.entityHit instanceof EntityPlayer)
  305.             {
  306.                 EntityPlayer entityplayer = (EntityPlayer)movingobjectposition.entityHit;
  307.  
  308.                 if (entityplayer.capabilities.disableDamage || this.shootingEntity instanceof EntityPlayer && !((EntityPlayer)this.shootingEntity).canAttackPlayer(entityplayer))
  309.                 {
  310.                     movingobjectposition = null;
  311.                 }
  312.             }
  313.  
  314.             float f2;
  315.             float f4;
  316.  
  317.             if (movingobjectposition != null)
  318.             {
  319.                 if (movingobjectposition.entityHit != null)
  320.                 {
  321.                     f2 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
  322.                     int k = MathHelper.ceiling_double_int((double)f2 * this.damage);
  323.  
  324.                     if (this.getIsCritical())
  325.                     {
  326.                         k += this.rand.nextInt(k / 2 + 2);
  327.                     }
  328.  
  329.                     DamageSource damagesource = null;
  330.  
  331.                     if (this.shootingEntity == null)
  332.                     {
  333.                         damagesource = DamageSource.causeThrownDamage(this, this);
  334.                     }
  335.                     else
  336.                     {
  337.                         damagesource = DamageSource.causeThrownDamage(this, this.shootingEntity);
  338.                     }
  339.  
  340.                     if (this.isBurning() && !(movingobjectposition.entityHit instanceof EntityEnderman))
  341.                     {
  342.                         movingobjectposition.entityHit.setFire(5);
  343.                     }
  344.  
  345.                     if (movingobjectposition.entityHit.attackEntityFrom(damagesource, (float)k))
  346.                     {
  347.                         if (movingobjectposition.entityHit instanceof EntityLivingBase)
  348.                         {
  349.                             EntityLivingBase entitylivingbase = (EntityLivingBase)movingobjectposition.entityHit;
  350.  
  351.                             if (!this.worldObj.isRemote)
  352.                             {
  353.                                 entitylivingbase.setArrowCountInEntity(entitylivingbase.getArrowCountInEntity() + 1);
  354.                             }
  355.  
  356.                             if (this.knockbackStrength > 0)
  357.                             {
  358.                                 f4 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
  359.  
  360.                                 if (f4 > 0.0F)
  361.                                 {
  362.                                     movingobjectposition.entityHit.addVelocity(this.motionX * (double)this.knockbackStrength * 0.6000000238418579D / (double)f4, 0.1D, this.motionZ * (double)this.knockbackStrength * 0.6000000238418579D / (double)f4);
  363.                                 }
  364.                             }
  365.  
  366.                             if (this.shootingEntity != null && this.shootingEntity instanceof EntityLivingBase)
  367.                             {
  368.                                 EnchantmentHelper.func_151384_a(entitylivingbase, this.shootingEntity);
  369.                                 EnchantmentHelper.func_151385_b((EntityLivingBase)this.shootingEntity, entitylivingbase);
  370.                             }
  371.  
  372.                             if (this.shootingEntity != null && movingobjectposition.entityHit != this.shootingEntity && movingobjectposition.entityHit instanceof EntityPlayer && this.shootingEntity instanceof EntityPlayerMP)
  373.                             {
  374.                                 ((EntityPlayerMP)this.shootingEntity).playerNetServerHandler.sendPacket(new S2BPacketChangeGameState(6, 0.0F));
  375.                             }
  376.                         }
  377.  
  378.                         this.playSound("random.bowhit", 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F));
  379.  
  380.                         if (!(movingobjectposition.entityHit instanceof EntityEnderman))
  381.                         {
  382.                             this.setDead();
  383.                         }
  384.                     }
  385.                     else
  386.                     {
  387.                         this.motionX *= -0.10000000149011612D;
  388.                         this.motionY *= -0.10000000149011612D;
  389.                         this.motionZ *= -0.10000000149011612D;
  390.                         this.rotationYaw += 180.0F;
  391.                         this.prevRotationYaw += 180.0F;
  392.                         this.ticksInAir = 0;
  393.                     }
  394.                 }
  395.                 else
  396.                 {
  397.                     this.field_145791_d = movingobjectposition.blockX;
  398.                     this.field_145792_e = movingobjectposition.blockY;
  399.                     this.field_145789_f = movingobjectposition.blockZ;
  400.                     this.field_145790_g = this.worldObj.getBlock(this.field_145791_d, this.field_145792_e, this.field_145789_f);
  401.                     this.inData = this.worldObj.getBlockMetadata(this.field_145791_d, this.field_145792_e, this.field_145789_f);
  402.                     this.motionX = (double)((float)(movingobjectposition.hitVec.xCoord - this.posX));
  403.                     this.motionY = (double)((float)(movingobjectposition.hitVec.yCoord - this.posY));
  404.                     this.motionZ = (double)((float)(movingobjectposition.hitVec.zCoord - this.posZ));
  405.                     f2 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
  406.                     this.posX -= this.motionX / (double)f2 * 0.05000000074505806D;
  407.                     this.posY -= this.motionY / (double)f2 * 0.05000000074505806D;
  408.                     this.posZ -= this.motionZ / (double)f2 * 0.05000000074505806D;
  409.                     this.playSound("random.bowhit", 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F));
  410.                     this.inGround = true;
  411.                     this.arrowShake = 7;
  412.                     this.setIsCritical(false);
  413.  
  414.                     if (this.field_145790_g.getMaterial() != Material.air)
  415.                     {
  416.                         this.field_145790_g.onEntityCollidedWithBlock(this.worldObj, this.field_145791_d, this.field_145792_e, this.field_145789_f, this);
  417.                     }
  418.                 }
  419.             }
  420.  
  421.             if (this.getIsCritical())
  422.             {
  423.                 for (i = 0; i < 4; ++i)
  424.                 {
  425.                     this.worldObj.spawnParticle("crit", this.posX + this.motionX * (double)i / 4.0D, this.posY + this.motionY * (double)i / 4.0D, this.posZ + this.motionZ * (double)i / 4.0D, -this.motionX, -this.motionY + 0.2D, -this.motionZ);
  426.                 }
  427.             }
  428.  
  429.             this.posX += this.motionX;
  430.             this.posY += this.motionY;
  431.             this.posZ += this.motionZ;
  432.             f2 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
  433.             this.rotationYaw = (float)(Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
  434.  
  435.             for (this.rotationPitch = (float)(Math.atan2(this.motionY, (double)f2) * 180.0D / Math.PI); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F)
  436.             {
  437.                 ;
  438.             }
  439.  
  440.             while (this.rotationPitch - this.prevRotationPitch >= 180.0F)
  441.             {
  442.                 this.prevRotationPitch += 360.0F;
  443.             }
  444.  
  445.             while (this.rotationYaw - this.prevRotationYaw < -180.0F)
  446.             {
  447.                 this.prevRotationYaw -= 360.0F;
  448.             }
  449.  
  450.             while (this.rotationYaw - this.prevRotationYaw >= 180.0F)
  451.             {
  452.                 this.prevRotationYaw += 360.0F;
  453.             }
  454.  
  455.             this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;
  456.             this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;
  457.             float f3 = 0.99F;
  458.             f1 = 0.05F;
  459.  
  460.             if (this.isInWater())
  461.             {
  462.                 for (int l = 0; l < 4; ++l)
  463.                 {
  464.                     f4 = 0.25F;
  465.                     this.worldObj.spawnParticle("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);
  466.                 }
  467.  
  468.                 f3 = 0.8F;
  469.             }
  470.  
  471.             if (this.isWet())
  472.             {
  473.                 this.extinguish();
  474.             }
  475.  
  476.             this.motionX *= (double)f3;
  477.             this.motionY *= (double)f3;
  478.             this.motionZ *= (double)f3;
  479.             this.motionY -= (double)f1;
  480.             this.setPosition(this.posX, this.posY, this.posZ);
  481.             this.func_145775_I();
  482.         }
  483.     }
  484.  
  485.     /**
  486.      * (abstract) Protected helper method to write subclass entity data to NBT.
  487.      */
  488.     public void writeEntityToNBT(NBTTagCompound p_70014_1_)
  489.     {
  490.         p_70014_1_.setShort("xTile", (short)this.field_145791_d);
  491.         p_70014_1_.setShort("yTile", (short)this.field_145792_e);
  492.         p_70014_1_.setShort("zTile", (short)this.field_145789_f);
  493.         p_70014_1_.setShort("life", (short)this.ticksInGround);
  494.         p_70014_1_.setByte("inTile", (byte)Block.getIdFromBlock(this.field_145790_g));
  495.         p_70014_1_.setByte("inData", (byte)this.inData);
  496.         p_70014_1_.setByte("shake", (byte)this.arrowShake);
  497.         p_70014_1_.setByte("inGround", (byte)(this.inGround ? 1 : 0));
  498.         p_70014_1_.setByte("pickup", (byte)this.canBePickedUp);
  499.         p_70014_1_.setDouble("damage", this.damage);
  500.     }
  501.  
  502.     /**
  503.      * (abstract) Protected helper method to read subclass entity data from NBT.
  504.      */
  505.     public void readEntityFromNBT(NBTTagCompound p_70037_1_)
  506.     {
  507.         this.field_145791_d = p_70037_1_.getShort("xTile");
  508.         this.field_145792_e = p_70037_1_.getShort("yTile");
  509.         this.field_145789_f = p_70037_1_.getShort("zTile");
  510.         this.ticksInGround = p_70037_1_.getShort("life");
  511.         this.field_145790_g = Block.getBlockById(p_70037_1_.getByte("inTile") & 255);
  512.         this.inData = p_70037_1_.getByte("inData") & 255;
  513.         this.arrowShake = p_70037_1_.getByte("shake") & 255;
  514.         this.inGround = p_70037_1_.getByte("inGround") == 1;
  515.  
  516.         if (p_70037_1_.hasKey("damage", 99))
  517.         {
  518.             this.damage = p_70037_1_.getDouble("damage");
  519.         }
  520.  
  521.         if (p_70037_1_.hasKey("pickup", 99))
  522.         {
  523.             this.canBePickedUp = p_70037_1_.getByte("pickup");
  524.         }
  525.         else if (p_70037_1_.hasKey("player", 99))
  526.         {
  527.             this.canBePickedUp = p_70037_1_.getBoolean("player") ? 1 : 0;
  528.         }
  529.     }
  530.  
  531.     /**
  532.      * Called by a player entity when they collide with an entity
  533.      */
  534.     public void onCollideWithPlayer(EntityPlayer p_70100_1_)
  535.     {
  536.         if (!this.worldObj.isRemote && this.inGround && this.arrowShake <= 0)
  537.         {
  538.             boolean flag = this.canBePickedUp == 1 || this.canBePickedUp == 2 && p_70100_1_.capabilities.isCreativeMode;
  539.  
  540.             if (this.canBePickedUp == 1 && !p_70100_1_.inventory.addItemStackToInventory(new ItemStack(Items.arrow, 1)))
  541.             {
  542.                 flag = false;
  543.             }
  544.  
  545.             if (flag)
  546.             {
  547.                 this.playSound("random.pop", 0.2F, ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
  548.                 p_70100_1_.onItemPickup(this, 1);
  549.                 this.setDead();
  550.             }
  551.         }
  552.     }
  553.  
  554.     /**
  555.      * returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to
  556.      * prevent them from trampling crops
  557.      */
  558.     protected boolean canTriggerWalking()
  559.     {
  560.         return false;
  561.     }
  562.  
  563.     @SideOnly(Side.CLIENT)
  564.     public float getShadowSize()
  565.     {
  566.         return 0.0F;
  567.     }
  568.  
  569.     public void setDamage(double p_70239_1_)
  570.     {
  571.         this.damage = p_70239_1_;
  572.     }
  573.  
  574.     public double getDamage()
  575.     {
  576.         return this.damage;
  577.     }
  578.  
  579.     /**
  580.      * Sets the amount of knockback the arrow applies when it hits a mob.
  581.      */
  582.     public void setKnockbackStrength(int p_70240_1_)
  583.     {
  584.         this.knockbackStrength = p_70240_1_;
  585.     }
  586.  
  587.     /**
  588.      * If returns false, the item will not inflict any damage against entities.
  589.      */
  590.     public boolean canAttackWithItem()
  591.     {
  592.         return false;
  593.     }
  594.  
  595.     /**
  596.      * Whether the arrow has a stream of critical hit particles flying behind it.
  597.      */
  598.     public void setIsCritical(boolean p_70243_1_)
  599.     {
  600.         byte b0 = this.dataWatcher.getWatchableObjectByte(16);
  601.  
  602.         if (p_70243_1_)
  603.         {
  604.             this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 | 1)));
  605.         }
  606.         else
  607.         {
  608.             this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 & -2)));
  609.         }
  610.     }
  611.  
  612.     /**
  613.      * Whether the arrow has a stream of critical hit particles flying behind it.
  614.      */
  615.     public boolean getIsCritical()
  616.     {
  617.         byte b0 = this.dataWatcher.getWatchableObjectByte(16);
  618.         return (b0 & 1) != 0;
  619.     }
  620.  
  621.  
  622. }
Advertisement
Add Comment
Please, Sign In to add comment