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