Advertisement
Guest User

Untitled

a guest
Jun 30th, 2020
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.87 KB | None | 0 0
  1. public void createDamageVec(EntityPlayer shooter) {
  2. if (CompilationFlag.SERVER) {
  3. NBTTagCompound weaponNBT = shooter.getHeldItem().getTagCompound();
  4. ItemWeapon gun = (ItemWeapon) shooter.getCurrentEquippedItem().getItem();
  5. if (shooter != null) {
  6. if (shooter.worldObj != null) {
  7. World w = shooter.worldObj;
  8. for (int k = 0; k < gun.getShots(); k++) {
  9. pointedEntity = null;
  10. double d0 = weaponNBT.getFloat("distance");
  11. if (d0 > 190) {
  12. d0 = 190;
  13. }
  14.  
  15. double d1 = d0;
  16.  
  17. Vec3 vec3 = Vec3.createVectorHelper(shooter.posX, shooter.posY, shooter.posZ);
  18. vec3.yCoord += shooter.getEyeHeight();
  19.  
  20. Vec3 vec31 = shooter.getLook(1);
  21.  
  22. vec31.xCoord += w.rand.nextGaussian() * (double) (w.rand.nextBoolean() ? -1 : 1)
  23. * 0.007499999832361937D * (double) weaponNBT.getFloat("spread") / 1.2F;
  24. vec31.yCoord += w.rand.nextGaussian() * (double) (w.rand.nextBoolean() ? -1 : 1)
  25. * 0.007499999832361937D * (double) weaponNBT.getFloat("spread") / 1.2F;
  26. vec31.zCoord += w.rand.nextGaussian() * (double) (w.rand.nextBoolean() ? -1 : 1)
  27. * 0.007499999832361937D * (double) weaponNBT.getFloat("spread") / 1.2F;
  28.  
  29. double xCord = vec31.xCoord;
  30. double yCord = vec31.yCoord - 0.12F / d1;
  31. double zCord = vec31.zCoord;
  32. // Minecraft.getMinecraft().effectRenderer.addEffect(new TracerFX(mc.thePlayer,
  33. // mc.theWorld, mc.thePlayer.posX, mc.thePlayer.posY, mc.thePlayer.posZ, xCord,
  34. // yCord, zCord));
  35.  
  36. ArrayList<MovingObjectPosition> blocklist = rayTrace(shooter, d0, 1F, xCord, yCord, zCord);
  37. for (int p = 0; p < blocklist.size(); p++) {
  38. MovingObjectPosition mop = blocklist.get(p);
  39. if (mop != null) {
  40. if (mop.typeOfHit.BLOCK != null) {
  41. Block block = w.getBlock(mop.blockX, mop.blockY, mop.blockZ);
  42. if (block == Blocks.iron_bars || block.getMaterial() == Material.glass
  43. || block.getMaterial() == Material.vine
  44. || block.getMaterial() == Material.plants
  45. || block.getMaterial() == Material.air
  46. || block.getMaterial() == Material.leaves
  47. || block.getMaterial() == Material.web) {
  48.  
  49. } else {
  50.  
  51. d0 = mop.hitVec.distanceTo(vec3);
  52.  
  53. // System.out.println(d1);
  54. // Minecraft.getMinecraft().effectRenderer.addEffect(new
  55. // BulletHoleFX(mc.theWorld, mop.hitVec.xCoord, mop.hitVec.yCoord,
  56. // mop.hitVec.zCoord, mop.sideHit));
  57. if (!(block instanceof InvizibleBlock) && !(block instanceof BlockCollider)
  58. && !(block instanceof BlockCollider3D)) {
  59. BatthertPacketHandler.INSTANCE.sendToAll(new PacketBulletHole(
  60. (float) mop.hitVec.xCoord, (float) mop.hitVec.yCoord,
  61. (float) mop.hitVec.zCoord, mop.sideHit));
  62.  
  63. if (k <= 1)
  64. BatthertPacketHandler.INSTANCE.sendToAll(new PacketSoundHit(
  65. (float) mop.hitVec.xCoord, (float) mop.hitVec.yCoord,
  66. (float) mop.hitVec.zCoord, mop.sideHit));
  67. }
  68. // Minecraft.getMinecraft().effectRenderer.addEffect(new
  69. // EntitySmokeFX(mc.theWorld, mop.hitVec.xCoord, mop.hitVec.yCoord,
  70. // mop.hitVec.zCoord, 0, 0, 0));
  71. // if(block.getMaterial() != Material.air)
  72. // System.out.println(block);
  73. break;
  74. }
  75. }
  76. }
  77. }
  78. Vec3 vec32 = vec3.addVector(vec31.xCoord * d0, vec31.yCoord * d0, vec31.zCoord * d0);
  79.  
  80. this.pointedEntity = null;
  81. Vec3 vec33 = null;
  82. float f1 = 1.0F;
  83. double d4 = d0;
  84.  
  85. //тут я сетаю всем игрокам бокс который у них был 20 тиков назад то есть секунду назад
  86. HashMap<EntityPlayer, AxisAlignedBB> boxes = new HashMap<>();
  87. for (Object o : w.playerEntities) {
  88. if (o instanceof EntityPlayer) {
  89. EntityPlayer player = (EntityPlayer) o;
  90. boxes.put(player, player.boundingBox.copy());
  91. AxisAlignedBB prevAABB = ExtendedPlayer.get(player).prevAABB;
  92. player.boundingBox.setBB(prevAABB);
  93.  
  94. }
  95. }
  96. List list = w.getEntitiesWithinAABBExcludingEntity(shooter,
  97. shooter.boundingBox.addCoord(vec31.xCoord * d0, vec31.yCoord * d0, vec31.zCoord * d0)
  98. .expand((double) f1, (double) f1, (double) f1));
  99.  
  100. double d2 = d4;
  101.  
  102. for (int i = list.size(); i > 0; --i) {
  103. Entity entity = (Entity) list.get(i - 1);
  104.  
  105. if (entity.canBeCollidedWith() && !entity.isDead) {
  106. float f2 = entity.getCollisionBorderSize();
  107.  
  108. AxisAlignedBB axisalignedbb = entity.boundingBox.expand((double) f2, (double) f2,
  109. (double) f2);
  110.  
  111. MovingObjectPosition movingobjectposition = axisalignedbb.calculateIntercept(vec3,
  112. vec32);
  113.  
  114. if (axisalignedbb.isVecInside(vec3)) {
  115. if (0.0D < d2 || d2 == 0.0D) {
  116. this.pointedEntity = entity;
  117. vec33 = movingobjectposition == null ? vec3 : movingobjectposition.hitVec;
  118. if (entity instanceof EntityLivingBase
  119. && ((EntityLivingBase) entity).getHealth() > 0) {
  120. this.pointedEntity = entity;
  121.  
  122. float headPosition = pointedEntity.getEyeHeight();
  123.  
  124. double hitPos = vec33.yCoord - pointedEntity.posY;
  125. if (pointedEntity.height < 1F) {
  126.  
  127. headPosition -= 1.4F;
  128. }
  129. // mc.thePlayer.addChatMessage(new ChatComponentText(""+headPosition));
  130. boolean headShot = ((hitPos - (headPosition - 0.45F))
  131. * (headPosition + 0.5F - hitPos) >= 0);
  132. pointedEntity.attackEntityFrom(DamageSource.causePlayerDamage(shooter),
  133. headShot ? gun.damage * 1.75F : gun.damage);
  134. if (shooter instanceof EntityPlayerMP)
  135. BatthertPacketHandler.INSTANCE.sendTo(new PacketHitmarker(headShot),
  136. (EntityPlayerMP) shooter);
  137. break;
  138. }
  139. d2 = 0D;
  140. break;
  141.  
  142. }
  143. } else if (movingobjectposition != null) {
  144. double d3 = vec3.distanceTo(movingobjectposition.hitVec);
  145.  
  146. // System.out.println(d3);
  147. if (d3 < d2 || d2 == 0.0D) {
  148. if (entity == shooter.ridingEntity && !entity.canRiderInteract()) {
  149. if (d2 == 0.0D) {
  150. this.pointedEntity = entity;
  151. vec33 = movingobjectposition.hitVec;
  152.  
  153. }
  154. } else if (!(entity instanceof EntityEnderCrystal)) {
  155. if (entity instanceof EntityLivingBase
  156. && ((EntityLivingBase) entity).getHealth() > 0) {
  157. this.pointedEntity = entity;
  158.  
  159. float headPosition = pointedEntity.getEyeHeight();
  160.  
  161. vec33 = movingobjectposition.hitVec;
  162.  
  163. d2 = d3;
  164. double hitPos = vec33.yCoord - pointedEntity.posY;
  165. if (pointedEntity.height < 1F) {
  166.  
  167. headPosition -= 1.4F;
  168. }
  169. // mc.thePlayer.addChatMessage(new ChatComponentText(""+headPosition));
  170. boolean headShot = ((hitPos - (headPosition - 0.45F))
  171. * (headPosition + 0.5F - hitPos) >= 0);
  172. pointedEntity.attackEntityFrom(DamageSource.causePlayerDamage(shooter),
  173. headShot ? gun.damage * 1.75F : gun.damage);
  174. if (shooter instanceof EntityPlayerMP)
  175. BatthertPacketHandler.INSTANCE.sendTo(new PacketHitmarker(headShot),
  176. (EntityPlayerMP) shooter);
  177.  
  178. break;
  179. }
  180.  
  181. }
  182. }
  183. }
  184.  
  185. }
  186. }
  187.  
  188. //здесь возвращаю его обратно
  189. for (Object o : w.playerEntities) {
  190. if (o instanceof EntityPlayer) {
  191. EntityPlayer player = (EntityPlayer) o;
  192. if (boxes.containsKey(player)) {
  193. player.boundingBox.setBB(boxes.get(player));
  194. }
  195. }
  196. }
  197.  
  198. }
  199. }
  200. }
  201. }
  202. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement