Advertisement
Guest User

Untitled

a guest
Sep 4th, 2015
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.50 KB | None | 0 0
  1. package net.minecraft.src;
  2.  
  3. import java.util.List;
  4. import java.util.Random;
  5. import net.minecraft.client.Minecraft;
  6.  
  7. public abstract class SdkEntityBullet extends Entity
  8. {
  9. protected int xTile;
  10. protected int yTile;
  11. protected int zTile;
  12. protected int inTile;
  13. protected boolean inGround;
  14. public Entity owner;
  15. protected int timeInTile;
  16. protected int timeInAir;
  17. protected int damage;
  18. protected float headshotMultiplier;
  19. protected boolean serverSpawned;
  20. protected String firingSound;
  21. protected float soundRangeFactor;
  22. protected boolean serverSoundPlayed;
  23.  
  24. public SdkEntityBullet(World world)
  25. {
  26. super(world);
  27. soundRangeFactor = 8F;
  28. serverSoundPlayed = false;
  29. xTile = -1;
  30. yTile = -1;
  31. zTile = -1;
  32. inTile = 0;
  33. inGround = false;
  34. timeInAir = 0;
  35. setSize(0.0625F, 0.03125F);
  36. }
  37.  
  38. public SdkEntityBullet(World world, double d, double d1, double d2)
  39. {
  40. this(world);
  41. setPosition(d, d1, d2);
  42. yOffset = 0.0F;
  43. serverSpawned = true;
  44. }
  45.  
  46. public abstract void playServerSound(World world);
  47.  
  48. public SdkEntityBullet(World world, Entity entity, SdkItemGun sdkitemgun, float f, float f1, float f2, float f3, float f4)
  49. {
  50. this(world);
  51. owner = entity;
  52. damage = sdkitemgun.damage;
  53. headshotMultiplier = sdkitemgun.headshotMultiplier;
  54. float f5 = entity.rotationYaw;
  55. float f6 = f5 * 0.01745329F;
  56. double d = f * MathHelper.cos(f6) - f2 * MathHelper.sin(f6);
  57. double d1 = f * MathHelper.sin(f6) + f2 * MathHelper.cos(f6);
  58. setLocationAndAngles(entity.posX + d, entity.posY + (double)entity.getEyeHeight() + (double)f1, entity.posZ + d1, entity.rotationYaw + f3, entity.rotationPitch + f4);
  59. posX -= MathHelper.cos((rotationYaw / 180F) * (float)Math.PI) * 0.16F;
  60. posY -= 0.1D;
  61. posZ -= MathHelper.sin((rotationYaw / 180F) * (float)Math.PI) * 0.16F;
  62. setPosition(posX, posY, posZ);
  63. yOffset = 0.0F;
  64. float f7 = sdkitemgun.spread;
  65.  
  66. if (entity instanceof EntityLiving)
  67. {
  68. if (entity instanceof EntityPlayer)
  69. {
  70. float f8 = sdkitemgun.recoil / (float)sdkitemgun.useDelay;
  71. float f9 = f8 / 0.1F;
  72.  
  73. if (f9 > 0.0F)
  74. {
  75. f7 = (float)((double)f7 * (1.0D + mod_SdkGuns.currentRecoilV / (double)f9));
  76. }
  77. }
  78.  
  79. boolean flag = Math.abs(entity.motionX) > 0.1D || Math.abs(entity.motionY) > 0.1D || Math.abs(entity.motionZ) > 0.1D;
  80.  
  81. if (flag)
  82. {
  83. f7 *= 2.0F;
  84.  
  85. if (sdkitemgun instanceof SdkItemGunMinigun)
  86. {
  87. f7 *= 2.0F;
  88. }
  89. }
  90.  
  91. if (!entity.onGround)
  92. {
  93. f7 *= 2.0F;
  94.  
  95. if (sdkitemgun instanceof SdkItemGunMinigun)
  96. {
  97. f7 *= 2.0F;
  98. }
  99. }
  100.  
  101. if ((entity instanceof EntityPlayer) && (sdkitemgun instanceof SdkItemGunSniper))
  102. {
  103. EntityPlayer entityplayer = (EntityPlayer)entity;
  104.  
  105. if (flag)
  106. {
  107. f7 = (float)((double)f7 + 0.25D);
  108. }
  109.  
  110. if (!entity.onGround)
  111. {
  112. f7 = (float)((double)f7 + 0.25D);
  113. }
  114.  
  115. if (!entityplayer.isSneaking())
  116. {
  117. f7 = (float)((double)f7 + 0.25D);
  118. }
  119.  
  120. if (!mod_SdkGuns.getSniperZoomedIn())
  121. {
  122. f7 = 8F;
  123. }
  124. }
  125. }
  126.  
  127. if (entity.riddenByEntity != null && (entity instanceof EntityPlayer))
  128. {
  129. owner = entity.riddenByEntity;
  130. }
  131.  
  132. motionX = -MathHelper.sin((rotationYaw / 180F) * (float)Math.PI) * MathHelper.cos((rotationPitch / 180F) * (float)Math.PI);
  133. motionZ = MathHelper.cos((rotationYaw / 180F) * (float)Math.PI) * MathHelper.cos((rotationPitch / 180F) * (float)Math.PI);
  134. motionY = -MathHelper.sin((rotationPitch / 180F) * (float)Math.PI);
  135. setBulletHeading(motionX, motionY, motionZ, sdkitemgun.muzzleVelocity, f7 / 2.0F);
  136. double d2 = 0.0D;
  137. double d3 = 0.0D;
  138. double d4 = 0.0D;
  139.  
  140. if (entity.ridingEntity != null)
  141. {
  142. d2 = entity.ridingEntity.motionX;
  143. d3 = entity.ridingEntity.onGround ? 0.0D : entity.ridingEntity.motionY;
  144. d4 = entity.ridingEntity.motionZ;
  145. }
  146. else if (entity.riddenByEntity != null)
  147. {
  148. d2 = entity.motionX;
  149. d3 = entity.onGround ? 0.0D : entity.motionY;
  150. d4 = entity.motionZ;
  151. }
  152.  
  153. motionX += d2;
  154. motionY += d3;
  155. motionZ += d4;
  156. }
  157.  
  158. protected void entityInit()
  159. {
  160. }
  161.  
  162. public void setBulletHeading(double d, double d1, double d2, float f, float f1)
  163. {
  164. float f2 = MathHelper.sqrt_double(d * d + d1 * d1 + d2 * d2);
  165. d /= f2;
  166. d1 /= f2;
  167. d2 /= f2;
  168. d += rand.nextGaussian() * 0.0075D * (double)f1;
  169. d1 += rand.nextGaussian() * 0.0075D * (double)f1;
  170. d2 += rand.nextGaussian() * 0.0075D * (double)f1;
  171. d *= f;
  172. d1 *= f;
  173. d2 *= f;
  174. motionX = d;
  175. motionY = d1;
  176. motionZ = d2;
  177. float f3 = MathHelper.sqrt_double(d * d + d2 * d2);
  178. prevRotationYaw = rotationYaw = (float)((Math.atan2(d, d2) * 180D) / Math.PI);
  179. prevRotationPitch = rotationPitch = (float)((Math.atan2(d1, f3) * 180D) / Math.PI);
  180. timeInTile = 0;
  181. }
  182.  
  183. /**
  184. * Checks if the entity is in range to render by using the past in distance and comparing it to its average edge
  185. * length * 64 * renderDistanceWeight Args: distance
  186. */
  187. public boolean isInRangeToRenderDist(double d)
  188. {
  189. return true;
  190. }
  191.  
  192. /**
  193. * Called to update the entity's position/logic.
  194. */
  195. public void onUpdate()
  196. {
  197. super.onUpdate();
  198.  
  199. if (serverSpawned && !serverSoundPlayed && owner != ModLoader.getMinecraftInstance().thePlayer)
  200. {
  201. playServerSound(worldObj);
  202. serverSoundPlayed = true;
  203. }
  204.  
  205. if (timeInAir == 200)
  206. {
  207. setEntityDead();
  208. }
  209.  
  210. if (prevRotationPitch == 0.0F && prevRotationYaw == 0.0F)
  211. {
  212. float f = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ);
  213. prevRotationYaw = rotationYaw = (float)((Math.atan2(motionX, motionZ) * 180D) / Math.PI);
  214. prevRotationPitch = rotationPitch = (float)((Math.atan2(motionY, f) * 180D) / Math.PI);
  215. }
  216.  
  217. if (inGround)
  218. {
  219. int i = worldObj.getBlockId(xTile, yTile, zTile);
  220.  
  221. if (i != inTile)
  222. {
  223. inGround = false;
  224. motionX *= rand.nextFloat() * 0.2F;
  225. motionY *= rand.nextFloat() * 0.2F;
  226. motionZ *= rand.nextFloat() * 0.2F;
  227. timeInTile = 0;
  228. timeInAir = 0;
  229. }
  230. else
  231. {
  232. timeInTile++;
  233.  
  234. if (timeInTile == 200)
  235. {
  236. setEntityDead();
  237. }
  238.  
  239. return;
  240. }
  241. }
  242. else
  243. {
  244. timeInAir++;
  245. }
  246.  
  247. Vec3D vec3d = Vec3D.createVector(posX, posY, posZ);
  248. Vec3D vec3d1 = Vec3D.createVector(posX + motionX, posY + motionY, posZ + motionZ);
  249. MovingObjectPosition movingobjectposition = worldObj.rayTraceBlocks(vec3d, vec3d1);
  250. vec3d = Vec3D.createVector(posX, posY, posZ);
  251. vec3d1 = Vec3D.createVector(posX + motionX, posY + motionY, posZ + motionZ);
  252.  
  253. if (movingobjectposition != null)
  254. {
  255. vec3d1 = Vec3D.createVector(movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord);
  256. }
  257.  
  258. Entity entity = null;
  259. List list = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.addCoord(motionX, motionY, motionZ).expand(1.0D, 1.0D, 1.0D));
  260. double d = 0.0D;
  261. Vec3D vec3d2 = null;
  262.  
  263. for (int j = 0; j < list.size(); j++)
  264. {
  265. Entity entity1 = (Entity)list.get(j);
  266.  
  267. if (!entity1.canBeCollidedWith() || (entity1 == owner || owner != null && entity1 == owner.ridingEntity || owner != null && entity1 == owner.riddenByEntity) && timeInAir < 5 || serverSpawned)
  268. {
  269. continue;
  270. }
  271.  
  272. float f4 = 0.3F;
  273. AxisAlignedBB axisalignedbb = entity1.boundingBox.expand(f4, f4, f4);
  274. MovingObjectPosition movingobjectposition1 = axisalignedbb.calculateIntercept(vec3d, vec3d1);
  275.  
  276. if (movingobjectposition1 == null)
  277. {
  278. continue;
  279. }
  280.  
  281. double d1 = vec3d.distanceTo(movingobjectposition1.hitVec);
  282.  
  283. if (d1 < d || d == 0.0D)
  284. {
  285. vec3d2 = movingobjectposition1.hitVec;
  286. entity = entity1;
  287. d = d1;
  288. }
  289. }
  290.  
  291. if (entity != null)
  292. {
  293. movingobjectposition = new MovingObjectPosition(entity);
  294. }
  295.  
  296. if (movingobjectposition != null)
  297. {
  298. int k = worldObj.getBlockId(movingobjectposition.blockX, movingobjectposition.blockY, movingobjectposition.blockZ);
  299.  
  300. if (movingobjectposition.entityHit != null || k != Block.tallGrass.blockID)
  301. {
  302. if (movingobjectposition.entityHit != null)
  303. {
  304. int l = damage;
  305.  
  306. if ((owner instanceof IMob) && (movingobjectposition.entityHit instanceof EntityPlayer))
  307. {
  308. if (worldObj.difficultySetting == 0)
  309. {
  310. l = 0;
  311. }
  312.  
  313. if (worldObj.difficultySetting == 1)
  314. {
  315. l = l / 3 + 1;
  316. }
  317.  
  318. if (worldObj.difficultySetting == 3)
  319. {
  320. l = (l * 3) / 2;
  321. }
  322. }
  323.  
  324. l = checkHeadshot(movingobjectposition, vec3d2, l);
  325.  
  326. if (movingobjectposition.entityHit instanceof EntityLiving)
  327. {
  328. SdkTools.attackEntityIgnoreDelay((EntityLiving)movingobjectposition.entityHit, DamageSource.causeThrownDamage(this, owner), l);
  329. }
  330. else
  331. {
  332. movingobjectposition.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, owner), l);
  333. }
  334. }
  335. else
  336. {
  337. xTile = movingobjectposition.blockX;
  338. yTile = movingobjectposition.blockY;
  339. zTile = movingobjectposition.blockZ;
  340. inTile = k;
  341. motionX = (float)(movingobjectposition.hitVec.xCoord - posX);
  342. motionY = (float)(movingobjectposition.hitVec.yCoord - posY);
  343. motionZ = (float)(movingobjectposition.hitVec.zCoord - posZ);
  344. float f2 = MathHelper.sqrt_double(motionX * motionX + motionY * motionY + motionZ * motionZ);
  345. posX -= (motionX / (double)f2) * 0.05D;
  346. posY -= (motionY / (double)f2) * 0.05D;
  347. posZ -= (motionZ / (double)f2) * 0.05D;
  348. inGround = true;
  349.  
  350. if (mod_SdkGuns.bulletsDestroyGlass && (inTile == Block.glass.blockID || inTile == Block.thinGlass.blockID))
  351. {
  352. Block block;
  353.  
  354. if (inTile == Block.glass.blockID)
  355. {
  356. block = Block.glass;
  357. }
  358. else
  359. {
  360. block = Block.thinGlass;
  361. }
  362.  
  363. SdkTools.minecraft.effectRenderer.addBlockDestroyEffects(xTile, yTile, zTile, block.blockID & 0xff, Block.glass.blockID >> 8 & 0xff);
  364. SdkTools.minecraft.sndManager.playSound(block.stepSound.getBreakSound(), (float)xTile + 0.5F, (float)yTile + 0.5F, (float)zTile + 0.5F, (block.stepSound.getVolume() + 1.0F) / 2.0F, block.stepSound.getPitch() * 0.8F);
  365. worldObj.setBlockWithNotify(xTile, yTile, zTile, 0);
  366. block.onBlockDestroyedByPlayer(worldObj, xTile, yTile, zTile, worldObj.getBlockMetadata(xTile, yTile, zTile));
  367. }
  368. }
  369.  
  370. worldObj.playSoundAtEntity(this, "sdk.impact", 0.2F, 1.0F / (rand.nextFloat() * 0.1F + 0.95F));
  371. setEntityDead();
  372. }
  373. }
  374.  
  375. posX += motionX;
  376. posY += motionY;
  377. posZ += motionZ;
  378. float f1 = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ);
  379. rotationYaw = (float)((Math.atan2(motionX, motionZ) * 180D) / Math.PI);
  380.  
  381. for (rotationPitch = (float)((Math.atan2(motionY, f1) * 180D) / Math.PI); rotationPitch - prevRotationPitch < -180F; prevRotationPitch -= 360F) { }
  382.  
  383. for (; rotationPitch - prevRotationPitch >= 180F; prevRotationPitch += 360F) { }
  384.  
  385. for (; rotationYaw - prevRotationYaw < -180F; prevRotationYaw -= 360F) { }
  386.  
  387. for (; rotationYaw - prevRotationYaw >= 180F; prevRotationYaw += 360F) { }
  388.  
  389. rotationPitch = prevRotationPitch + (rotationPitch - prevRotationPitch) * 0.2F;
  390. rotationYaw = prevRotationYaw + (rotationYaw - prevRotationYaw) * 0.2F;
  391. float f3 = 1.0F;
  392. float f5 = 0.0F;
  393.  
  394. if (handleWaterMovement())
  395. {
  396. for (int i1 = 0; i1 < 4; i1++)
  397. {
  398. float f6 = 0.25F;
  399. worldObj.spawnParticle("bubble", posX - motionX * (double)f6, posY - motionY * (double)f6, posZ - motionZ * (double)f6, motionX, motionY, motionZ);
  400. }
  401.  
  402. f3 = 0.8F;
  403. f5 = 0.03F;
  404. }
  405.  
  406. motionX *= f3;
  407. motionY *= f3;
  408. motionZ *= f3;
  409. motionY -= f5;
  410. setPosition(posX, posY, posZ);
  411. }
  412.  
  413. protected int checkHeadshot(MovingObjectPosition movingobjectposition, Vec3D vec3d, int i)
  414. {
  415. Render render = RenderManager.instance.getEntityClassRenderObject(movingobjectposition.entityHit.getClass());
  416.  
  417. if (render instanceof RenderLiving)
  418. {
  419. RenderLiving renderliving = (RenderLiving)render;
  420. float f = 0.0F;
  421.  
  422. if (renderliving.mainModel instanceof ModelBiped)
  423. {
  424. ModelBiped modelbiped = (ModelBiped)renderliving.mainModel;
  425. ModelBox modelbox = (ModelBox)modelbiped.bipedHead.cubeList.get(0);
  426. ModelBox modelbox2 = (ModelBox)modelbiped.bipedRightLeg.cubeList.get(0);
  427. f = (modelbox.posY2 - modelbox.posY1) / ((modelbox2.posY2 + modelbiped.bipedRightLeg.rotationPointY) - (modelbox.posY1 + modelbiped.bipedHead.rotationPointY));
  428. }
  429. else if (renderliving.mainModel instanceof ModelCreeper)
  430. {
  431. ModelCreeper modelcreeper = (ModelCreeper)renderliving.mainModel;
  432. ModelBox modelbox1 = (ModelBox)modelcreeper.head.cubeList.get(0);
  433. ModelBox modelbox3 = (ModelBox)modelcreeper.leg1.cubeList.get(0);
  434. f = (modelbox1.posY2 - modelbox1.posY1) / ((modelbox3.posY2 + modelcreeper.leg1.rotationPointY) - (modelbox1.posY1 + modelcreeper.head.rotationPointY));
  435. }
  436.  
  437. if (f > 0.0F)
  438. {
  439. double d = movingobjectposition.entityHit.boundingBox.maxY;
  440. double d1 = movingobjectposition.entityHit.boundingBox.minY;
  441. double d2 = d - d1;
  442.  
  443. if (vec3d.yCoord > d - d2 * (double)f)
  444. {
  445. i = Math.round((float)i * headshotMultiplier);
  446. }
  447. }
  448. }
  449.  
  450. return i;
  451. }
  452.  
  453. /**
  454. * (abstract) Protected helper method to write subclass entity data to NBT.
  455. */
  456. public void writeEntityToNBT(NBTTagCompound nbttagcompound)
  457. {
  458. nbttagcompound.setShort("xTile", (short)xTile);
  459. nbttagcompound.setShort("yTile", (short)yTile);
  460. nbttagcompound.setShort("zTile", (short)zTile);
  461. nbttagcompound.setByte("inTile", (byte)inTile);
  462. nbttagcompound.setByte("inGround", (byte)(inGround ? 1 : 0));
  463. }
  464.  
  465. /**
  466. * (abstract) Protected helper method to read subclass entity data from NBT.
  467. */
  468. public void readEntityFromNBT(NBTTagCompound nbttagcompound)
  469. {
  470. xTile = nbttagcompound.getShort("xTile");
  471. yTile = nbttagcompound.getShort("yTile");
  472. zTile = nbttagcompound.getShort("zTile");
  473. inTile = nbttagcompound.getByte("inTile") & 0xff;
  474. inGround = nbttagcompound.getByte("inGround") == 1;
  475. }
  476.  
  477. public float getShadowSize()
  478. {
  479. return 0.0F;
  480. }
  481.  
  482. /**
  483. * Will get destroyed next tick
  484. */
  485. public void setEntityDead()
  486. {
  487. super.setEntityDead();
  488. owner = null;
  489. }
  490. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement