Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.09 KB | None | 0 0
  1. package net.minecraft.entity.item;
  2.  
  3. import cpw.mods.fml.relauncher.Side;
  4. import cpw.mods.fml.relauncher.SideOnly;
  5. import java.util.List;
  6. import net.minecraft.block.Block;
  7. import net.minecraft.block.material.Material;
  8. import net.minecraft.entity.Entity;
  9. import net.minecraft.entity.EntityLivingBase;
  10. import net.minecraft.entity.player.EntityPlayer;
  11. import net.minecraft.init.Blocks;
  12. import net.minecraft.init.Items;
  13. import net.minecraft.item.Item;
  14. import net.minecraft.nbt.NBTTagCompound;
  15. import net.minecraft.util.AxisAlignedBB;
  16. import net.minecraft.util.DamageSource;
  17. import net.minecraft.util.MathHelper;
  18. import net.minecraft.world.World;
  19.  
  20. public class EntityBoat extends Entity
  21. {
  22. /** true if no player in boat */
  23. private boolean isBoatEmpty;
  24. private double speedMultiplier;
  25. private int boatPosRotationIncrements;
  26. private double boatX;
  27. private double boatY;
  28. private double boatZ;
  29. private double boatYaw;
  30. private double boatPitch;
  31. @SideOnly(Side.CLIENT)
  32. private double velocityX;
  33. @SideOnly(Side.CLIENT)
  34. private double velocityY;
  35. @SideOnly(Side.CLIENT)
  36. private double velocityZ;
  37. private static final String __OBFID = "CL_00001667";
  38.  
  39. public EntityBoat(World p_i1704_1_)
  40. {
  41. super(p_i1704_1_);
  42. this.isBoatEmpty = true;
  43. this.speedMultiplier = 0.07D;
  44. this.preventEntitySpawning = true;
  45. this.setSize(1.5F, 0.6F);
  46. this.yOffset = this.height / 2.0F;
  47. }
  48.  
  49. /**
  50. * returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to
  51. * prevent them from trampling crops
  52. */
  53. protected boolean canTriggerWalking()
  54. {
  55. return false;
  56. }
  57.  
  58. protected void entityInit()
  59. {
  60. this.dataWatcher.addObject(17, new Integer(0));
  61. this.dataWatcher.addObject(18, new Integer(1));
  62. this.dataWatcher.addObject(19, new Float(0.0F));
  63. }
  64.  
  65. /**
  66. * Returns a boundingBox used to collide the entity with other entities and blocks. This enables the entity to be
  67. * pushable on contact, like boats or minecarts.
  68. */
  69. public AxisAlignedBB getCollisionBox(Entity p_70114_1_)
  70. {
  71. return p_70114_1_.boundingBox;
  72. }
  73.  
  74. /**
  75. * returns the bounding box for this entity
  76. */
  77. public AxisAlignedBB getBoundingBox()
  78. {
  79. return this.boundingBox;
  80. }
  81.  
  82. /**
  83. * Returns true if this entity should push and be pushed by other entities when colliding.
  84. */
  85. public boolean canBePushed()
  86. {
  87. return true;
  88. }
  89.  
  90. public EntityBoat(World p_i1705_1_, double p_i1705_2_, double p_i1705_4_, double p_i1705_6_)
  91. {
  92. this(p_i1705_1_);
  93. this.setPosition(p_i1705_2_, p_i1705_4_ + (double)this.yOffset, p_i1705_6_);
  94. this.motionX = 0.0D;
  95. this.motionY = 0.0D;
  96. this.motionZ = 0.0D;
  97. this.prevPosX = p_i1705_2_;
  98. this.prevPosY = p_i1705_4_;
  99. this.prevPosZ = p_i1705_6_;
  100. }
  101.  
  102. /**
  103. * Returns the Y offset from the entity's position for any entity riding this one.
  104. */
  105. public double getMountedYOffset()
  106. {
  107. return (double)this.height * 0.0D - 0.30000001192092896D;
  108. }
  109.  
  110. /**
  111. * Called when the entity is attacked.
  112. */
  113. public boolean attackEntityFrom(DamageSource p_70097_1_, float p_70097_2_)
  114. {
  115. if (this.isEntityInvulnerable())
  116. {
  117. return false;
  118. }
  119. else if (!this.worldObj.isRemote && !this.isDead)
  120. {
  121. this.setForwardDirection(-this.getForwardDirection());
  122. this.setTimeSinceHit(10);
  123. this.setDamageTaken(this.getDamageTaken() + p_70097_2_ * 10.0F);
  124. this.setBeenAttacked();
  125. boolean flag = p_70097_1_.getEntity() instanceof EntityPlayer && ((EntityPlayer)p_70097_1_.getEntity()).capabilities.isCreativeMode;
  126.  
  127. if (flag || this.getDamageTaken() > 40.0F)
  128. {
  129. if (this.riddenByEntity != null)
  130. {
  131. this.riddenByEntity.mountEntity(this);
  132. }
  133.  
  134. if (!flag)
  135. {
  136. this.func_145778_a(Items.boat, 1, 0.0F);
  137. }
  138.  
  139. this.setDead();
  140. }
  141.  
  142. return true;
  143. }
  144. else
  145. {
  146. return true;
  147. }
  148. }
  149.  
  150. /**
  151. * Setups the entity to do the hurt animation. Only used by packets in multiplayer.
  152. */
  153. @SideOnly(Side.CLIENT)
  154. public void performHurtAnimation()
  155. {
  156. this.setForwardDirection(-this.getForwardDirection());
  157. this.setTimeSinceHit(10);
  158. this.setDamageTaken(this.getDamageTaken() * 11.0F);
  159. }
  160.  
  161. /**
  162. * Returns true if other Entities should be prevented from moving through this Entity.
  163. */
  164. public boolean canBeCollidedWith()
  165. {
  166. return !this.isDead;
  167. }
  168.  
  169. /**
  170. * Sets the position and rotation. Only difference from the other one is no bounding on the rotation. Args: posX,
  171. * posY, posZ, yaw, pitch
  172. */
  173. @SideOnly(Side.CLIENT)
  174. public void setPositionAndRotation2(double p_70056_1_, double p_70056_3_, double p_70056_5_, float p_70056_7_, float p_70056_8_, int p_70056_9_)
  175. {
  176. if (this.isBoatEmpty)
  177. {
  178. this.boatPosRotationIncrements = p_70056_9_ + 5;
  179. }
  180. else
  181. {
  182. double d3 = p_70056_1_ - this.posX;
  183. double d4 = p_70056_3_ - this.posY;
  184. double d5 = p_70056_5_ - this.posZ;
  185. double d6 = d3 * d3 + d4 * d4 + d5 * d5;
  186.  
  187. if (d6 <= 1.0D)
  188. {
  189. return;
  190. }
  191.  
  192. this.boatPosRotationIncrements = 3;
  193. }
  194.  
  195. this.boatX = p_70056_1_;
  196. this.boatY = p_70056_3_;
  197. this.boatZ = p_70056_5_;
  198. this.boatYaw = (double)p_70056_7_;
  199. this.boatPitch = (double)p_70056_8_;
  200. this.motionX = this.velocityX;
  201. this.motionY = this.velocityY;
  202. this.motionZ = this.velocityZ;
  203. }
  204.  
  205. /**
  206. * Sets the velocity to the args. Args: x, y, z
  207. */
  208. @SideOnly(Side.CLIENT)
  209. public void setVelocity(double p_70016_1_, double p_70016_3_, double p_70016_5_)
  210. {
  211. this.velocityX = this.motionX = p_70016_1_;
  212. this.velocityY = this.motionY = p_70016_3_;
  213. this.velocityZ = this.motionZ = p_70016_5_;
  214. }
  215.  
  216. /**
  217. * Called to update the entity's position/logic.
  218. */
  219. public void onUpdate()
  220. {
  221. super.onUpdate();
  222.  
  223. if (this.getTimeSinceHit() > 0)
  224. {
  225. this.setTimeSinceHit(this.getTimeSinceHit() - 1);
  226. }
  227.  
  228. if (this.getDamageTaken() > 0.0F)
  229. {
  230. this.setDamageTaken(this.getDamageTaken() - 1.0F);
  231. }
  232.  
  233. this.prevPosX = this.posX;
  234. this.prevPosY = this.posY;
  235. this.prevPosZ = this.posZ;
  236. byte b0 = 5;
  237. double d0 = 0.0D;
  238.  
  239. for (int i = 0; i < b0; ++i)
  240. {
  241. double d1 = this.boundingBox.minY + (this.boundingBox.maxY - this.boundingBox.minY) * (double)(i + 0) / (double)b0 - 0.125D;
  242. double d3 = this.boundingBox.minY + (this.boundingBox.maxY - this.boundingBox.minY) * (double)(i + 1) / (double)b0 - 0.125D;
  243. AxisAlignedBB axisalignedbb = AxisAlignedBB.getBoundingBox(this.boundingBox.minX, d1, this.boundingBox.minZ, this.boundingBox.maxX, d3, this.boundingBox.maxZ);
  244.  
  245. if (this.worldObj.isAABBInMaterial(axisalignedbb, Material.water))
  246. {
  247. d0 += 1.0D / (double)b0;
  248. }
  249. }
  250.  
  251. double d10 = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
  252. double d2;
  253. double d4;
  254. int j;
  255.  
  256. if (d10 > 0.26249999999999996D)
  257. {
  258. d2 = Math.cos((double)this.rotationYaw * Math.PI / 180.0D);
  259. d4 = Math.sin((double)this.rotationYaw * Math.PI / 180.0D);
  260.  
  261. for (j = 0; (double)j < 1.0D + d10 * 60.0D; ++j)
  262. {
  263. double d5 = (double)(this.rand.nextFloat() * 2.0F - 1.0F);
  264. double d6 = (double)(this.rand.nextInt(2) * 2 - 1) * 0.7D;
  265. double d8;
  266. double d9;
  267.  
  268. if (this.rand.nextBoolean())
  269. {
  270. d8 = this.posX - d2 * d5 * 0.8D + d4 * d6;
  271. d9 = this.posZ - d4 * d5 * 0.8D - d2 * d6;
  272. this.worldObj.spawnParticle("splash", d8, this.posY - 0.125D, d9, this.motionX, this.motionY, this.motionZ);
  273. }
  274. else
  275. {
  276. d8 = this.posX + d2 + d4 * d5 * 0.7D;
  277. d9 = this.posZ + d4 - d2 * d5 * 0.7D;
  278. this.worldObj.spawnParticle("splash", d8, this.posY - 0.125D, d9, this.motionX, this.motionY, this.motionZ);
  279. }
  280. }
  281. }
  282.  
  283. double d11;
  284. double d12;
  285.  
  286. if (this.worldObj.isRemote && this.isBoatEmpty)
  287. {
  288. if (this.boatPosRotationIncrements > 0)
  289. {
  290. d2 = this.posX + (this.boatX - this.posX) / (double)this.boatPosRotationIncrements;
  291. d4 = this.posY + (this.boatY - this.posY) / (double)this.boatPosRotationIncrements;
  292. d11 = this.posZ + (this.boatZ - this.posZ) / (double)this.boatPosRotationIncrements;
  293. d12 = MathHelper.wrapAngleTo180_double(this.boatYaw - (double)this.rotationYaw);
  294. this.rotationYaw = (float)((double)this.rotationYaw + d12 / (double)this.boatPosRotationIncrements);
  295. this.rotationPitch = (float)((double)this.rotationPitch + (this.boatPitch - (double)this.rotationPitch) / (double)this.boatPosRotationIncrements);
  296. --this.boatPosRotationIncrements;
  297. this.setPosition(d2, d4, d11);
  298. this.setRotation(this.rotationYaw, this.rotationPitch);
  299. }
  300. else
  301. {
  302. d2 = this.posX + this.motionX;
  303. d4 = this.posY + this.motionY;
  304. d11 = this.posZ + this.motionZ;
  305. this.setPosition(d2, d4, d11);
  306.  
  307. if (this.onGround)
  308. {
  309. this.motionX *= 0.5D;
  310. this.motionY *= 0.5D;
  311. this.motionZ *= 0.5D;
  312. }
  313.  
  314. this.motionX *= 0.9900000095367432D;
  315. this.motionY *= 0.949999988079071D;
  316. this.motionZ *= 0.9900000095367432D;
  317. }
  318. }
  319. else
  320. {
  321. if (d0 < 1.0D)
  322. {
  323. d2 = d0 * 2.0D - 1.0D;
  324. this.motionY += 0.03999999910593033D * d2;
  325. }
  326. else
  327. {
  328. if (this.motionY < 0.0D)
  329. {
  330. this.motionY /= 2.0D;
  331. }
  332.  
  333. this.motionY += 0.007000000216066837D;
  334. }
  335.  
  336. if (this.riddenByEntity != null && this.riddenByEntity instanceof EntityLivingBase)
  337. {
  338. EntityLivingBase entitylivingbase = (EntityLivingBase)this.riddenByEntity;
  339. float f = this.riddenByEntity.rotationYaw + -entitylivingbase.moveStrafing * 90.0F;
  340. this.motionX += -Math.sin((double)(f * (float)Math.PI / 180.0F)) * this.speedMultiplier * (double)entitylivingbase.moveForward * 0.05000000074505806D;
  341. this.motionZ += Math.cos((double)(f * (float)Math.PI / 180.0F)) * this.speedMultiplier * (double)entitylivingbase.moveForward * 0.05000000074505806D;
  342. }
  343.  
  344. d2 = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
  345.  
  346. if (d2 > 0.35D)
  347. {
  348. d4 = 0.35D / d2;
  349. this.motionX *= d4;
  350. this.motionZ *= d4;
  351. d2 = 0.35D;
  352. }
  353.  
  354. if (d2 > d10 && this.speedMultiplier < 0.35D)
  355. {
  356. this.speedMultiplier += (0.35D - this.speedMultiplier) / 35.0D;
  357.  
  358. if (this.speedMultiplier > 0.35D)
  359. {
  360. this.speedMultiplier = 0.35D;
  361. }
  362. }
  363. else
  364. {
  365. this.speedMultiplier -= (this.speedMultiplier - 0.07D) / 35.0D;
  366.  
  367. if (this.speedMultiplier < 0.07D)
  368. {
  369. this.speedMultiplier = 0.07D;
  370. }
  371. }
  372.  
  373. int l;
  374.  
  375. for (l = 0; l < 4; ++l)
  376. {
  377. int i1 = MathHelper.floor_double(this.posX + ((double)(l % 2) - 0.5D) * 0.8D);
  378. j = MathHelper.floor_double(this.posZ + ((double)(l / 2) - 0.5D) * 0.8D);
  379.  
  380. for (int j1 = 0; j1 < 2; ++j1)
  381. {
  382. int k = MathHelper.floor_double(this.posY) + j1;
  383. Block block = this.worldObj.getBlock(i1, k, j);
  384.  
  385. if (block == Blocks.snow_layer)
  386. {
  387. this.worldObj.setBlockToAir(i1, k, j);
  388. this.isCollidedHorizontally = false;
  389. }
  390. else if (block == Blocks.waterlily)
  391. {
  392. this.worldObj.func_147480_a(i1, k, j, true);
  393. this.isCollidedHorizontally = false;
  394. }
  395. }
  396. }
  397.  
  398. if (this.onGround)
  399. {
  400. this.motionX *= 0.5D;
  401. this.motionY *= 0.5D;
  402. this.motionZ *= 0.5D;
  403. }
  404.  
  405. this.moveEntity(this.motionX, this.motionY, this.motionZ);
  406.  
  407. if (this.isCollidedHorizontally && d10 > 0.2D)
  408. {
  409. if (!this.worldObj.isRemote && !this.isDead)
  410. {
  411. this.setDead();
  412.  
  413. for (l = 0; l < 3; ++l)
  414. {
  415. this.func_145778_a(Item.getItemFromBlock(Blocks.planks), 1, 0.0F);
  416. }
  417.  
  418. for (l = 0; l < 2; ++l)
  419. {
  420. this.func_145778_a(Items.stick, 1, 0.0F);
  421. }
  422. }
  423. }
  424. else
  425. {
  426. this.motionX *= 0.9900000095367432D;
  427. this.motionY *= 0.949999988079071D;
  428. this.motionZ *= 0.9900000095367432D;
  429. }
  430.  
  431. this.rotationPitch = 0.0F;
  432. d4 = (double)this.rotationYaw;
  433. d11 = this.prevPosX - this.posX;
  434. d12 = this.prevPosZ - this.posZ;
  435.  
  436. if (d11 * d11 + d12 * d12 > 0.001D)
  437. {
  438. d4 = (double)((float)(Math.atan2(d12, d11) * 180.0D / Math.PI));
  439. }
  440.  
  441. double d7 = MathHelper.wrapAngleTo180_double(d4 - (double)this.rotationYaw);
  442.  
  443. if (d7 > 20.0D)
  444. {
  445. d7 = 20.0D;
  446. }
  447.  
  448. if (d7 < -20.0D)
  449. {
  450. d7 = -20.0D;
  451. }
  452.  
  453. this.rotationYaw = (float)((double)this.rotationYaw + d7);
  454. this.setRotation(this.rotationYaw, this.rotationPitch);
  455.  
  456. if (!this.worldObj.isRemote)
  457. {
  458. List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox.expand(0.20000000298023224D, 0.0D, 0.20000000298023224D));
  459.  
  460. if (list != null && !list.isEmpty())
  461. {
  462. for (int k1 = 0; k1 < list.size(); ++k1)
  463. {
  464. Entity entity = (Entity)list.get(k1);
  465.  
  466. if (entity != this.riddenByEntity && entity.canBePushed() && entity instanceof EntityBoat)
  467. {
  468. entity.applyEntityCollision(this);
  469. }
  470. }
  471. }
  472.  
  473. if (this.riddenByEntity != null && this.riddenByEntity.isDead)
  474. {
  475. this.riddenByEntity = null;
  476. }
  477. }
  478. }
  479. }
  480.  
  481. public void updateRiderPosition()
  482. {
  483. if (this.riddenByEntity != null)
  484. {
  485. double d0 = Math.cos((double)this.rotationYaw * Math.PI / 180.0D) * 0.4D;
  486. double d1 = Math.sin((double)this.rotationYaw * Math.PI / 180.0D) * 0.4D;
  487. this.riddenByEntity.setPosition(this.posX + d0, this.posY + this.getMountedYOffset() + this.riddenByEntity.getYOffset(), this.posZ + d1);
  488. }
  489. }
  490.  
  491. /**
  492. * (abstract) Protected helper method to write subclass entity data to NBT.
  493. */
  494. protected void writeEntityToNBT(NBTTagCompound p_70014_1_) {}
  495.  
  496. /**
  497. * (abstract) Protected helper method to read subclass entity data from NBT.
  498. */
  499. protected void readEntityFromNBT(NBTTagCompound p_70037_1_) {}
  500.  
  501. @SideOnly(Side.CLIENT)
  502. public float getShadowSize()
  503. {
  504. return 0.0F;
  505. }
  506.  
  507. /**
  508. * First layer of player interaction
  509. */
  510. public boolean interactFirst(EntityPlayer p_130002_1_)
  511. {
  512. if (this.riddenByEntity != null && this.riddenByEntity instanceof EntityPlayer && this.riddenByEntity != p_130002_1_)
  513. {
  514. return true;
  515. }
  516. else
  517. {
  518. if (!this.worldObj.isRemote)
  519. {
  520. p_130002_1_.mountEntity(this);
  521. }
  522.  
  523. return true;
  524. }
  525. }
  526.  
  527. /**
  528. * Takes in the distance the entity has fallen this tick and whether its on the ground to update the fall distance
  529. * and deal fall damage if landing on the ground. Args: distanceFallenThisTick, onGround
  530. */
  531. protected void updateFallState(double p_70064_1_, boolean p_70064_3_)
  532. {
  533. int i = MathHelper.floor_double(this.posX);
  534. int j = MathHelper.floor_double(this.posY);
  535. int k = MathHelper.floor_double(this.posZ);
  536.  
  537. if (p_70064_3_)
  538. {
  539. if (this.fallDistance > 3.0F)
  540. {
  541. this.fall(this.fallDistance);
  542.  
  543. if (!this.worldObj.isRemote && !this.isDead)
  544. {
  545. this.setDead();
  546. int l;
  547.  
  548. for (l = 0; l < 3; ++l)
  549. {
  550. this.func_145778_a(Item.getItemFromBlock(Blocks.planks), 1, 0.0F);
  551. }
  552.  
  553. for (l = 0; l < 2; ++l)
  554. {
  555. this.func_145778_a(Items.stick, 1, 0.0F);
  556. }
  557. }
  558.  
  559. this.fallDistance = 0.0F;
  560. }
  561. }
  562. else if (this.worldObj.getBlock(i, j - 1, k).getMaterial() != Material.water && p_70064_1_ < 0.0D)
  563. {
  564. this.fallDistance = (float)((double)this.fallDistance - p_70064_1_);
  565. }
  566. }
  567.  
  568. /**
  569. * Sets the damage taken from the last hit.
  570. */
  571. public void setDamageTaken(float p_70266_1_)
  572. {
  573. this.dataWatcher.updateObject(19, Float.valueOf(p_70266_1_));
  574. }
  575.  
  576. /**
  577. * Gets the damage taken from the last hit.
  578. */
  579. public float getDamageTaken()
  580. {
  581. return this.dataWatcher.getWatchableObjectFloat(19);
  582. }
  583.  
  584. /**
  585. * Sets the time to count down from since the last time entity was hit.
  586. */
  587. public void setTimeSinceHit(int p_70265_1_)
  588. {
  589. this.dataWatcher.updateObject(17, Integer.valueOf(p_70265_1_));
  590. }
  591.  
  592. /**
  593. * Gets the time since the last hit.
  594. */
  595. public int getTimeSinceHit()
  596. {
  597. return this.dataWatcher.getWatchableObjectInt(17);
  598. }
  599.  
  600. /**
  601. * Sets the forward direction of the entity.
  602. */
  603. public void setForwardDirection(int p_70269_1_)
  604. {
  605. this.dataWatcher.updateObject(18, Integer.valueOf(p_70269_1_));
  606. }
  607.  
  608. /**
  609. * Gets the forward direction of the entity.
  610. */
  611. public int getForwardDirection()
  612. {
  613. return this.dataWatcher.getWatchableObjectInt(18);
  614. }
  615.  
  616. /**
  617. * true if no player in boat
  618. */
  619. @SideOnly(Side.CLIENT)
  620. public void setIsBoatEmpty(boolean p_70270_1_)
  621. {
  622. this.isBoatEmpty = p_70270_1_;
  623. }
  624. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement