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