Advertisement
Guest User

EntityTrucks

a guest
Aug 16th, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.90 KB | None | 0 0
  1. package simcraft.entity.trucks;
  2.  
  3. import java.util.List;
  4.  
  5. import org.lwjgl.input.Keyboard;
  6.  
  7. import cpw.mods.fml.relauncher.Side;
  8. import cpw.mods.fml.relauncher.SideOnly;
  9.  
  10. import simcraft.core.SimCraft;
  11. import simcraft.core.sound.SoundSource;
  12. import simcraft.core.sound.SoundsManager;
  13. import simcraft.entity.KeyConfig;
  14. import net.minecraft.block.Block;
  15. import net.minecraft.block.material.Material;
  16. import net.minecraft.entity.Entity;
  17. import net.minecraft.entity.EntityLiving;
  18. import net.minecraft.entity.EntityLivingBase;
  19. import net.minecraft.entity.item.EntityBoat;
  20. import net.minecraft.entity.item.EntityItem;
  21. import net.minecraft.entity.player.EntityPlayer;
  22. import net.minecraft.item.Item;
  23. import net.minecraft.item.ItemStack;
  24. import net.minecraft.nbt.NBTTagCompound;
  25. import net.minecraft.nbt.NBTTagList;
  26. import net.minecraft.util.AxisAlignedBB;
  27. import net.minecraft.util.DamageSource;
  28. import net.minecraft.util.MathHelper;
  29. import net.minecraft.world.World;
  30.  
  31. public class EntityTrucks extends Entity
  32. {
  33. public boolean field_70279_a;
  34. public double speedMultiplier;
  35. public int vehiclePosRotationIncrements;
  36. public double vehicleX;
  37. public double vehicleY;
  38. public double vehicleZ;
  39. public double vehicleYaw;
  40. public double vehiclePitch;
  41. @SideOnly(Side.CLIENT)
  42. public double velocityX;
  43. @SideOnly(Side.CLIENT)
  44. public double velocityY;
  45. @SideOnly(Side.CLIENT)
  46. public double velocityZ;
  47.  
  48. public double turnLeftModifier;
  49. public double turnRightModifier;
  50. public double acceleration;
  51. public double decceleration;
  52. public double maxSpeed;
  53. public double engineSpeed;
  54. public float rotationRoll;
  55. public float wheelYaw;
  56. public double playerXOffset;
  57. public double playerYOffset;
  58. public double playerZOffset;
  59. public double theta;
  60.  
  61. public int vehicleMaxHealth;
  62. public int vehicleHealth;
  63. public int vehicleMaxFuel;
  64. public int vehicleFuel;
  65.  
  66. public EntityTrucks(World par1World)
  67. {
  68. super(par1World);
  69. this.field_70279_a = true;
  70. this.speedMultiplier = 0.07D;
  71. this.preventEntitySpawning = true;
  72. this.setSize(1.5F, 0.6F);
  73. this.yOffset = this.height - 0.17F;
  74. this.playerXOffset = 0.0D;
  75. this.playerYOffset = 0.0D;
  76. this.playerZOffset = 0.0D;
  77. this.wheelYaw = 0.0F;
  78. this.vehicleHealth = 0;
  79. this.vehicleMaxHealth = 0;
  80. this.vehicleMaxFuel = 0;
  81. this.vehicleFuel = 0;
  82. }
  83.  
  84. public EntityTrucks(World world, double d, double d1, double d2)
  85. {
  86. this(world);
  87. this.setPosition(d, d1 + (double)yOffset, d2);
  88. this.motionX = 0.0D;
  89. this.motionY = 0.0D;
  90. this.motionZ = 0.0D;
  91. this.prevPosX = d;
  92. this.prevPosY = d1;
  93. this.prevPosZ = d2;
  94. }
  95.  
  96. public EntityTrucks(World world, double d, double d1, double d2,
  97. EntityPlayer entityplayer, int i)
  98. {
  99. this(world);
  100. this.setPosition(d, d1 + (double)yOffset, d2);
  101. this.motionX = 0.0D;
  102. this.motionY = 0.0D;
  103. this.motionZ = 0.0D;
  104. this.rotationYaw = entityplayer.rotationYaw;
  105. this.prevPosX = d;
  106. this.prevPosY = d1;
  107. this.prevPosZ = d2;
  108. }
  109.  
  110. /**
  111. * returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to
  112. * prevent them from trampling crops
  113. */
  114. protected boolean canTriggerWalking()
  115. {
  116. return false;
  117. }
  118.  
  119. protected void entityInit()
  120. {
  121. this.dataWatcher.addObject(17, new Integer(0));
  122. this.dataWatcher.addObject(18, new Integer(1));
  123. this.dataWatcher.addObject(19, new Float(0.0F));
  124. }
  125.  
  126. /**
  127. * Returns a boundingBox used to collide the entity with other entities and blocks. This enables the entity to be
  128. * pushable on contact, like boats or minecarts.
  129. */
  130. public AxisAlignedBB getCollisionBox(Entity par1Entity)
  131. {
  132. return par1Entity.boundingBox;
  133. }
  134.  
  135. /**
  136. * returns the bounding box for this entity
  137. */
  138. public AxisAlignedBB getBoundingBox()
  139. {
  140. return this.boundingBox;
  141. }
  142.  
  143. /**
  144. * Returns true if this entity should push and be pushed by other entities when colliding.
  145. */
  146. public boolean canBePushed()
  147. {
  148. return false;
  149. }
  150.  
  151. /**
  152. * Returns the Y offset from the entity's position for any entity riding this one.
  153. */
  154. public double getMountedYOffset()
  155. {
  156. return playerYOffset;
  157. }
  158.  
  159. /**
  160. * Sets The position of the Vehicle.
  161. */
  162. public void setPosition(double d, double d1, double d2)
  163. {
  164. this.posX = d;
  165. this.posY = d1;
  166. this.posZ = d2;
  167. float f = width / 2.0F;
  168. float f1 = height;
  169. this.boundingBox.setBounds(d - (double)f, (d1 - (double)this.yOffset) + (double)this.ySize, d2 - (double)f, d + (double)f, (d1 - (double)this.yOffset) + (double)this.ySize + (double)f1, d2 + (double)f);
  170. }
  171.  
  172. /**
  173. * Called when the entity is attacked.
  174. */
  175. public boolean attackEntityFrom(DamageSource par1DamageSource, float par2)
  176. {
  177. if (this.isEntityInvulnerable())
  178. {
  179. return false;
  180. }
  181. else if (!this.worldObj.isRemote && !this.isDead)
  182. {
  183. this.setForwardDirection(-this.getForwardDirection());
  184. this.setTimeSinceHit(10);
  185. this.setDamageTaken(this.getDamageTaken() + par2 * 10.0F);
  186. this.setBeenAttacked();
  187. boolean flag = par1DamageSource.getEntity() instanceof EntityPlayer && ((EntityPlayer)par1DamageSource.getEntity()).capabilities.isCreativeMode;
  188.  
  189. if (flag || this.getDamageTaken() > 40.0F)
  190. {
  191. if (this.riddenByEntity != null)
  192. {
  193. this.riddenByEntity.mountEntity(this);
  194. }
  195.  
  196. if (!flag)
  197. {
  198. this.dropItemWithOffset(Item.boat.itemID, 1, 0.0F);
  199. }
  200.  
  201. this.destroyVehicle();
  202. }
  203.  
  204. return true;
  205. }
  206. else
  207. {
  208. return true;
  209. }
  210. }
  211.  
  212. /**
  213. * Destroys the vehicle.
  214. */
  215. public void destroyVehicle()
  216. {
  217. if (!worldObj.isRemote)
  218. {
  219. this.setDead();
  220. this.spawnExplosionParticle();
  221. }
  222. }
  223.  
  224. /**
  225. * Spawns an explosion particle around the Entity's location
  226. */
  227. public void spawnExplosionParticle()
  228. {
  229. for (int i = 0; i < 20; ++i)
  230. {
  231. double d0 = this.rand.nextGaussian() * 0.02D;
  232. double d1 = this.rand.nextGaussian() * 0.02D;
  233. double d2 = this.rand.nextGaussian() * 0.02D;
  234. double d3 = 10.0D;
  235. this.worldObj.spawnParticle("explode", this.posX + (double)(this.rand.nextFloat() * this.width * 2.0F) - (double)this.width - d0 * d3, this.posY + (double)(this.rand.nextFloat() * this.height) - d1 * d3, this.posZ + (double)(this.rand.nextFloat() * this.width * 2.0F) - (double)this.width - d2 * d3, d0, d1, d2);
  236. }
  237. }
  238.  
  239. @SideOnly(Side.CLIENT)
  240. /**
  241. * Setups the entity to do the hurt animation. Only used by packets in multiplayer.
  242. */
  243. public void performHurtAnimation()
  244. {
  245. this.setForwardDirection(-this.getForwardDirection());
  246. this.setTimeSinceHit(10);
  247. this.setDamageTaken(this.getDamageTaken() * 11.0F);
  248. if (this.getForwardDirection() > 0)
  249. {
  250. this.worldObj.playSoundAtEntity(this, "impactA", 1.0F, 1.0F);
  251. }
  252. else
  253. {
  254. this.worldObj.playSoundAtEntity(this, "impactB", 1.0F, 1.0F);
  255. }
  256. }
  257.  
  258. /**
  259. * Returns true if other Entities should be prevented from moving through this Entity.
  260. */
  261. public boolean canBeCollidedWith()
  262. {
  263. return !this.isDead;
  264. }
  265.  
  266. @SideOnly(Side.CLIENT)
  267.  
  268. /**
  269. * Sets the position and rotation. Only difference from the other one is no bounding on the rotation. Args: posX,
  270. * posY, posZ, yaw, pitch
  271. */
  272. public void setPositionAndRotation2(double par1, double par3, double par5, float par7, float par8, int par9)
  273. {
  274. if (this.field_70279_a)
  275. {
  276. this.vehiclePosRotationIncrements = par9 + 5;
  277. }
  278. else
  279. {
  280. double d3 = par1 - this.posX;
  281. double d4 = par3 - this.posY;
  282. double d5 = par5 - this.posZ;
  283. double d6 = d3 * d3 + d4 * d4 + d5 * d5;
  284.  
  285. if (d6 <= 1.0D)
  286. {
  287. return;
  288. }
  289.  
  290. this.vehiclePosRotationIncrements = 3;
  291. }
  292.  
  293. this.vehicleX = par1;
  294. this.vehicleY = par3;
  295. this.vehicleZ = par5;
  296. this.vehicleYaw = (double)par7;
  297. this.vehiclePitch = (double)par8;
  298. this.motionX = this.velocityX;
  299. this.motionY = this.velocityY;
  300. this.motionZ = this.velocityZ;
  301. }
  302.  
  303. @SideOnly(Side.CLIENT)
  304.  
  305. /**
  306. * Sets the velocity to the args. Args: x, y, z
  307. */
  308. public void setVelocity(double par1, double par3, double par5)
  309. {
  310. this.velocityX = this.motionX = par1;
  311. this.velocityY = this.motionY = par3;
  312. this.velocityZ = this.motionZ = par5;
  313. }
  314.  
  315. public double getSpeed()
  316. {
  317. return Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
  318. }
  319.  
  320. public void onUpdate()
  321. {
  322. this.pressKeyClient();
  323.  
  324.  
  325. /** Last Time Entity was Hit **/
  326. if (this.getTimeSinceHit() > 0)
  327. {
  328. this.setTimeSinceHit(this.getTimeSinceHit() - 1);
  329. }
  330.  
  331. /** Last TDamage Taken **/
  332. if (this.getDamageTaken() > 0.0F)
  333. {
  334. this.setDamageTaken(this.getDamageTaken() - 1.0F);
  335. }
  336.  
  337. /** Update current position and recalculate fuel and health **/
  338. this.prevPosX = this.posX;
  339. this.prevPosY = this.posY;
  340. this.prevPosZ = this.posZ;
  341. this.vehicleFuel = Math.max(0, Math.min(this.vehicleFuel, this.vehicleMaxFuel));
  342. this.vehicleFuel = 10 * this.vehicleFuel < this.vehicleMaxFuel ? this.vehicleFuel - 1 : this.vehicleFuel;
  343. this.vehicleHealth = Math.max(0, Math.min(this.vehicleHealth, this.vehicleMaxHealth));
  344. this.vehicleHealth = 10 * this.vehicleHealth < this.vehicleMaxHealth ? this.vehicleHealth - 1 : this.vehicleHealth;
  345.  
  346. /**Vehicle Health **/
  347. if (this.vehicleHealth <= 0)
  348. {
  349. this.destroyVehicle();
  350. }
  351.  
  352. /** Vehicle Fuel deducted while moving**/
  353. if (this.vehicleFuel > 0 && getSpeed() > 0.02D)
  354. {
  355. this.vehicleFuel--;
  356. }
  357.  
  358. /** Vehicle Health Below 150 **/
  359. if (this.vehicleHealth < 150)
  360. {
  361. this.worldObj.spawnParticle("smoke", posX + 2.5D * Math.cos(((double)this.rotationYaw * Math.PI) / 180D) + (0.80000000000000004D * (double)rand.nextFloat() - 0.40000000000000002D), posY + 1.2D, posZ + 2.5D * Math.sin(((double)this.rotationYaw * Math.PI) / 180D) + (0.80000000000000004D * (double)rand.nextFloat() - 0.40000000000000002D), this.motionX, 0.10000000000000001D, this.motionZ);
  362. }
  363.  
  364. /** Vehicle Health Below 50 **/
  365. if (this.vehicleHealth < 50)
  366. {
  367. this.worldObj.spawnParticle("flame", posX + 2.5D * Math.cos(((double)this.rotationYaw * Math.PI) / 180D) + (0.59999999999999998D * (double)rand.nextFloat() - 0.29999999999999999D), posY + 1.2D, posZ + 2.5D * Math.sin(((double)this.rotationYaw * Math.PI) / 180D) + (0.59999999999999998D * (double)rand.nextFloat() - 0.29999999999999999D), this.motionX, 0.050000000000000003D, this.motionZ);
  368. }
  369.  
  370. /** Bounding Box around Entity **/
  371.  
  372. this.prevPosX = this.posX;
  373. this.prevPosY = this.posY;
  374. this.prevPosZ = this.posZ;
  375. byte b0 = 5;
  376. double d0 = 0.0D;
  377.  
  378. for (int i = 0; i < b0; ++i)
  379. {
  380. double d1 = this.boundingBox.minY + (this.boundingBox.maxY - this.boundingBox.minY) * (double)(i + 0) / (double)b0 - 0.125D;
  381. double d2 = this.boundingBox.minY + (this.boundingBox.maxY - this.boundingBox.minY) * (double)(i + 1) / (double)b0 - 0.125D;
  382. AxisAlignedBB axisalignedbb = AxisAlignedBB.getAABBPool().getAABB(this.boundingBox.minX, d1, this.boundingBox.minZ, this.boundingBox.maxX, d2, this.boundingBox.maxZ);
  383.  
  384. if (this.worldObj.isAABBInMaterial(axisalignedbb, Material.water))
  385. {
  386. d0 += 1.0D / (double)b0;
  387. }
  388. }
  389.  
  390. double d3 = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
  391. double d4;
  392. double d5;
  393.  
  394. if (d3 > 0.26249999999999996D)
  395. {
  396. d4 = Math.cos((double)this.rotationYaw * Math.PI / 180.0D);
  397. d5 = Math.sin((double)this.rotationYaw * Math.PI / 180.0D);
  398.  
  399. for (int j = 0; (double)j < 1.0D + d3 * 60.0D; ++j)
  400. {
  401. double d6 = (double)(this.rand.nextFloat() * 2.0F - 1.0F);
  402. double d7 = (double)(this.rand.nextInt(2) * 2 - 1) * 0.7D;
  403. double d8;
  404. double d9;
  405.  
  406. if (this.rand.nextBoolean())
  407. {
  408. d8 = this.posX - d4 * d6 * 0.8D + d5 * d7;
  409. d9 = this.posZ - d5 * d6 * 0.8D - d4 * d7;
  410. this.worldObj.spawnParticle("smoke", d8, this.posY - 0.125D, d9, this.motionX, this.motionY, this.motionZ);
  411. }
  412. else
  413. {
  414. d8 = this.posX + d4 + d5 * d6 * 0.7D;
  415. d9 = this.posZ + d5 - d4 * d6 * 0.7D;
  416. this.worldObj.spawnParticle("smoke", d8, this.posY - 0.125D, d9, this.motionX, this.motionY, this.motionZ);
  417. }
  418. }
  419. }
  420.  
  421. double d10;
  422. double d11;
  423.  
  424. if (this.worldObj.isRemote && this.field_70279_a)
  425. {
  426. if (this.vehiclePosRotationIncrements > 0)
  427. {
  428. d4 = this.posX + (this.vehicleX - this.posX) / (double)this.vehiclePosRotationIncrements;
  429. d5 = this.posY + (this.vehicleY - this.posY) / (double)this.vehiclePosRotationIncrements;
  430. d11 = this.posZ + (this.vehicleZ - this.posZ) / (double)this.vehiclePosRotationIncrements;
  431. d10 = MathHelper.wrapAngleTo180_double(this.vehicleYaw - (double)this.rotationYaw);
  432. double d12;
  433.  
  434. for (d12 = vehicleYaw - (double)rotationYaw; d12 < -180D; d12 += 360D) { }
  435.  
  436. for (; d12 >= 180D; d12 -= 360D) { }
  437.  
  438. this.rotationYaw += d12 / (double)this.vehiclePosRotationIncrements;
  439. this.rotationPitch += (this.vehiclePitch - (double)this.rotationPitch) / (double)this.vehiclePosRotationIncrements;
  440. vehiclePosRotationIncrements--;
  441. this.setPosition(d4, d5, d11);
  442. this.setRotation(this.rotationYaw, this.rotationPitch);
  443. }
  444. else
  445. {
  446. d4 = this.posX + this.motionX;
  447. d5 = this.posY + this.motionY;
  448. d11 = this.posZ + this.motionZ;
  449. this.setPosition(d4, d5, d11);
  450.  
  451. if (this.onGround)
  452. {
  453. this.motionX *= 0.5D;
  454. this.motionY *= 0.5D;
  455. this.motionZ *= 0.5D;
  456. }
  457.  
  458. this.motionX *= 0.94999999999999996D;
  459. this.motionY *= 0.94999999999999996D;
  460. this.motionZ *= 0.94999999999999996D;
  461.  
  462.  
  463. }
  464.  
  465. return;
  466. }
  467.  
  468. /** movement of Entity **/
  469. if (this.riddenByEntity != null && this.riddenByEntity instanceof EntityLivingBase)
  470. {
  471. double d = this.engineSpeed;
  472.  
  473. if (d < 0.0D)
  474. {
  475. d = 0.0D;
  476. }
  477.  
  478. double dmotionX = this.riddenByEntity.motionX;
  479. double dmotionY = this.riddenByEntity.motionY;
  480. double dmotionZ = this.riddenByEntity.motionZ;
  481. double d15 = Math.sqrt(dmotionX * dmotionX + dmotionY * dmotionY + dmotionZ * dmotionZ);
  482. this.engineSpeed += d15;
  483. double d16 = this.riddenByEntity.rotationYaw;
  484. double d17 = this.riddenByEntity.rotationPitch;
  485.  
  486. if (d16 - (double)this.rotationYaw > 1.0D)
  487. {
  488. this.rotationYaw += d / 3D;
  489. }
  490.  
  491. if (d16 - (double)this.rotationYaw < 1.0D)
  492. {
  493. this.rotationYaw -= d / 3D;
  494. }
  495.  
  496. if (d17 - (double)this.rotationPitch > 1.0D)
  497. {
  498. this.rotationPitch += d / 3D;
  499. }
  500.  
  501. if (d17 - (double)this.rotationPitch < 1.0D)
  502. {
  503. this.rotationPitch -= d / 3D;
  504. }
  505. }
  506.  
  507.  
  508. /** Wheel Yaw **/
  509. this.wheelYaw = Math.max(-60F, Math.min(60F, this.wheelYaw));
  510. this.wheelYaw *= 0.80000000000000004D;
  511.  
  512.  
  513. if ((getSpeed() * 10D <= (double)this.wheelYaw || this.wheelYaw <= 0.0F) && (getSpeed() * 5D <= (double)(-this.wheelYaw) || this.wheelYaw >= 0.0F) && getSpeed() > 0.0D)
  514. {
  515.  
  516. this.theta = (Math.atan2(this.motionZ, this.motionX) * 180D) / Math.PI;
  517.  
  518. for (this.theta = (Math.atan2(this.motionZ, this.motionX) * 180D) / Math.PI; this.theta <= 0.0D; this.theta += 360D) { }
  519.  
  520. for (; this.theta > 360D; this.theta -= 360D) { }
  521.  
  522. double d1;
  523.  
  524. for (d1 = this.rotationYaw; d1 <= 0.0D; d1 += 360D) { }
  525.  
  526. for (; d1 > 360D; d1 -= 360D) { }
  527.  
  528. double d6 = Math.abs(this.theta - d1);
  529.  
  530. if (d6 < 90D || d6 > 270D)
  531. {
  532. this.rotationYaw += 0.40000000000000002D * (double)this.wheelYaw * Math.sqrt(getSpeed() / this.maxSpeed);
  533. }
  534. else
  535. {
  536. this.rotationYaw -= 0.59999999999999998D * (double)this.wheelYaw * Math.sqrt(getSpeed() / this.maxSpeed);
  537. }
  538.  
  539. if (this.wheelYaw > 0.0F)
  540. {
  541. this.motionX += getSpeed() * 0.02D * this.acceleration * Math.cos(((this.rotationYaw + 90F) * (float)Math.PI) / 180F);
  542. this.motionZ += getSpeed() * 0.02D * this.acceleration * Math.sin(((this.rotationYaw + 90F) * (float)Math.PI) / 180F);
  543. }
  544. else
  545. {
  546. this.motionX += getSpeed() * 0.02D * this.acceleration * Math.cos(((this.rotationYaw - 90F) * (float)Math.PI) / 180F);
  547. this.motionZ += getSpeed() * 0.02D * this.acceleration * Math.sin(((this.rotationYaw - 90F) * (float)Math.PI) / 180F);
  548. }
  549. }
  550.  
  551. if (getSpeed() > this.maxSpeed)
  552. {
  553. this.motionX *= this.maxSpeed / getSpeed();
  554. this.motionY *= this.maxSpeed / getSpeed();
  555. this.motionZ *= this.maxSpeed / getSpeed();
  556. }
  557.  
  558.  
  559. if (this.onGround && this.riddenByEntity == null)
  560. {
  561. this.motionX = 0.0D;
  562. this.motionY = 0.0D;
  563. this.motionZ = 0.0D;
  564. this.rotationPitch *= 0.90000000000000002D;
  565. this.engineSpeed *= 0.90000000000000002D;
  566. }
  567.  
  568.  
  569. if (!this.onGround)
  570. {
  571. //motionY--;
  572. }
  573.  
  574. this.motionX *= 0.94999999999999996D;
  575. this.motionY *= 0.94999999999999996D;
  576. this.motionZ *= 0.94999999999999996D;
  577.  
  578. moveEntity(this.motionX, this.motionY, this.motionZ);
  579.  
  580. int j = (int)Math.floor(this.posX);
  581. int k = (int)Math.floor(this.posY + 0.5D);
  582. int l = (int)Math.floor(this.posZ);
  583. byte byte0 = 0;
  584. byte byte1 = 0;
  585. float f;
  586.  
  587. for (f = this.rotationYaw; f <= -45F; f += 360F) { }
  588.  
  589. for (; f > 315F; f -= 360F) { }
  590.  
  591. if (f > -45F && f <= 45F)
  592. {
  593. byte0 = 1;
  594. byte1 = 0;
  595. }
  596.  
  597. if (f > 45F && f <= 135F)
  598. {
  599. byte0 = 0;
  600. byte1 = 1;
  601. }
  602.  
  603. if (f > 135F && f <= 225F)
  604. {
  605. byte0 = -1;
  606. byte1 = 0;
  607. }
  608.  
  609. if (f > 225F && f <= 315F)
  610. {
  611. byte0 = 0;
  612. byte1 = -1;
  613. }
  614.  
  615.  
  616. boolean flag = false;
  617.  
  618.  
  619. /** Collision of Blocks **/
  620. if (!this.worldObj.isRemote)
  621. {
  622. List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox.expand(0.20000000298023224D, 0.0D, 0.20000000298023224D));
  623. int li;
  624.  
  625. if (list != null && !list.isEmpty())
  626. {
  627. for (li = 0; li < list.size(); ++li)
  628. {
  629. Entity entity = (Entity)list.get(li);
  630.  
  631. if (entity != this.riddenByEntity && entity instanceof EntityTrucks)
  632. {
  633. entity.applyEntityCollision(this);
  634. }
  635. }
  636. }
  637.  
  638. for (li = 0; li < 4; ++li)
  639. {
  640. int i1 = MathHelper.floor_double(this.posX + ((double)(li % 2) - 0.5D) * 0.8D);
  641. int j1 = MathHelper.floor_double(this.posZ + ((double)(li / 2) - 0.5D) * 0.8D);
  642.  
  643. for (int k1 = 0; k1 < 2; ++k1)
  644. {
  645. int l1 = MathHelper.floor_double(this.posY) + k1;
  646. int i2 = this.worldObj.getBlockId(i1, l1, j1);
  647.  
  648. if (i2 == Block.leaves.blockID)
  649. {
  650. this.worldObj.setBlockToAir(i1, l1, j1);
  651. }
  652. else if (i2 == Block.glass.blockID)
  653. {
  654. this.worldObj.destroyBlock(i1, l1, j1, true);
  655. }
  656. }
  657. }
  658.  
  659. rotationPitch = flag ? ((rotationPitch + 5F) * 8F) / 10F : rotationPitch * 0.8F;
  660. rotationRoll *= 0.8F;
  661.  
  662.  
  663. if (riddenByEntity != null)
  664. {
  665.  
  666. riddenByEntity.fallDistance = 0.0F;
  667. List list1 = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.expand(0.10000000000000001D, 0.0D, 0.10000000000000001D));
  668.  
  669. if (list1 != null && list1.size() > 0)
  670. {
  671. for (int i2 = 0; i2 < list1.size(); i2++)
  672. {
  673. Entity entity = (Entity)list1.get(i2);
  674. boolean flag2 = true;
  675.  
  676. if (flag2 && entity != riddenByEntity && entity.canBePushed())
  677. {
  678. entity.applyEntityCollision(this);
  679. }
  680. }
  681. }
  682. }
  683.  
  684. if (this.riddenByEntity != null && this.riddenByEntity.isDead)
  685. {
  686. this.riddenByEntity = null;
  687. }
  688. }
  689.  
  690. }
  691.  
  692. public void updateRiderPosition()
  693. {
  694. if (this.riddenByEntity != null)
  695. {
  696. double d = this.playerXOffset + 0.05D;
  697. double d1 = getMountedYOffset() + this.riddenByEntity.getYOffset() - 1.5D;
  698. double d2 = this.playerZOffset + 0.05D;
  699. double d3 = Math.cos(((double)(-this.rotationYaw) / 180D) * 3.1415926535897931D);
  700. double d4 = Math.sin(((double)(-this.rotationYaw) / 180D) * 3.1415926535897931D);
  701. //double d5 = Math.cos(((double)this.rotationPitch / 180D) * 3.1415926535897931D);
  702. // double d6 = Math.sin(((double)this.rotationPitch / 180D) * 3.1415926535897931D);
  703. double d7 = Math.cos(((double)this.rotationYaw * 3.1415926535897931D) / 180D) * 0.40000000000000002D;
  704. double d8 = Math.sin(((double)this.rotationYaw * 3.1415926535897931D) / 180D) * 0.40000000000000002D;
  705. double d9 = (d - d1 ) * d3 + d2 * d4;
  706. double d10 = d + d1;
  707. double d11 = (d1 - d) * d4 + d2 * d3;
  708. this.riddenByEntity.setPosition(this.posX + d9 + d7, this.posY + d10, this.posZ + d11 + d8);
  709. return;
  710. }
  711. else
  712. {
  713. return;
  714. }
  715. }
  716.  
  717. /**
  718. * (abstract) Protected helper method to write subclass entity data to NBT.
  719. */
  720. protected void writeEntityToNBT(NBTTagCompound par1NBTTagCompound) {}
  721.  
  722. /**
  723. * (abstract) Protected helper method to read subclass entity data from NBT.
  724. */
  725. protected void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) {}
  726.  
  727. @SideOnly(Side.CLIENT)
  728. public float getShadowSize()
  729. {
  730. return 0.0F;
  731. }
  732.  
  733. public boolean func_130002_c(EntityPlayer par1EntityPlayer)
  734. {
  735. if (this.riddenByEntity != null && this.riddenByEntity instanceof EntityPlayer && this.riddenByEntity != par1EntityPlayer)
  736. {
  737. return true;
  738. }
  739. else
  740. {
  741. if (!this.worldObj.isRemote)
  742. {
  743. par1EntityPlayer.mountEntity(this);
  744. }
  745.  
  746. return true;
  747. }
  748. }
  749.  
  750. public void pressKey(int i)
  751. {
  752. double d = getSpeed();
  753.  
  754. if (d < 0.0D)
  755. {
  756. d = 0.0D;
  757. }
  758.  
  759. if (vehicleFuel > 0 || this.worldObj.isRemote)
  760. {
  761. switch (i)
  762. {
  763.  
  764. case 0:
  765. this.motionX += 0.02D * this.acceleration * Math.cos((this.rotationYaw * (float)Math.PI) / 180F);
  766. this.motionZ += 0.02D * this.acceleration * Math.sin((this.rotationYaw * (float)Math.PI) / 180F);
  767.  
  768. if (getSpeed() / this.maxSpeed < 0.75D)
  769. {
  770. this.rotationPitch += 2D * (1.0D - Math.sqrt(getSpeed() / this.maxSpeed));
  771. }
  772. break;
  773. case 1:
  774. this.motionX -= 0.02D * this.acceleration * Math.cos((this.rotationYaw * (float)Math.PI) / 180F);
  775. this.motionZ -= 0.02D * this.acceleration * Math.sin((this.rotationYaw * (float)Math.PI) / 180F);
  776.  
  777. if (getSpeed() / this.maxSpeed > 0.25D)
  778. {
  779. this.rotationPitch -= 2D * (getSpeed() / this.maxSpeed);
  780. }
  781. break;
  782. case 2:
  783. this.wheelYaw += 2D * ((this.maxSpeed * 2D - d) * this.turnRightModifier);
  784.  
  785. if (getSpeed() / this.maxSpeed > 0.5D)
  786. {
  787. this.rotationRoll -= 3D * (getSpeed() / this.maxSpeed - 0.20000000000000001D);
  788. }
  789.  
  790. break;
  791. case 3:
  792. this.wheelYaw -= 2D * ((this.maxSpeed * 2D - d) * this.turnLeftModifier);
  793.  
  794.  
  795. if (getSpeed() / this.maxSpeed > 0.20000000000000001D)
  796. {
  797. this.rotationRoll += 3D * (getSpeed() / this.maxSpeed - 0.20000000000000001D);
  798. }
  799.  
  800. break;
  801. }
  802.  
  803.  
  804. }
  805. }
  806.  
  807.  
  808.  
  809. public void pressKeyClient(int i)
  810. {
  811. SimCraft.network.initiateKeyUpdate(i);
  812. }
  813.  
  814. public void pressKeyClient()
  815. {
  816. if (this.riddenByEntity != null && this.riddenByEntity.ridingEntity != null && this.riddenByEntity.ridingEntity == this)
  817. {
  818. try
  819. {
  820. if (Class.forName("org.lwjgl.input.Keyboard") != null && Keyboard.isCreated())
  821. {
  822. if (Keyboard.isKeyDown(KeyConfig.KEY_ACC))
  823. {
  824. this.pressKeyClient(0);
  825. }
  826.  
  827. if (Keyboard.isKeyDown(KeyConfig.KEY_DEC))
  828. {
  829. this.pressKeyClient(1);
  830. }
  831.  
  832. if (Keyboard.isKeyDown(KeyConfig.KEY_TURNRIGHT))
  833. {
  834. this.pressKeyClient(2);
  835. }
  836.  
  837. if (Keyboard.isKeyDown(KeyConfig.KEY_TURNLEFT))
  838. {
  839. this.pressKeyClient(3);
  840. }
  841. }
  842. }
  843. catch (ClassNotFoundException var2)
  844. {
  845. ;
  846. }
  847. }
  848. }
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.  
  856.  
  857.  
  858. /** DataWatchers **/
  859.  
  860. /**
  861. * Sets the damage taken from the last hit.
  862. */
  863. public void setDamageTaken(float par1)
  864. {
  865. this.dataWatcher.updateObject(19, Float.valueOf(par1));
  866. }
  867.  
  868. /**
  869. * Gets the damage taken from the last hit.
  870. */
  871. public float getDamageTaken()
  872. {
  873. return this.dataWatcher.func_111145_d(19);
  874. }
  875.  
  876. /**
  877. * Sets the time to count down from since the last time entity was hit.
  878. */
  879. public void setTimeSinceHit(int par1)
  880. {
  881. this.dataWatcher.updateObject(17, Integer.valueOf(par1));
  882. }
  883.  
  884. /**
  885. * Gets the time since the last hit.
  886. */
  887. public int getTimeSinceHit()
  888. {
  889. return this.dataWatcher.getWatchableObjectInt(17);
  890. }
  891.  
  892. /**
  893. * Sets the forward direction of the entity.
  894. */
  895. public void setForwardDirection(int par1)
  896. {
  897. this.dataWatcher.updateObject(18, Integer.valueOf(par1));
  898. }
  899.  
  900. /**
  901. * Gets the forward direction of the entity.
  902. */
  903. public int getForwardDirection()
  904. {
  905. return this.dataWatcher.getWatchableObjectInt(18);
  906. }
  907.  
  908. @SideOnly(Side.CLIENT)
  909. public void func_70270_d(boolean par1)
  910. {
  911. this.field_70279_a = par1;
  912. }
  913.  
  914.  
  915.  
  916.  
  917.  
  918.  
  919.  
  920.  
  921.  
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.  
  929.  
  930.  
  931.  
  932.  
  933. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement