Zapfox

Untitled

Dec 4th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.49 KB | None | 0 0
  1. package orescape.mod.entity;
  2.  
  3.  
  4. import java.util.List;
  5.  
  6. import javax.annotation.Nullable;
  7.  
  8. import com.google.common.base.Predicate;
  9. import com.google.common.base.Predicates;
  10.  
  11. import net.minecraft.block.Block;
  12. import net.minecraft.block.material.Material;
  13. import net.minecraft.block.state.IBlockState;
  14. import net.minecraft.enchantment.EnchantmentHelper;
  15. import net.minecraft.entity.Entity;
  16. import net.minecraft.entity.EntityLivingBase;
  17. import net.minecraft.entity.IProjectile;
  18. import net.minecraft.entity.MoverType;
  19. import net.minecraft.entity.monster.EntityEnderman;
  20. import net.minecraft.entity.player.EntityPlayer;
  21. import net.minecraft.entity.player.EntityPlayerMP;
  22. import net.minecraft.entity.projectile.EntityArrow;
  23. import net.minecraft.init.Enchantments;
  24. import net.minecraft.init.SoundEvents;
  25. import net.minecraft.item.ItemStack;
  26. import net.minecraft.nbt.NBTTagCompound;
  27. import net.minecraft.network.datasync.DataParameter;
  28. import net.minecraft.network.datasync.DataSerializers;
  29. import net.minecraft.network.datasync.EntityDataManager;
  30. import net.minecraft.network.play.server.SPacketChangeGameState;
  31. import net.minecraft.util.DamageSource;
  32. import net.minecraft.util.EntitySelectors;
  33. import net.minecraft.util.EnumParticleTypes;
  34. import net.minecraft.util.ResourceLocation;
  35. import net.minecraft.util.datafix.DataFixer;
  36. import net.minecraft.util.math.AxisAlignedBB;
  37. import net.minecraft.util.math.BlockPos;
  38. import net.minecraft.util.math.MathHelper;
  39. import net.minecraft.util.math.RayTraceResult;
  40. import net.minecraft.util.math.Vec3d;
  41. import net.minecraft.world.World;
  42. import net.minecraftforge.fml.relauncher.Side;
  43. import net.minecraftforge.fml.relauncher.SideOnly;
  44.  
  45. public abstract class BronzeArrow extends EntityArrow implements IProjectile
  46. {
  47. private static final Predicate<Entity> ARROW_TARGETS = Predicates.and(EntitySelectors.NOT_SPECTATING, EntitySelectors.IS_ALIVE, new Predicate<Entity>()
  48. {
  49. public boolean apply(@Nullable Entity p_apply_1_)
  50. {
  51. return p_apply_1_.canBeCollidedWith();
  52. }
  53. });
  54. private static final DataParameter<Byte> CRITICAL = EntityDataManager.<Byte>createKey(BronzeArrow.class, DataSerializers.BYTE);
  55. private int xTile;
  56. private int yTile;
  57. private int zTile;
  58. private Block inTile;
  59. private int inData;
  60. protected boolean inGround;
  61. protected int timeInGround;
  62. /** 1 if the player can pick up the arrow */
  63. public BronzeArrow.PickupStatus pickupStatus;
  64. /** Seems to be some sort of timer for animating an arrow. */
  65. public int arrowShake;
  66. /** The owner of this arrow. */
  67. public Entity shootingEntity;
  68. private int ticksInGround;
  69. private int ticksInAir;
  70. private double damage;
  71. /** The amount of knockback an arrow applies when it hits a mob. */
  72. private int knockbackStrength;
  73.  
  74. public BronzeArrow(World worldIn)
  75. {
  76. super(worldIn);
  77. this.xTile = -1;
  78. this.yTile = -1;
  79. this.zTile = -1;
  80. this.pickupStatus = BronzeArrow.PickupStatus.DISALLOWED;
  81. this.damage = 0.5D;
  82. this.setSize(0.5F, 0.5F);
  83. }
  84.  
  85. public BronzeArrow(World worldIn, double x, double y, double z)
  86. {
  87. this(worldIn);
  88. this.setPosition(x, y, z);
  89. }
  90.  
  91. public BronzeArrow(World worldIn, EntityLivingBase shooter)
  92. {
  93. this(worldIn, shooter.posX, shooter.posY + (double)shooter.getEyeHeight() - 0.10000000149011612D, shooter.posZ);
  94. this.shootingEntity = shooter;
  95.  
  96. if (shooter instanceof EntityPlayer)
  97. {
  98. this.pickupStatus = BronzeArrow.PickupStatus.DISALLOWED;
  99. }
  100. }
  101.  
  102. /**
  103. * Checks if the entity is in range to render.
  104. */
  105. @SideOnly(Side.CLIENT)
  106. public boolean isInRangeToRenderDist(double distance)
  107. {
  108. double d0 = this.getEntityBoundingBox().getAverageEdgeLength() * 10.0D;
  109.  
  110. if (Double.isNaN(d0))
  111. {
  112. d0 = 1.0D;
  113. }
  114.  
  115. d0 = d0 * 64.0D * getRenderDistanceWeight();
  116. return distance < d0 * d0;
  117. }
  118.  
  119. protected void entityInit()
  120. {
  121. this.dataManager.register(CRITICAL, Byte.valueOf((byte)0));
  122. }
  123.  
  124. public void shoot(Entity shooter, float pitch, float yaw, float p_184547_4_, float velocity, float inaccuracy)
  125. {
  126. float f = -MathHelper.sin(yaw * 0.017453292F) * MathHelper.cos(pitch * 0.017453292F);
  127. float f1 = -MathHelper.sin(pitch * 0.017453292F);
  128. float f2 = MathHelper.cos(yaw * 0.017453292F) * MathHelper.cos(pitch * 0.017453292F);
  129. this.shoot((double)f, (double)f1, (double)f2, velocity, inaccuracy);
  130. this.motionX += shooter.motionX;
  131. this.motionZ += shooter.motionZ;
  132.  
  133. if (!shooter.onGround)
  134. {
  135. this.motionY += shooter.motionY;
  136. }
  137. }
  138.  
  139. /**
  140. * Similar to setArrowHeading, it's point the throwable entity to a x, y, z direction.
  141. */
  142. public void shoot(double x, double y, double z, float velocity, float inaccuracy)
  143. {
  144. float f = MathHelper.sqrt(x * x + y * y + z * z);
  145. x = x / (double)f;
  146. y = y / (double)f;
  147. z = z / (double)f;
  148. x = x + this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy;
  149. y = y + this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy;
  150. z = z + this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy;
  151. x = x * (double)velocity;
  152. y = y * (double)velocity;
  153. z = z * (double)velocity;
  154. this.motionX = x;
  155. this.motionY = y;
  156. this.motionZ = z;
  157. float f1 = MathHelper.sqrt(x * x + z * z);
  158. this.rotationYaw = (float)(MathHelper.atan2(x, z) * (180D / Math.PI));
  159. this.rotationPitch = (float)(MathHelper.atan2(y, (double)f1) * (180D / Math.PI));
  160. this.prevRotationYaw = this.rotationYaw;
  161. this.prevRotationPitch = this.rotationPitch;
  162. this.ticksInGround = 0;
  163. }
  164.  
  165. /**
  166. * Set the position and rotation values directly without any clamping.
  167. */
  168. @SideOnly(Side.CLIENT)
  169. public void setPositionAndRotationDirect(double x, double y, double z, float yaw, float pitch, int posRotationIncrements, boolean teleport)
  170. {
  171. this.setPosition(x, y, z);
  172. this.setRotation(yaw, pitch);
  173. }
  174.  
  175. /**
  176. * Updates the entity motion clientside, called by packets from the server
  177. */
  178. @SideOnly(Side.CLIENT)
  179. public void setVelocity(double x, double y, double z)
  180. {
  181. this.motionX = x;
  182. this.motionY = y;
  183. this.motionZ = z;
  184.  
  185. if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F)
  186. {
  187. float f = MathHelper.sqrt(x * x + z * z);
  188. this.rotationPitch = (float)(MathHelper.atan2(y, (double)f) * (180D / Math.PI));
  189. this.rotationYaw = (float)(MathHelper.atan2(x, z) * (180D / Math.PI));
  190. this.prevRotationPitch = this.rotationPitch;
  191. this.prevRotationYaw = this.rotationYaw;
  192. this.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch);
  193. this.ticksInGround = 0;
  194. }
  195. }
  196.  
  197. /**
  198. * Called to update the entity's position/logic.
  199. */
  200. public void onUpdate()
  201. {
  202. super.onUpdate();
  203.  
  204. if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F)
  205. {
  206. float f = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
  207. this.rotationYaw = (float)(MathHelper.atan2(this.motionX, this.motionZ) * (180D / Math.PI));
  208. this.rotationPitch = (float)(MathHelper.atan2(this.motionY, (double)f) * (180D / Math.PI));
  209. this.prevRotationYaw = this.rotationYaw;
  210. this.prevRotationPitch = this.rotationPitch;
  211. }
  212.  
  213. BlockPos blockpos = new BlockPos(this.xTile, this.yTile, this.zTile);
  214. IBlockState iblockstate = this.world.getBlockState(blockpos);
  215. Block block = iblockstate.getBlock();
  216.  
  217. if (iblockstate.getMaterial() != Material.AIR)
  218. {
  219. AxisAlignedBB axisalignedbb = iblockstate.getCollisionBoundingBox(this.world, blockpos);
  220.  
  221. if (axisalignedbb != Block.NULL_AABB && axisalignedbb.offset(blockpos).contains(new Vec3d(this.posX, this.posY, this.posZ)))
  222. {
  223. this.inGround = true;
  224. }
  225. }
  226.  
  227. if (this.arrowShake > 0)
  228. {
  229. --this.arrowShake;
  230. }
  231.  
  232. if (this.inGround)
  233. {
  234. int j = block.getMetaFromState(iblockstate);
  235.  
  236. if ((block != this.inTile || j != this.inData) && !this.world.collidesWithAnyBlock(this.getEntityBoundingBox().grow(0.05D)))
  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.ticksInGround;
  248.  
  249. if (this.ticksInGround >= 20)
  250. {
  251. this.setDead();
  252. }
  253. }
  254.  
  255. ++this.timeInGround;
  256. }
  257. else
  258. {
  259. this.timeInGround = 0;
  260. ++this.ticksInAir;
  261. Vec3d vec3d1 = new Vec3d(this.posX, this.posY, this.posZ);
  262. Vec3d vec3d = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
  263. RayTraceResult raytraceresult = this.world.rayTraceBlocks(vec3d1, vec3d, false, true, false);
  264. vec3d1 = new Vec3d(this.posX, this.posY, this.posZ);
  265. vec3d = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
  266.  
  267. if (raytraceresult != null)
  268. {
  269. vec3d = new Vec3d(raytraceresult.hitVec.x, raytraceresult.hitVec.y, raytraceresult.hitVec.z);
  270. }
  271.  
  272. Entity entity = this.findEntityOnPath(vec3d1, vec3d);
  273.  
  274. if (entity != null)
  275. {
  276. raytraceresult = new RayTraceResult(entity);
  277. }
  278.  
  279. if (raytraceresult != null && raytraceresult.entityHit instanceof EntityPlayer)
  280. {
  281. EntityPlayer entityplayer = (EntityPlayer)raytraceresult.entityHit;
  282.  
  283. if (this.shootingEntity instanceof EntityPlayer && !((EntityPlayer)this.shootingEntity).canAttackPlayer(entityplayer))
  284. {
  285. raytraceresult = null;
  286. }
  287. }
  288.  
  289. if (raytraceresult != null && !net.minecraftforge.event.ForgeEventFactory.onProjectileImpact(this, raytraceresult))
  290. {
  291. this.onHit(raytraceresult);
  292. }
  293.  
  294. if (this.getIsCritical())
  295. {
  296. for (int k = 0; k < 4; ++k)
  297. {
  298. this.world.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);
  299. }
  300. }
  301.  
  302. this.posX += this.motionX;
  303. this.posY += this.motionY;
  304. this.posZ += this.motionZ;
  305. float f4 = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
  306. this.rotationYaw = (float)(MathHelper.atan2(this.motionX, this.motionZ) * (180D / Math.PI));
  307.  
  308. for (this.rotationPitch = (float)(MathHelper.atan2(this.motionY, (double)f4) * (180D / Math.PI)); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F)
  309. {
  310. ;
  311. }
  312.  
  313. while (this.rotationPitch - this.prevRotationPitch >= 180.0F)
  314. {
  315. this.prevRotationPitch += 360.0F;
  316. }
  317.  
  318. while (this.rotationYaw - this.prevRotationYaw < -180.0F)
  319. {
  320. this.prevRotationYaw -= 360.0F;
  321. }
  322.  
  323. while (this.rotationYaw - this.prevRotationYaw >= 180.0F)
  324. {
  325. this.prevRotationYaw += 360.0F;
  326. }
  327.  
  328. this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;
  329. this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;
  330. float f1 = 0.99F;
  331. float f2 = 0.05F;
  332.  
  333. if (this.isInWater())
  334. {
  335. for (int i = 0; i < 4; ++i)
  336. {
  337. float f3 = 0.25F;
  338. this.world.spawnParticle(EnumParticleTypes.WATER_BUBBLE, this.posX - this.motionX * 0.25D, this.posY - this.motionY * 0.25D, this.posZ - this.motionZ * 0.25D, this.motionX, this.motionY, this.motionZ);
  339. }
  340.  
  341. f1 = 0.6F;
  342. }
  343.  
  344. if (this.isWet())
  345. {
  346. this.extinguish();
  347. }
  348.  
  349. this.motionX *= (double)f1;
  350. this.motionY *= (double)f1;
  351. this.motionZ *= (double)f1;
  352.  
  353. if (!this.hasNoGravity())
  354. {
  355. this.motionY -= 0.05000000074505806D;
  356. }
  357.  
  358. this.setPosition(this.posX, this.posY, this.posZ);
  359. this.doBlockCollisions();
  360. }
  361. }
  362.  
  363. /**
  364. * Called when the arrow hits a block or an entity
  365. */
  366. protected void onHit(RayTraceResult raytraceResultIn)
  367. {
  368. Entity entity = raytraceResultIn.entityHit;
  369.  
  370. if (entity != null)
  371. {
  372. float f = MathHelper.sqrt(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
  373. int i = MathHelper.ceil((double)f * this.damage);
  374.  
  375. if (this.getIsCritical())
  376. {
  377. i += this.rand.nextInt(i / 2 + 2);
  378. }
  379.  
  380. DamageSource damagesource;
  381.  
  382. if (this.shootingEntity == null)
  383. {
  384. damagesource = DamageSource.causeArrowDamage(this, this);
  385. }
  386. else
  387. {
  388. damagesource = DamageSource.causeArrowDamage(this, this.shootingEntity);
  389. }
  390.  
  391. if (this.isBurning() && !(entity instanceof EntityEnderman))
  392. {
  393. entity.setFire(5);
  394. }
  395.  
  396. if (entity.attackEntityFrom(damagesource, (float)i))
  397. {
  398. if (entity instanceof EntityLivingBase)
  399. {
  400. EntityLivingBase entitylivingbase = (EntityLivingBase)entity;
  401.  
  402. if (!this.world.isRemote)
  403. {
  404. entitylivingbase.setArrowCountInEntity(entitylivingbase.getArrowCountInEntity() + 1);
  405. }
  406.  
  407. if (this.knockbackStrength > 0)
  408. {
  409. float f1 = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
  410.  
  411. if (f1 > 0.0F)
  412. {
  413. entitylivingbase.addVelocity(this.motionX * (double)this.knockbackStrength * 0.6000000238418579D / (double)f1, 0.1D, this.motionZ * (double)this.knockbackStrength * 0.6000000238418579D / (double)f1);
  414. }
  415. }
  416.  
  417. if (this.shootingEntity instanceof EntityLivingBase)
  418. {
  419. EnchantmentHelper.applyThornEnchantments(entitylivingbase, this.shootingEntity);
  420. EnchantmentHelper.applyArthropodEnchantments((EntityLivingBase)this.shootingEntity, entitylivingbase);
  421. }
  422.  
  423. this.arrowHit(entitylivingbase);
  424.  
  425. if (this.shootingEntity != null && entitylivingbase != this.shootingEntity && entitylivingbase instanceof EntityPlayer && this.shootingEntity instanceof EntityPlayerMP)
  426. {
  427. ((EntityPlayerMP)this.shootingEntity).connection.sendPacket(new SPacketChangeGameState(6, 0.0F));
  428. }
  429. }
  430.  
  431. this.playSound(SoundEvents.ENTITY_ARROW_HIT, 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F));
  432.  
  433. if (!(entity instanceof EntityEnderman))
  434. {
  435. this.setDead();
  436. }
  437. }
  438. else
  439. {
  440. this.motionX *= -0.10000000149011612D;
  441. this.motionY *= -0.10000000149011612D;
  442. this.motionZ *= -0.10000000149011612D;
  443. this.rotationYaw += 180.0F;
  444. this.prevRotationYaw += 180.0F;
  445. this.ticksInAir = 0;
  446.  
  447. if (!this.world.isRemote && this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ < 0.0010000000474974513D)
  448. {
  449.  
  450. this.setDead();
  451. }
  452. }
  453. }
  454. else
  455. {
  456. BlockPos blockpos = raytraceResultIn.getBlockPos();
  457. this.xTile = blockpos.getX();
  458. this.yTile = blockpos.getY();
  459. this.zTile = blockpos.getZ();
  460. IBlockState iblockstate = this.world.getBlockState(blockpos);
  461. this.inTile = iblockstate.getBlock();
  462. this.inData = this.inTile.getMetaFromState(iblockstate);
  463. this.motionX = (double)((float)(raytraceResultIn.hitVec.x - this.posX));
  464. this.motionY = (double)((float)(raytraceResultIn.hitVec.y - this.posY));
  465. this.motionZ = (double)((float)(raytraceResultIn.hitVec.z - this.posZ));
  466. float f2 = MathHelper.sqrt(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
  467. this.posX -= this.motionX / (double)f2 * 0.05000000074505806D;
  468. this.posY -= this.motionY / (double)f2 * 0.05000000074505806D;
  469. this.posZ -= this.motionZ / (double)f2 * 0.05000000074505806D;
  470. this.playSound(SoundEvents.ENTITY_ARROW_HIT, 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F));
  471. this.inGround = true;
  472. this.arrowShake = 7;
  473. this.setIsCritical(false);
  474.  
  475. if (iblockstate.getMaterial() != Material.AIR)
  476. {
  477. this.inTile.onEntityCollidedWithBlock(this.world, blockpos, iblockstate, this);
  478. }
  479. }
  480. }
  481.  
  482. /**
  483. * Tries to move the entity towards the specified location.
  484. */
  485. public void move(MoverType type, double x, double y, double z)
  486. {
  487. super.move(type, x, y, z);
  488.  
  489. if (this.inGround)
  490. {
  491. this.xTile = MathHelper.floor(this.posX);
  492. this.yTile = MathHelper.floor(this.posY);
  493. this.zTile = MathHelper.floor(this.posZ);
  494. }
  495. }
  496.  
  497. protected void arrowHit(EntityLivingBase living)
  498. {
  499. }
  500.  
  501. @Nullable
  502. protected Entity findEntityOnPath(Vec3d start, Vec3d end)
  503. {
  504. Entity entity = null;
  505. List<Entity> list = this.world.getEntitiesInAABBexcluding(this, this.getEntityBoundingBox().expand(this.motionX, this.motionY, this.motionZ).grow(1.0D), ARROW_TARGETS);
  506. double d0 = 0.0D;
  507.  
  508. for (int i = 0; i < list.size(); ++i)
  509. {
  510. Entity entity1 = list.get(i);
  511.  
  512. if (entity1 != this.shootingEntity || this.ticksInAir >= 5)
  513. {
  514. AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().grow(0.30000001192092896D);
  515. RayTraceResult raytraceresult = axisalignedbb.calculateIntercept(start, end);
  516.  
  517. if (raytraceresult != null)
  518. {
  519. double d1 = start.squareDistanceTo(raytraceresult.hitVec);
  520.  
  521. if (d1 < d0 || d0 == 0.0D)
  522. {
  523. entity = entity1;
  524. d0 = d1;
  525. }
  526. }
  527. }
  528. }
  529.  
  530. return entity;
  531. }
  532.  
  533. public static void registerFixesArrow(DataFixer fixer, String name)
  534. {
  535. }
  536.  
  537. public static void registerFixesArrow(DataFixer fixer)
  538. {
  539. registerFixesArrow(fixer, "Arrow");
  540. }
  541.  
  542. /**
  543. * (abstract) Protected helper method to write subclass entity data to NBT.
  544. */
  545. public void writeEntityToNBT(NBTTagCompound compound)
  546. {
  547. compound.setInteger("xTile", this.xTile);
  548. compound.setInteger("yTile", this.yTile);
  549. compound.setInteger("zTile", this.zTile);
  550. compound.setShort("life", (short)this.ticksInGround);
  551. ResourceLocation resourcelocation = Block.REGISTRY.getNameForObject(this.inTile);
  552. compound.setString("inTile", resourcelocation == null ? "" : resourcelocation.toString());
  553. compound.setByte("inData", (byte)this.inData);
  554. compound.setByte("shake", (byte)this.arrowShake);
  555. compound.setByte("inGround", (byte)(this.inGround ? 1 : 0));
  556. compound.setByte("pickup", (byte)this.pickupStatus.ordinal());
  557. compound.setDouble("damage", this.damage);
  558. compound.setBoolean("crit", this.getIsCritical());
  559. }
  560.  
  561. /**
  562. * (abstract) Protected helper method to read subclass entity data from NBT.
  563. */
  564. public void readEntityFromNBT(NBTTagCompound compound)
  565. {
  566. this.xTile = compound.getInteger("xTile");
  567. this.yTile = compound.getInteger("yTile");
  568. this.zTile = compound.getInteger("zTile");
  569. this.ticksInGround = compound.getShort("life");
  570.  
  571. if (compound.hasKey("inTile", 8))
  572. {
  573. this.inTile = Block.getBlockFromName(compound.getString("inTile"));
  574. }
  575. else
  576. {
  577. this.inTile = Block.getBlockById(compound.getByte("inTile") & 255);
  578. }
  579.  
  580. this.inData = compound.getByte("inData") & 255;
  581. this.arrowShake = compound.getByte("shake") & 255;
  582. this.inGround = compound.getByte("inGround") == 1;
  583.  
  584. if (compound.hasKey("damage", 99))
  585. {
  586. this.damage = compound.getDouble("damage");
  587. }
  588.  
  589. if (compound.hasKey("pickup", 99))
  590. {
  591. this.pickupStatus = BronzeArrow.PickupStatus.getByOrdinal(compound.getByte("pickup"));
  592. }
  593. else if (compound.hasKey("player", 99))
  594. {
  595. this.pickupStatus = compound.getBoolean("player") ? BronzeArrow.PickupStatus.ALLOWED : BronzeArrow.PickupStatus.DISALLOWED;
  596. }
  597.  
  598. this.setIsCritical(compound.getBoolean("crit"));
  599. }
  600.  
  601. /**
  602. * Called by a player entity when they collide with an entity
  603. */
  604. public void onCollideWithPlayer(EntityPlayer entityIn)
  605. {
  606.  
  607. {
  608. this.setDead();
  609. }
  610. }
  611.  
  612.  
  613. protected abstract ItemStack getArrowStack();
  614.  
  615. /**
  616. * returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to
  617. * prevent them from trampling crops
  618. */
  619. protected boolean canTriggerWalking()
  620. {
  621. return false;
  622. }
  623.  
  624. public void setDamage(double damageIn)
  625. {
  626. this.damage = damageIn;
  627. }
  628.  
  629. public double getDamage()
  630. {
  631. return this.damage;
  632. }
  633.  
  634. /**
  635. * Sets the amount of knockback the arrow applies when it hits a mob.
  636. */
  637. public void setKnockbackStrength(int knockbackStrengthIn)
  638. {
  639. this.knockbackStrength = knockbackStrengthIn;
  640. }
  641.  
  642. /**
  643. * Returns true if it's possible to attack this entity with an item.
  644. */
  645. public boolean canBeAttackedWithItem()
  646. {
  647. return false;
  648. }
  649.  
  650. public float getEyeHeight()
  651. {
  652. return 0.0F;
  653. }
  654.  
  655. /**
  656. * Whether the arrow has a stream of critical hit particles flying behind it.
  657. */
  658. public void setIsCritical(boolean critical)
  659. {
  660. byte b0 = ((Byte)this.dataManager.get(CRITICAL)).byteValue();
  661.  
  662. if (critical)
  663. {
  664. this.dataManager.set(CRITICAL, Byte.valueOf((byte)(b0 | 1)));
  665. }
  666. else
  667. {
  668. this.dataManager.set(CRITICAL, Byte.valueOf((byte)(b0 & -2)));
  669. }
  670. }
  671.  
  672. /**
  673. * Whether the arrow has a stream of critical hit particles flying behind it.
  674. */
  675. public boolean getIsCritical()
  676. {
  677. byte b0 = ((Byte)this.dataManager.get(CRITICAL)).byteValue();
  678. return (b0 & 1) != 0;
  679. }
  680.  
  681. public void setEnchantmentEffectsFromEntity(EntityLivingBase p_190547_1_, float p_190547_2_)
  682. {
  683. int i = EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.POWER, p_190547_1_);
  684. int j = EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.PUNCH, p_190547_1_);
  685. this.setDamage((double)(p_190547_2_ * 2.0F) + this.rand.nextGaussian() * 0.25D + (double)((float)this.world.getDifficulty().getDifficultyId() * 0.11F));
  686.  
  687. if (i > 0)
  688. {
  689. this.setDamage(this.getDamage() + (double)i * 0.5D + 0.5D);
  690. }
  691.  
  692. if (j > 0)
  693. {
  694. this.setKnockbackStrength(j);
  695. }
  696.  
  697. if (EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.FLAME, p_190547_1_) > 0)
  698. {
  699. this.setFire(100);
  700. }
  701. }
  702.  
  703. public static enum PickupStatus
  704. {
  705. ALLOWED,
  706. DISALLOWED;
  707.  
  708.  
  709.  
  710. public static BronzeArrow.PickupStatus getByOrdinal(int ordinal)
  711. {
  712. if (ordinal < 0 || ordinal > values().length)
  713. {
  714. ordinal = 0;
  715. }
  716.  
  717. return values()[ordinal];
  718. }
  719. }
  720. }
Add Comment
Please, Sign In to add comment