Guest User

Untitled

a guest
Dec 9th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.50 KB | None | 0 0
  1. package minecraftwero.common; //CHANGE THIS
  2. import java.util.List;
  3. import java.util.Random;
  4. import net.minecraft.client.Minecraft;
  5. import net.minecraft.src.AxisAlignedBB;
  6. import net.minecraft.src.Block;
  7. import net.minecraft.src.Entity;
  8. import net.minecraft.src.EntityDamageSource;
  9. import net.minecraft.src.EntityLiving;
  10. import net.minecraft.src.EntityPlayer;
  11. import net.minecraft.src.Item;
  12. import net.minecraft.src.ItemStack;
  13. import net.minecraft.src.MathHelper;
  14. import net.minecraft.src.MovingObjectPosition;
  15. import net.minecraft.src.NBTTagCompound;
  16. import net.minecraft.src.Vec3;
  17. import net.minecraft.src.Vec3Pool;
  18. import net.minecraft.src.World;
  19. public class EntityBullet extends Entity
  20. {
  21. private int xTile;
  22. private int yTile;
  23. private int zTile;
  24. private int inTile;
  25. private boolean inGround;
  26. public int arrowShake;
  27. public EntityLiving shootingEntity;
  28. private int timeTillDeath;
  29. private int flyTime;
  30. private EntityPlayer owner;
  31. private int damage;
  32. private final float size = 1F;
  33.  
  34. public EntityBullet(World world)
  35. {
  36. super(world);
  37. xTile = -1;
  38. yTile = -1;
  39. zTile = -1;
  40. inTile = 0;
  41. inGround = false;
  42. arrowShake = 0;
  43. flyTime = 0;
  44. setSize(size, size);
  45. }
  46. public EntityBullet(World world, double d, double d1, double d2,
  47. double d3, double d4, double d5, EntityPlayer entityplayer)
  48. {
  49. super(world);
  50. xTile = -1;
  51. yTile = -1;
  52. zTile = -1;
  53. inTile = 0;
  54. inGround = false;
  55. arrowShake = 0;
  56. flyTime = 0;
  57. setSize(size, size);
  58. setPosition(d, d1, d2);
  59. yOffset = 0.0F;
  60. setVelocity(d3, d4, d5);
  61. owner = entityplayer;
  62. }
  63. public EntityBullet(World world, double d, double d1, double d2)
  64. {
  65. super(world);
  66. xTile = -1;
  67. yTile = -1;
  68. zTile = -1;
  69. inTile = 0;
  70. inGround = false;
  71. arrowShake = 0;
  72. flyTime = 0;
  73. setSize(size, size);
  74. setPosition(d, d1, d2);
  75. yOffset = 0.0F;
  76. }
  77. public EntityBullet(World world, EntityLiving entityliving, int damage, int accuracy)
  78. {
  79. super(world);
  80. this.damage = damage;
  81. xTile = -1;
  82. yTile = -1;
  83. zTile = -1;
  84. inTile = 0;
  85. inGround = false;
  86. arrowShake = 0;
  87. flyTime = 0;
  88. shootingEntity = entityliving;
  89. setSize(size, size);
  90. setLocationAndAngles(entityliving.posX, entityliving.posY + (double)entityliving.getEyeHeight(), entityliving.posZ, entityliving.rotationYaw, entityliving.rotationPitch);
  91. posX -= MathHelper.cos((rotationYaw / 180F) * 3.141593F) * 0.16F;
  92. posY -= 0.10000000149011612D;
  93. posZ -= MathHelper.sin((rotationYaw / 180F) * 3.141593F) * 0.16F;
  94. setPosition(posX, posY, posZ);
  95. yOffset = 0.0F;
  96. motionX = 1000F * -MathHelper.sin((rotationYaw / 180F) * 3.141593F) * MathHelper.cos((rotationPitch / 180F) * 3.141593F);
  97. motionZ = 1000F * MathHelper.cos((rotationYaw / 180F) * 3.141593F) * MathHelper.cos((rotationPitch / 180F) * 3.141593F);
  98. motionY = 1000F * -MathHelper.sin((rotationPitch / 180F) * 3.141593F);
  99. setArrowHeading(motionX, motionY, motionZ, 200.0F, 1.5F, accuracy);
  100. }
  101. protected void entityInit()
  102. {
  103. }
  104. public void setArrowHeading(double d, double d1, double d2, float f,
  105. float f1, int i)
  106. {
  107. float f2 = MathHelper.sqrt_double(d * d + d1 * d1 + d2 * d2);
  108. d /= f2;
  109. d1 /= f2;
  110. d2 /= f2;
  111. d += rand.nextGaussian() * 0.0034999998323619365D * (double)f1 * (double)i / 5;
  112. d1 += rand.nextGaussian() * 0.0034999998323619365D * (double)f1 * (double)i / 5;
  113. d2 += rand.nextGaussian() * 0.0034999998323619365D * (double)f1 * (double)i / 5;
  114. d *= f;
  115. d1 *= f;
  116. d2 *= f;
  117. motionX = d;
  118. motionY = d1;
  119. motionZ = d2;
  120. float f3 = MathHelper.sqrt_double(d * d + d2 * d2);
  121. prevRotationYaw = rotationYaw = (float)((Math.atan2(d, d2) * 180D) / 3.1415927410125732D);
  122. prevRotationPitch = rotationPitch = (float)((Math.atan2(d1, f3) * 180D) / 3.1415927410125732D);
  123. timeTillDeath = 0;
  124. }
  125. public void setVelocity(double d, double d1, double d2)
  126. {
  127. motionX = d;
  128. motionY = d1;
  129. motionZ = d2;
  130. if (prevRotationPitch == 0.0F && prevRotationYaw == 0.0F)
  131. {
  132. float f = MathHelper.sqrt_double(d * d + d2 * d2);
  133. prevRotationYaw = rotationYaw = (float)((Math.atan2(d, d2) * 180D) / 3.1415927410125732D);
  134. prevRotationPitch = rotationPitch = (float)((Math.atan2(d1, f) * 180D) / 3.1415927410125732D);
  135. }
  136. }
  137. public void onUpdate()
  138. {
  139. super.onUpdate();
  140. if (flyTime > 1000)
  141. {
  142. setDead();
  143. }
  144. if (prevRotationPitch == 0.0F && prevRotationYaw == 0.0F)
  145. {
  146. float f = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ);
  147. prevRotationYaw = rotationYaw = (float)((Math.atan2(motionX, motionZ) * 180D) / 3.1415927410125732D);
  148. prevRotationPitch = rotationPitch = (float)((Math.atan2(motionY, f) * 180D) / 3.1415927410125732D);
  149. }
  150. if (arrowShake > 0)
  151. {
  152. arrowShake--;
  153. }
  154. if (inGround)
  155. {
  156. int i = worldObj.getBlockId(xTile, yTile, zTile);
  157. if (i != inTile)
  158. {
  159. inGround = false;
  160. motionX *= rand.nextFloat() * 0.2F;
  161. motionY *= rand.nextFloat() * 0.2F;
  162. motionZ *= rand.nextFloat() * 0.2F;
  163. timeTillDeath = 0;
  164. flyTime = 0;
  165. }
  166. else
  167. {
  168. timeTillDeath++;
  169. if (timeTillDeath == 1200)
  170. {
  171. setDead();
  172. }
  173. return;
  174. }
  175. }
  176. else
  177. {
  178. flyTime++;
  179. }
  180. Vec3 vec3d = Vec3.getVec3Pool().getVecFromPool(posX, posY, posZ);
  181. Vec3 vec3d1 = Vec3.getVec3Pool().getVecFromPool(posX + motionX, posY + motionY, posZ + motionZ);
  182. MovingObjectPosition movingobjectposition = worldObj.rayTraceBlocks(vec3d, vec3d1);
  183. vec3d = Vec3.getVec3Pool().getVecFromPool(posX, posY, posZ);
  184. vec3d1 = Vec3.getVec3Pool().getVecFromPool(posX + motionX, posY + motionY, posZ + motionZ);
  185. if (movingobjectposition != null)
  186. {
  187. vec3d1 = Vec3.getVec3Pool().getVecFromPool(movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord);
  188. }
  189. Entity entity = null;
  190. List list = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.addCoord(motionX, motionY, motionZ).expand(1.0D, 1.0D, 1.0D));
  191. double d = 0.0D;
  192. for (int j = 0; j < list.size(); j++)
  193. {
  194. Entity entity1 = (Entity)list.get(j);
  195. if (!entity1.canBeCollidedWith() || entity1 == shootingEntity && flyTime < 5)
  196. {
  197. continue;
  198. }
  199. float f4 = 0.3F;
  200. AxisAlignedBB axisalignedbb = entity1.boundingBox.expand(f4, f4, f4);
  201. MovingObjectPosition movingobjectposition1 = axisalignedbb.calculateIntercept(vec3d, vec3d1);
  202. if (movingobjectposition1 == null)
  203. {
  204. continue;
  205. }
  206. double d1 = vec3d.distanceTo(movingobjectposition1.hitVec);
  207. if (d1 < d || d == 0.0D)
  208. {
  209. entity = entity1;
  210. d = d1;
  211. }
  212. }
  213. if (entity != null)
  214. {
  215. movingobjectposition = new MovingObjectPosition(entity);
  216. }
  217. if (movingobjectposition != null)
  218. {
  219. if (movingobjectposition.entityHit != null)
  220. {
  221. if (movingobjectposition.entityHit.attackEntityFrom(new EntityDamageSource("player", owner), damage))
  222. {
  223. worldObj.playSoundAtEntity(this, "BulletHit", 1.0F, 1.2F / (rand.nextFloat() * 0.2F + 0.9F));
  224. setDead();
  225. }
  226. else
  227. {
  228. motionX *= 0.10000000149011612D;
  229. motionY *= 0.10000000149011612D;
  230. motionZ *= 0.10000000149011612D;
  231. flyTime = 0;
  232. setDead();
  233. }
  234. }
  235. else
  236. {
  237. xTile = movingobjectposition.blockX;
  238. yTile = movingobjectposition.blockY;
  239. zTile = movingobjectposition.blockZ;
  240. inTile = worldObj.getBlockId(xTile, yTile, zTile);
  241. if (inTile == Block.glass.blockID || inTile == Block.glowStone.blockID || inTile == Block.leaves.blockID)
  242. {
  243. Block block = Block.blocksList[inTile];
  244. //ModLoader.getMinecraftInstance().sndManager.playSound(block.stepSound.stepSoundDir(), (float)xTile + 0.5F, (float)yTile + 0.5F, (float)zTile + 0.5F, (block.stepSound.getVolume() + 1.0F) / 2.0F, block.stepSound.getPitch() * 0.8F);
  245. worldObj.setBlockWithNotify(xTile, yTile, zTile, 0);
  246. }
  247. else
  248. {
  249. motionX = (float)(movingobjectposition.hitVec.xCoord - posX);
  250. motionY = (float)(movingobjectposition.hitVec.yCoord - posY);
  251. motionZ = (float)(movingobjectposition.hitVec.zCoord - posZ);
  252. float f1 = MathHelper.sqrt_double(motionX * motionX + motionY * motionY + motionZ * motionZ);
  253. posX -= (motionX / (double)f1) * 0.05000000074505806D;
  254. posY -= (motionY / (double)f1) * 0.05000000074505806D;
  255. posZ -= (motionZ / (double)f1) * 0.05000000074505806D;
  256. worldObj.playSoundAtEntity(this, "Bullet2Hit", 1.0F, 1.2F / (rand.nextFloat() * 0.2F + 0.9F));
  257. setDead();
  258. }
  259. }
  260. }
  261. posX += motionX * 3D;
  262. posY += motionY * 3D;
  263. posZ += motionZ * 3D;
  264. float f2 = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ);
  265. rotationYaw = (float)((Math.atan2(motionX, motionZ) * 180D) / 3.1415927410125732D);
  266. for (rotationPitch = (float)((Math.atan2(motionY, f2) * 180D) / 3.1415927410125732D); rotationPitch - prevRotationPitch < -180F; prevRotationPitch -= 360F) { }
  267. for (; rotationPitch - prevRotationPitch >= 180F; prevRotationPitch += 360F) { }
  268. for (; rotationYaw - prevRotationYaw < -180F; prevRotationYaw -= 360F) { }
  269. for (; rotationYaw - prevRotationYaw >= 180F; prevRotationYaw += 360F) { }
  270. rotationPitch = prevRotationPitch + (rotationPitch - prevRotationPitch) * 0.2F;
  271. rotationYaw = prevRotationYaw + (rotationYaw - prevRotationYaw) * 0.2F;
  272. float f3 = 0.99F;
  273. float f5 = 0.03F;
  274. if (handleWaterMovement())
  275. {
  276. for (int k = 0; k < 4; k++)
  277. {
  278. float f6 = 0.25F;
  279. worldObj.spawnParticle("bubble", posX - motionX * (double)f6, posY - motionY * (double)f6, posZ - motionZ * (double)f6, motionX, motionY, motionZ);
  280. }
  281. f3 = 0.8F;
  282. }
  283. motionX *= f3;
  284. motionY *= f3;
  285. motionZ *= f3;
  286. setPosition(posX, posY, posZ);
  287. }
  288. public void writeEntityToNBT(NBTTagCompound nbttagcompound)
  289. {
  290. nbttagcompound.setShort("xTile", (short)xTile);
  291. nbttagcompound.setShort("yTile", (short)yTile);
  292. nbttagcompound.setShort("zTile", (short)zTile);
  293. nbttagcompound.setByte("inTile", (byte)inTile);
  294. nbttagcompound.setByte("shake", (byte)arrowShake);
  295. nbttagcompound.setByte("inGround", (byte)(inGround ? 1 : 0));
  296. }
  297. public void readEntityFromNBT(NBTTagCompound nbttagcompound)
  298. {
  299. xTile = nbttagcompound.getShort("xTile");
  300. yTile = nbttagcompound.getShort("yTile");
  301. zTile = nbttagcompound.getShort("zTile");
  302. inTile = nbttagcompound.getByte("inTile") & 0xff;
  303. arrowShake = nbttagcompound.getByte("shake") & 0xff;
  304. inGround = nbttagcompound.getByte("inGround") == 1;
  305. }
  306. public void onCollideWithPlayer(EntityPlayer entityplayer)
  307. {
  308. if (worldObj.isRemote)
  309. {
  310. return;
  311. }
  312. if (inGround && shootingEntity == entityplayer && arrowShake <= 0 && entityplayer.inventory.addItemStackToInventory(new ItemStack(Item.arrow, 1)))
  313. {
  314. worldObj.playSoundAtEntity(this, "random.pop", 0.2F, ((rand.nextFloat() - rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
  315. entityplayer.onItemPickup(this, 1);
  316. setDead();
  317. }
  318. }
  319.  
  320.  
  321. public float getShadowSize()
  322. {
  323. return 0.0F;
  324. }
  325. }
Add Comment
Please, Sign In to add comment