Advertisement
Guest User

Example EntityFishHook for Minecraft

a guest
Apr 25th, 2014
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 27.60 KB | None | 0 0
  1. package com.examplemod.entity;
  2.  
  3. import java.util.Arrays;
  4. import java.util.List;
  5.  
  6. import net.minecraft.block.Block;
  7. import net.minecraft.block.material.Material;
  8. import net.minecraft.enchantment.EnchantmentHelper;
  9. import net.minecraft.entity.Entity;
  10. import net.minecraft.entity.item.EntityItem;
  11. import net.minecraft.entity.item.EntityXPOrb;
  12. import net.minecraft.entity.player.EntityPlayer;
  13. import net.minecraft.entity.projectile.EntityFishHook;
  14. import net.minecraft.init.Blocks;
  15. import net.minecraft.init.Items;
  16. import net.minecraft.item.ItemFishFood;
  17. import net.minecraft.item.ItemStack;
  18. import net.minecraft.nbt.NBTTagCompound;
  19. import net.minecraft.stats.StatList;
  20. import net.minecraft.util.AxisAlignedBB;
  21. import net.minecraft.util.DamageSource;
  22. import net.minecraft.util.MathHelper;
  23. import net.minecraft.util.MovingObjectPosition;
  24. import net.minecraft.util.Vec3;
  25. import net.minecraft.util.WeightedRandom;
  26. import net.minecraft.util.WeightedRandomFishable;
  27. import net.minecraft.world.World;
  28. import net.minecraft.world.WorldServer;
  29. import cpw.mods.fml.relauncher.Side;
  30. import cpw.mods.fml.relauncher.SideOnly;
  31.  
  32. public class EntityExampleFishHook extends EntityFishHook
  33. {
  34.     @SuppressWarnings("rawtypes")
  35.     private static final List trashCatches = Arrays.asList(new WeightedRandomFishable[] {(new WeightedRandomFishable(new ItemStack(Items.leather_boots), 10)).func_150709_a(0.9F), new WeightedRandomFishable(new ItemStack(Items.leather), 10), new WeightedRandomFishable(new ItemStack(Items.bone), 10), new WeightedRandomFishable(new ItemStack(Items.potionitem), 10), new WeightedRandomFishable(new ItemStack(Items.string), 5), (new WeightedRandomFishable(new ItemStack(Items.fishing_rod), 2)).func_150709_a(0.9F), new WeightedRandomFishable(new ItemStack(Items.bowl), 10), new WeightedRandomFishable(new ItemStack(Items.stick), 5), new WeightedRandomFishable(new ItemStack(Items.dye, 10, 0), 1), new WeightedRandomFishable(new ItemStack(Blocks.tripwire_hook), 10), new WeightedRandomFishable(new ItemStack(Items.rotten_flesh), 10)});
  36.    
  37.     @SuppressWarnings("rawtypes")
  38.     private static final List treasureCatches = Arrays.asList(new WeightedRandomFishable[] {new WeightedRandomFishable(new ItemStack(Blocks.waterlily), 1), new WeightedRandomFishable(new ItemStack(Items.name_tag), 1), new WeightedRandomFishable(new ItemStack(Items.saddle), 1), (new WeightedRandomFishable(new ItemStack(Items.bow), 1)).func_150709_a(0.25F).func_150707_a(), (new WeightedRandomFishable(new ItemStack(Items.fishing_rod), 1)).func_150709_a(0.25F).func_150707_a(), (new WeightedRandomFishable(new ItemStack(Items.book), 1)).func_150707_a()});
  39.    
  40.     @SuppressWarnings("rawtypes")
  41.     private static final List fishCatches = Arrays.asList(new WeightedRandomFishable[] {new WeightedRandomFishable(new ItemStack(Items.fish, 1, ItemFishFood.FishType.COD.func_150976_a()), 60), new WeightedRandomFishable(new ItemStack(Items.fish, 1, ItemFishFood.FishType.SALMON.func_150976_a()), 25), new WeightedRandomFishable(new ItemStack(Items.fish, 1, ItemFishFood.FishType.CLOWNFISH.func_150976_a()), 2), new WeightedRandomFishable(new ItemStack(Items.fish, 1, ItemFishFood.FishType.PUFFERFISH.func_150976_a()), 13)});
  42.     private int xTile;
  43.     private int yTile;
  44.     private int zTile;
  45.     private Block tileID;
  46.     private boolean inGround;
  47.     public int shakeTime;
  48.     public EntityPlayer playerObj;
  49.     private int groundTime;
  50.     private int airTime;
  51.     private int hasCatchedFish;
  52.     private int fishSpeed;
  53.     private int hookedTicks;
  54.     private float swayTicks;
  55.     public Entity hookedEntity;
  56.     private int thrownDirection;
  57.     private double headedX;
  58.     private double headedY;
  59.     private double headedZ;
  60.     private double renderYaw;
  61.     private double renderPitch;
  62.     @SideOnly(Side.CLIENT)
  63.     private double velocityX;
  64.     @SideOnly(Side.CLIENT)
  65.     private double velocityY;
  66.     @SideOnly(Side.CLIENT)
  67.     private double velocityZ;
  68.  
  69.     public EntityExampleFishHook(World par1World)
  70.     {
  71.         super(par1World);
  72.         this.xTile = -1;
  73.         this.yTile = -1;
  74.         this.zTile = -1;
  75.         this.setSize(0.25F, 0.25F);
  76.         this.ignoreFrustumCheck = true;
  77.     }
  78.  
  79.     @SideOnly(Side.CLIENT)
  80.     public EntityExampleFishHook(World par1World, double par2, double par4, double par6, EntityPlayer par8EntityPlayer)
  81.     {
  82.         this(par1World);
  83.         this.setPosition(par2, par4, par6);
  84.         this.ignoreFrustumCheck = true;
  85.         this.playerObj = par8EntityPlayer;
  86.         par8EntityPlayer.fishEntity = this;
  87.     }
  88.  
  89.     public EntityExampleFishHook(World par1World, EntityPlayer par2EntityPlayer)
  90.     {
  91.         super(par1World);
  92.         this.xTile = -1;
  93.         this.yTile = -1;
  94.         this.zTile = -1;
  95.         this.ignoreFrustumCheck = true;
  96.         this.playerObj = par2EntityPlayer;
  97.         this.playerObj.fishEntity = this;
  98.         this.setSize(0.25F, 0.25F);
  99.         this.setLocationAndAngles(par2EntityPlayer.posX, par2EntityPlayer.posY + 1.62D - (double)par2EntityPlayer.yOffset, par2EntityPlayer.posZ, par2EntityPlayer.rotationYaw, par2EntityPlayer.rotationPitch);
  100.         this.posX -= (double)(MathHelper.cos(this.rotationYaw / 180.0F * (float)Math.PI) * 0.16F);
  101.         this.posY -= 0.10000000149011612D;
  102.         this.posZ -= (double)(MathHelper.sin(this.rotationYaw / 180.0F * (float)Math.PI) * 0.16F);
  103.         this.setPosition(this.posX, this.posY, this.posZ);
  104.         this.yOffset = 0.0F;
  105.         float f = 0.4F;
  106.         this.motionX = (double)(-MathHelper.sin(this.rotationYaw / 180.0F * (float)Math.PI) * MathHelper.cos(this.rotationPitch / 180.0F * (float)Math.PI) * f);
  107.         this.motionZ = (double)(MathHelper.cos(this.rotationYaw / 180.0F * (float)Math.PI) * MathHelper.cos(this.rotationPitch / 180.0F * (float)Math.PI) * f);
  108.         this.motionY = (double)(-MathHelper.sin(this.rotationPitch / 180.0F * (float)Math.PI) * f);
  109.         this.setThrowableHeading(this.motionX, this.motionY, this.motionZ, 1.5F, 1.0F);
  110.     }
  111.  
  112.     protected void entityInit() {}
  113.  
  114.     public void setThrowableHeading(double x, double y, double z, float ry, float rp)
  115.     {
  116.         float f2 = MathHelper.sqrt_double(x * x + y * y + z * z);
  117.         x /= (double)f2;
  118.         y /= (double)f2;
  119.         z /= (double)f2;
  120.         x += this.rand.nextGaussian() * 0.007499999832361937D * (double)rp;
  121.         y += this.rand.nextGaussian() * 0.007499999832361937D * (double)rp;
  122.         z += this.rand.nextGaussian() * 0.007499999832361937D * (double)rp;
  123.         x *= (double)ry;
  124.         y *= (double)ry;
  125.         z *= (double)ry;
  126.         this.motionX = x;
  127.         this.motionY = y;
  128.         this.motionZ = z;
  129.         float f3 = MathHelper.sqrt_double(x * x + z * z);
  130.         this.prevRotationYaw = this.rotationYaw = (float)(Math.atan2(x, z) * 180.0D / Math.PI);
  131.         this.prevRotationPitch = this.rotationPitch = (float)(Math.atan2(y, (double)f3) * 180.0D / Math.PI);
  132.         this.groundTime = 0;
  133.     }
  134.  
  135.     /**
  136.      * Checks if the entity is in range to render by using the past in distance and comparing it to its average edge
  137.      * length * 64 * renderDistanceWeight Args: distance
  138.      */
  139.     @SideOnly(Side.CLIENT)
  140.     public boolean isInRangeToRenderDist(double par1)
  141.     {
  142.         double d1 = this.boundingBox.getAverageEdgeLength() * 4.0D;
  143.         d1 *= 64.0D;
  144.         return par1 < d1 * d1;
  145.     }
  146.  
  147.     /**
  148.      * Sets the position and rotation. Only difference from the other one is no bounding on the rotation. Args: posX,
  149.      * posY, posZ, yaw, pitch
  150.      */
  151.     @SideOnly(Side.CLIENT)
  152.     public void setPositionAndRotation2(double par1, double par3, double par5, float par7, float par8, int par9)
  153.     {
  154.         this.headedX = par1;
  155.         this.headedY = par3;
  156.         this.headedZ = par5;
  157.         this.renderYaw = (double)par7;
  158.         this.renderPitch = (double)par8;
  159.         this.thrownDirection = par9;
  160.         this.motionX = this.velocityX;
  161.         this.motionY = this.velocityY;
  162.         this.motionZ = this.velocityZ;
  163.     }
  164.  
  165.     /**
  166.      * Sets the velocity to the args. Args: x, y, z
  167.      */
  168.     @SideOnly(Side.CLIENT)
  169.     public void setVelocity(double par1, double par3, double par5)
  170.     {
  171.         this.velocityX = this.motionX = par1;
  172.         this.velocityY = this.motionY = par3;
  173.         this.velocityZ = this.motionZ = par5;
  174.     }
  175.  
  176.     /**
  177.      * Called to update the entity's position/logic.
  178.      */
  179.     @SuppressWarnings("rawtypes")
  180.     public void onUpdate()
  181.     {
  182.         super.onUpdate();
  183.  
  184.         if (this.thrownDirection > 0)
  185.         {
  186.             double d7 = this.posX + (this.headedX - this.posX) / (double)this.thrownDirection;
  187.             double d8 = this.posY + (this.headedY - this.posY) / (double)this.thrownDirection;
  188.             double d9 = this.posZ + (this.headedZ - this.posZ) / (double)this.thrownDirection;
  189.             double d1 = MathHelper.wrapAngleTo180_double(this.renderYaw - (double)this.rotationYaw);
  190.             this.rotationYaw = (float)((double)this.rotationYaw + d1 / (double)this.thrownDirection);
  191.             this.rotationPitch = (float)((double)this.rotationPitch + (this.renderPitch - (double)this.rotationPitch) / (double)this.thrownDirection);
  192.             --this.thrownDirection;
  193.             this.setPosition(d7, d8, d9);
  194.             this.setRotation(this.rotationYaw, this.rotationPitch);
  195.         }
  196.         else
  197.         {
  198.             if (!this.worldObj.isRemote)
  199.             {
  200.                 ItemStack itemstack = this.playerObj.getCurrentEquippedItem();
  201.  
  202.                 if (this.playerObj.isDead || !this.playerObj.isEntityAlive() || itemstack == null || itemstack.getItem() != Items.fishing_rod || this.getDistanceSqToEntity(this.playerObj) > 1024.0D)
  203.                 {
  204.                     this.setDead();
  205.                     this.playerObj.fishEntity = null;
  206.                     return;
  207.                 }
  208.  
  209.                 if (this.hookedEntity != null)
  210.                 {
  211.                     if (!this.hookedEntity.isDead)
  212.                     {
  213.                         this.posX = this.hookedEntity.posX;
  214.                         this.posY = this.hookedEntity.boundingBox.minY + (double)this.hookedEntity.height * 0.8D;
  215.                         this.posZ = this.hookedEntity.posZ;
  216.                         return;
  217.                     }
  218.  
  219.                     this.hookedEntity = null;
  220.                 }
  221.             }
  222.  
  223.             if (this.shakeTime > 0)
  224.             {
  225.                 --this.shakeTime;
  226.             }
  227.  
  228.             if (this.inGround)
  229.             {
  230.                 if (this.worldObj.getBlock(this.xTile, this.yTile, this.zTile) == this.tileID)
  231.                 {
  232.                     ++this.groundTime;
  233.  
  234.                     if (this.groundTime == 1200)
  235.                     {
  236.                         this.setDead();
  237.                     }
  238.  
  239.                     return;
  240.                 }
  241.  
  242.                 this.inGround = false;
  243.                 this.motionX *= (double)(this.rand.nextFloat() * 0.2F);
  244.                 this.motionY *= (double)(this.rand.nextFloat() * 0.2F);
  245.                 this.motionZ *= (double)(this.rand.nextFloat() * 0.2F);
  246.                 this.groundTime = 0;
  247.                 this.airTime = 0;
  248.             }
  249.             else
  250.             {
  251.                 ++this.airTime;
  252.             }
  253.  
  254.             Vec3 vec31 = this.worldObj.getWorldVec3Pool().getVecFromPool(this.posX, this.posY, this.posZ);
  255.             Vec3 vec3 = this.worldObj.getWorldVec3Pool().getVecFromPool(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
  256.             MovingObjectPosition movingobjectposition = this.worldObj.rayTraceBlocks(vec31, vec3);
  257.             vec31 = this.worldObj.getWorldVec3Pool().getVecFromPool(this.posX, this.posY, this.posZ);
  258.             vec3 = this.worldObj.getWorldVec3Pool().getVecFromPool(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
  259.  
  260.             if (movingobjectposition != null)
  261.             {
  262.                 vec3 = this.worldObj.getWorldVec3Pool().getVecFromPool(movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord);
  263.             }
  264.  
  265.             Entity entity = null;
  266.             List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox.addCoord(this.motionX, this.motionY, this.motionZ).expand(1.0D, 1.0D, 1.0D));
  267.             double d0 = 0.0D;
  268.             double d2;
  269.  
  270.             for (int i = 0; i < list.size(); ++i)
  271.             {
  272.                 Entity entity1 = (Entity)list.get(i);
  273.  
  274.                 if (entity1.canBeCollidedWith() && (entity1 != this.playerObj || this.airTime >= 5))
  275.                 {
  276.                     float f = 0.3F;
  277.                     AxisAlignedBB axisalignedbb = entity1.boundingBox.expand((double)f, (double)f, (double)f);
  278.                     MovingObjectPosition movingobjectposition1 = axisalignedbb.calculateIntercept(vec31, vec3);
  279.  
  280.                     if (movingobjectposition1 != null)
  281.                     {
  282.                         d2 = vec31.distanceTo(movingobjectposition1.hitVec);
  283.  
  284.                         if (d2 < d0 || d0 == 0.0D)
  285.                         {
  286.                             entity = entity1;
  287.                             d0 = d2;
  288.                         }
  289.                     }
  290.                 }
  291.             }
  292.  
  293.             if (entity != null)
  294.             {
  295.                 movingobjectposition = new MovingObjectPosition(entity);
  296.             }
  297.  
  298.             if (movingobjectposition != null)
  299.             {
  300.                 if (movingobjectposition.entityHit != null)
  301.                 {
  302.                     if (movingobjectposition.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.playerObj), 0.0F))
  303.                     {
  304.                         this.hookedEntity = movingobjectposition.entityHit;
  305.                     }
  306.                 }
  307.                 else
  308.                 {
  309.                     this.inGround = true;
  310.                 }
  311.             }
  312.  
  313.             if (!this.inGround)
  314.             {
  315.                 this.moveEntity(this.motionX, this.motionY, this.motionZ);
  316.                 float f5 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
  317.                 this.rotationYaw = (float)(Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
  318.  
  319.                 for (this.rotationPitch = (float)(Math.atan2(this.motionY, (double)f5) * 180.0D / Math.PI); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F)
  320.                 {
  321.                     ;
  322.                 }
  323.  
  324.                 while (this.rotationPitch - this.prevRotationPitch >= 180.0F)
  325.                 {
  326.                     this.prevRotationPitch += 360.0F;
  327.                 }
  328.  
  329.                 while (this.rotationYaw - this.prevRotationYaw < -180.0F)
  330.                 {
  331.                     this.prevRotationYaw -= 360.0F;
  332.                 }
  333.  
  334.                 while (this.rotationYaw - this.prevRotationYaw >= 180.0F)
  335.                 {
  336.                     this.prevRotationYaw += 360.0F;
  337.                 }
  338.  
  339.                 this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;
  340.                 this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;
  341.                 float f6 = 0.92F;
  342.  
  343.                 if (this.onGround || this.isCollidedHorizontally)
  344.                 {
  345.                     f6 = 0.5F;
  346.                 }
  347.  
  348.                 byte b0 = 5;
  349.                 double d10 = 0.0D;
  350.  
  351.                 for (int j = 0; j < b0; ++j)
  352.                 {
  353.                     double d3 = this.boundingBox.minY + (this.boundingBox.maxY - this.boundingBox.minY) * (double)(j + 0) / (double)b0 - 0.125D + 0.125D;
  354.                     double d4 = this.boundingBox.minY + (this.boundingBox.maxY - this.boundingBox.minY) * (double)(j + 1) / (double)b0 - 0.125D + 0.125D;
  355.                     AxisAlignedBB axisalignedbb1 = AxisAlignedBB.getAABBPool().getAABB(this.boundingBox.minX, d3, this.boundingBox.minZ, this.boundingBox.maxX, d4, this.boundingBox.maxZ);
  356.  
  357.                     if (this.worldObj.isAABBInMaterial(axisalignedbb1, Material.water))
  358.                     {
  359.                         d10 += 1.0D / (double)b0;
  360.                     }
  361.                 }
  362.  
  363.                 if (!this.worldObj.isRemote && d10 > 0.0D)
  364.                 {
  365.                     WorldServer worldserver = (WorldServer)this.worldObj;
  366.                     int k = 1;
  367.  
  368.                     if (this.rand.nextFloat() < 0.25F && this.worldObj.canLightningStrikeAt(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.posY) + 1, MathHelper.floor_double(this.posZ)))
  369.                     {
  370.                         k = 2;
  371.                     }
  372.  
  373.                     if (this.rand.nextFloat() < 0.5F && !this.worldObj.canBlockSeeTheSky(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.posY) + 1, MathHelper.floor_double(this.posZ)))
  374.                     {
  375.                         --k;
  376.                     }
  377.  
  378.                     if (this.hasCatchedFish > 0)
  379.                     {
  380.                         --this.hasCatchedFish;
  381.  
  382.                         if (this.hasCatchedFish <= 0)
  383.                         {
  384.                             this.fishSpeed = 0;
  385.                             this.hookedTicks = 0;
  386.                         }
  387.                     }
  388.                     else
  389.                     {
  390.                         float f1;
  391.                         float f2;
  392.                         double d5;
  393.                         double d6;
  394.                         float f7;
  395.                         double d11;
  396.  
  397.                         if (this.hookedTicks > 0)
  398.                         {
  399.                             this.hookedTicks -= k;
  400.  
  401.                             if (this.hookedTicks <= 0)
  402.                             {
  403.                                 this.motionY -= 0.20000000298023224D;
  404.                                 this.playSound("random.splash", 0.25F, 1.0F + (this.rand.nextFloat() - this.rand.nextFloat()) * 0.4F);
  405.                                 f1 = (float)MathHelper.floor_double(this.boundingBox.minY);
  406.                                 worldserver.func_147487_a("bubble", this.posX, (double)(f1 + 1.0F), this.posZ, (int)(1.0F + this.width * 20.0F), (double)this.width, 0.0D, (double)this.width, 0.20000000298023224D);
  407.                                 worldserver.func_147487_a("wake", this.posX, (double)(f1 + 1.0F), this.posZ, (int)(1.0F + this.width * 20.0F), (double)this.width, 0.0D, (double)this.width, 0.20000000298023224D);
  408.                                 this.hasCatchedFish = MathHelper.getRandomIntegerInRange(this.rand, 10, 30);
  409.                             }
  410.                             else
  411.                             {
  412.                                 this.swayTicks = (float)((double)this.swayTicks + this.rand.nextGaussian() * 4.0D);
  413.                                 f1 = this.swayTicks * 0.017453292F;
  414.                                 f7 = MathHelper.sin(f1);
  415.                                 f2 = MathHelper.cos(f1);
  416.                                 d11 = this.posX + (double)(f7 * (float)this.hookedTicks * 0.1F);
  417.                                 d5 = (double)((float)MathHelper.floor_double(this.boundingBox.minY) + 1.0F);
  418.                                 d6 = this.posZ + (double)(f2 * (float)this.hookedTicks * 0.1F);
  419.  
  420.                                 if (this.rand.nextFloat() < 0.15F)
  421.                                 {
  422.                                     worldserver.func_147487_a("bubble", d11, d5 - 0.10000000149011612D, d6, 1, (double)f7, 0.1D, (double)f2, 0.0D);
  423.                                 }
  424.  
  425.                                 float f3 = f7 * 0.04F;
  426.                                 float f4 = f2 * 0.04F;
  427.                                 worldserver.func_147487_a("wake", d11, d5, d6, 0, (double)f4, 0.01D, (double)(-f3), 1.0D);
  428.                                 worldserver.func_147487_a("wake", d11, d5, d6, 0, (double)(-f4), 0.01D, (double)f3, 1.0D);
  429.                             }
  430.                         }
  431.                         else if (this.fishSpeed > 0)
  432.                         {
  433.                             this.fishSpeed -= k;
  434.                             f1 = 0.15F;
  435.  
  436.                             if (this.fishSpeed < 20)
  437.                             {
  438.                                 f1 = (float)((double)f1 + (double)(20 - this.fishSpeed) * 0.05D);
  439.                             }
  440.                             else if (this.fishSpeed < 40)
  441.                             {
  442.                                 f1 = (float)((double)f1 + (double)(40 - this.fishSpeed) * 0.02D);
  443.                             }
  444.                             else if (this.fishSpeed < 60)
  445.                             {
  446.                                 f1 = (float)((double)f1 + (double)(60 - this.fishSpeed) * 0.01D);
  447.                             }
  448.  
  449.                             if (this.rand.nextFloat() < f1)
  450.                             {
  451.                                 f7 = MathHelper.randomFloatClamp(this.rand, 0.0F, 360.0F) * 0.017453292F;
  452.                                 f2 = MathHelper.randomFloatClamp(this.rand, 25.0F, 60.0F);
  453.                                 d11 = this.posX + (double)(MathHelper.sin(f7) * f2 * 0.1F);
  454.                                 d5 = (double)((float)MathHelper.floor_double(this.boundingBox.minY) + 1.0F);
  455.                                 d6 = this.posZ + (double)(MathHelper.cos(f7) * f2 * 0.1F);
  456.                                 worldserver.func_147487_a("splash", d11, d5, d6, 2 + this.rand.nextInt(2), 0.10000000149011612D, 0.0D, 0.10000000149011612D, 0.0D);
  457.                             }
  458.  
  459.                             if (this.fishSpeed <= 0)
  460.                             {
  461.                                 this.swayTicks = MathHelper.randomFloatClamp(this.rand, 0.0F, 360.0F);
  462.                                 this.hookedTicks = MathHelper.getRandomIntegerInRange(this.rand, 20, 80);
  463.                             }
  464.                         }
  465.                         else
  466.                         {
  467.                             this.fishSpeed = MathHelper.getRandomIntegerInRange(this.rand, 100, 900);
  468.                             this.fishSpeed -= EnchantmentHelper.func_151387_h(this.playerObj) * 20 * 5;
  469.                         }
  470.                     }
  471.  
  472.                     if (this.hasCatchedFish > 0)
  473.                     {
  474.                         this.motionY -= (double)(this.rand.nextFloat() * this.rand.nextFloat() * this.rand.nextFloat()) * 0.2D;
  475.                     }
  476.                 }
  477.  
  478.                 d2 = d10 * 2.0D - 1.0D;
  479.                 this.motionY += 0.03999999910593033D * d2;
  480.  
  481.                 if (d10 > 0.0D)
  482.                 {
  483.                     f6 = (float)((double)f6 * 0.9D);
  484.                     this.motionY *= 0.8D;
  485.                 }
  486.  
  487.                 this.motionX *= (double)f6;
  488.                 this.motionY *= (double)f6;
  489.                 this.motionZ *= (double)f6;
  490.                 this.setPosition(this.posX, this.posY, this.posZ);
  491.             }
  492.         }
  493.     }
  494.  
  495.     /**
  496.      * (abstract) Protected helper method to write subclass entity data to NBT.
  497.      */
  498.     public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound)
  499.     {
  500.         par1NBTTagCompound.setShort("xTile", (short)this.xTile);
  501.         par1NBTTagCompound.setShort("yTile", (short)this.yTile);
  502.         par1NBTTagCompound.setShort("zTile", (short)this.zTile);
  503.         par1NBTTagCompound.setByte("inTile", (byte)Block.getIdFromBlock(this.tileID));
  504.         par1NBTTagCompound.setByte("shake", (byte)this.shakeTime);
  505.         par1NBTTagCompound.setByte("inGround", (byte)(this.inGround ? 1 : 0));
  506.     }
  507.  
  508.     /**
  509.      * (abstract) Protected helper method to read subclass entity data from NBT.
  510.      */
  511.     public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound)
  512.     {
  513.         this.xTile = par1NBTTagCompound.getShort("xTile");
  514.         this.yTile = par1NBTTagCompound.getShort("yTile");
  515.         this.zTile = par1NBTTagCompound.getShort("zTile");
  516.         this.tileID = Block.getBlockById(par1NBTTagCompound.getByte("inTile") & 255);
  517.         this.shakeTime = par1NBTTagCompound.getByte("shake") & 255;
  518.         this.inGround = par1NBTTagCompound.getByte("inGround") == 1;
  519.     }
  520.  
  521.     @SideOnly(Side.CLIENT)
  522.     public float getShadowSize()
  523.     {
  524.         return 0.0F;
  525.     }
  526.  
  527.     public int throwEntityOrHookFish()
  528.     {
  529.         if (this.worldObj.isRemote)
  530.         {
  531.             return 0;
  532.         }
  533.         else
  534.         {
  535.             byte b0 = 0;
  536.  
  537.             if (this.hookedEntity != null)
  538.             {
  539.                 double d0 = this.playerObj.posX - this.posX;
  540.                 double d2 = this.playerObj.posY - this.posY;
  541.                 double d4 = this.playerObj.posZ - this.posZ;
  542.                 double d6 = (double)MathHelper.sqrt_double(d0 * d0 + d2 * d2 + d4 * d4);
  543.                 double d8 = 0.1D;
  544.                 this.hookedEntity.motionX += d0 * d8;
  545.                 this.hookedEntity.motionY += d2 * d8 + (double)MathHelper.sqrt_double(d6) * 0.08D;
  546.                 this.hookedEntity.motionZ += d4 * d8;
  547.                 b0 = 3;
  548.             }
  549.             else if (this.hasCatchedFish > 0)
  550.             {
  551.                 EntityItem entityitem = new EntityItem(this.worldObj, this.posX, this.posY, this.posZ, this.getFishOrTreasure());
  552.                 double d1 = this.playerObj.posX - this.posX;
  553.                 double d3 = this.playerObj.posY - this.posY;
  554.                 double d5 = this.playerObj.posZ - this.posZ;
  555.                 double d7 = (double)MathHelper.sqrt_double(d1 * d1 + d3 * d3 + d5 * d5);
  556.                 double d9 = 0.1D;
  557.                 entityitem.motionX = d1 * d9;
  558.                 entityitem.motionY = d3 * d9 + (double)MathHelper.sqrt_double(d7) * 0.08D;
  559.                 entityitem.motionZ = d5 * d9;
  560.                 this.worldObj.spawnEntityInWorld(entityitem);
  561.                 this.playerObj.worldObj.spawnEntityInWorld(new EntityXPOrb(this.playerObj.worldObj, this.playerObj.posX, this.playerObj.posY + 0.5D, this.playerObj.posZ + 0.5D, this.rand.nextInt(6) + 1));
  562.                 b0 = 1;
  563.             }
  564.  
  565.             if (this.inGround)
  566.             {
  567.                 b0 = 2;
  568.             }
  569.  
  570.             this.setDead();
  571.             this.playerObj.fishEntity = null;
  572.             return b0;
  573.         }
  574.     }
  575.  
  576.     private ItemStack getFishOrTreasure()
  577.     {
  578.         float f = this.worldObj.rand.nextFloat();
  579.         int i = EnchantmentHelper.func_151386_g(this.playerObj);
  580.         int j = EnchantmentHelper.func_151387_h(this.playerObj);
  581.         float f1 = 0.1F - (float)i * 0.025F - (float)j * 0.01F;
  582.         float f2 = 0.05F + (float)i * 0.01F - (float)j * 0.01F;
  583.         f1 = MathHelper.clamp_float(f1, 0.0F, 1.0F);
  584.         f2 = MathHelper.clamp_float(f2, 0.0F, 1.0F);
  585.  
  586.         if (f < f1)
  587.         {
  588.             this.playerObj.addStat(StatList.field_151183_A, 1);
  589.             return ((WeightedRandomFishable)WeightedRandom.getRandomItem(this.rand, trashCatches)).func_150708_a(this.rand);
  590.         }
  591.         else
  592.         {
  593.             f -= f1;
  594.  
  595.             if (f < f2)
  596.             {
  597.                 this.playerObj.addStat(StatList.field_151184_B, 1);
  598.                 return ((WeightedRandomFishable)WeightedRandom.getRandomItem(this.rand, treasureCatches)).func_150708_a(this.rand);
  599.             }
  600.             else
  601.             {
  602.                 float f3 = f - f2;
  603.                 this.playerObj.addStat(StatList.fishCaughtStat, 1);
  604.                 return ((WeightedRandomFishable)WeightedRandom.getRandomItem(this.rand, fishCatches)).func_150708_a(this.rand);
  605.             }
  606.         }
  607.     }
  608.  
  609.     /**
  610.      * Will get destroyed next tick.
  611.      */
  612.     public void setDead()
  613.     {
  614.         super.setDead();
  615.  
  616.         if (this.playerObj != null)
  617.         {
  618.             this.playerObj.fishEntity = null;
  619.         }
  620.     }
  621. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement