PlasmaVNGaming

Untitled

Aug 28th, 2021
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.00 KB | None | 0 0
  1. private Function<Double, Double> createModifier(String tag, Function<Double, Double> function) {
  2. return new Function<Double, Double>() {
  3.  
  4. @Override
  5. public Double apply(@org.jetbrains.annotations.Nullable Double input) {
  6. Double value = function.apply(input);
  7. if (value.isNaN()) {
  8. Bukkit.getLogger().warning("NaN in " + tag + " damage modifier function.");
  9. }
  10. if (value.isInfinite()) {
  11. Bukkit.getLogger().warning("Infinite in " + tag + " damage modifier function.");
  12. }
  13. return value;
  14. }
  15.  
  16. };
  17. }
  18.  
  19. // CraftBukkit start
  20. protected boolean damageEntity0(final DamageSource damagesource, float f) { // void -> boolean, add final
  21. if (!this.isInvulnerable(damagesource)) {
  22. final boolean human = this instanceof EntityHuman;
  23. float originalDamage = f;
  24. Function<Double, Double> hardHat = new Function<Double, Double>() {
  25. @Override
  26. public Double apply(Double f) {
  27. if ((damagesource == DamageSource.ANVIL || damagesource == DamageSource.FALLING_BLOCK) && !EntityLiving.this.getEquipment(EnumItemSlot.HEAD).isEmpty()) {
  28. return -(f - (f * 0.75F));
  29.  
  30. }
  31. return -0.0;
  32. }
  33. };
  34. hardHat = createModifier("hardHat", hardHat);
  35. float hardHatModifier = hardHat.apply((double) f).floatValue();
  36. f += hardHatModifier;
  37.  
  38. Function<Double, Double> blocking = new Function<Double, Double>() {
  39. @Override
  40. public Double apply(Double f) {
  41. return -((EntityLiving.this.applyBlockingModifier(damagesource)) ? f : 0.0);
  42. }
  43. };
  44. blocking = createModifier("blocking", blocking);
  45. float blockingModifier = blocking.apply((double) f).floatValue();
  46. f += blockingModifier;
  47.  
  48. Function<Double, Double> armor = new Function<Double, Double>() {
  49. @Override
  50. public Double apply(Double f) {
  51. return -(f - EntityLiving.this.applyArmorModifier(damagesource, f.floatValue()));
  52. }
  53. };
  54. armor = createModifier("armor", armor);
  55. float armorModifier = armor.apply((double) f).floatValue();
  56. f += armorModifier;
  57.  
  58. Function<Double, Double> resistance = new Function<Double, Double>() {
  59. @Override
  60. public Double apply(Double f) {
  61. if (!damagesource.isStarvation() && EntityLiving.this.hasEffect(MobEffects.RESISTANCE) && damagesource != DamageSource.OUT_OF_WORLD) {
  62. int i = (EntityLiving.this.getEffect(MobEffects.RESISTANCE).getAmplifier() + 1) * 5;
  63. int j = 25 - i;
  64. float f1 = f.floatValue() * (float) j;
  65. return -(f - (f1 / 25.0F));
  66. }
  67. return -0.0;
  68. }
  69. };
  70. resistance = createModifier("resistance", resistance);
  71. float resistanceModifier = resistance.apply((double) f).floatValue();
  72. f += resistanceModifier;
  73.  
  74. Function<Double, Double> magic = new Function<Double, Double>() {
  75. @Override
  76. public Double apply(Double f) {
  77. return -(f - EntityLiving.this.applyMagicModifier(damagesource, f.floatValue()));
  78. }
  79. };
  80. magic = createModifier("magic", magic);
  81. float magicModifier = magic.apply((double) f).floatValue();
  82. f += magicModifier;
  83.  
  84. Function<Double, Double> absorption = new Function<Double, Double>() {
  85. @Override
  86. public Double apply(Double f) {
  87. return -(Math.max(f - Math.max(f - EntityLiving.this.getAbsorptionHearts(), 0.0F), 0.0F));
  88. }
  89. };
  90. absorption = createModifier("absorption", absorption);
  91. float absorptionModifier = absorption.apply((double) f).floatValue();
  92.  
  93. EntityDamageEvent event = CraftEventFactory.handleLivingEntityDamageEvent(this, damagesource, originalDamage, hardHatModifier, blockingModifier, armorModifier, resistanceModifier, magicModifier, absorptionModifier, hardHat, blocking, armor, resistance, magic, absorption);
  94. if (damagesource.getEntity() instanceof EntityHuman) {
  95. // Paper start - PlayerAttackEntityCooldownResetEvent
  96. if (damagesource.getEntity() instanceof EntityPlayer) {
  97. EntityPlayer player = (EntityPlayer) damagesource.getEntity();
  98. if (new com.destroystokyo.paper.event.player.PlayerAttackEntityCooldownResetEvent(player.getBukkitEntity(), this.getBukkitEntity(), player.getAttackCooldown(0F)).callEvent()) {
  99. player.resetAttackCooldown();
  100. }
  101. } else {
  102. ((EntityHuman) damagesource.getEntity()).resetAttackCooldown();
  103. }
  104. // Paper end
  105. }
  106. if (event.isCancelled()) {
  107. return false;
  108. }
  109.  
  110. f = (float) event.getFinalDamage();
  111.  
  112. // Resistance
  113. if (event.getDamage(DamageModifier.RESISTANCE) < 0) {
  114. float f3 = (float) -event.getDamage(DamageModifier.RESISTANCE);
  115. if (f3 > 0.0F && f3 < 3.4028235E37F) {
  116. if (this instanceof EntityPlayer) {
  117. ((EntityPlayer) this).a(StatisticList.DAMAGE_RESISTED, Math.round(f3 * 10.0F));
  118. } else if (damagesource.getEntity() instanceof EntityPlayer) {
  119. ((EntityPlayer) damagesource.getEntity()).a(StatisticList.DAMAGE_DEALT_RESISTED, Math.round(f3 * 10.0F));
  120. }
  121. }
  122. }
  123.  
  124. // Apply damage to helmet
  125. if ((damagesource == DamageSource.ANVIL || damagesource == DamageSource.FALLING_BLOCK) && this.getEquipment(EnumItemSlot.HEAD) != null) {
  126. this.getEquipment(EnumItemSlot.HEAD).damage((int) (event.getDamage() * 4.0F + this.random.nextFloat() * event.getDamage() * 2.0F), this, (entityliving) -> {
  127. entityliving.broadcastItemBreak(EnumItemSlot.HEAD);
  128. });
  129. }
  130.  
  131. // Apply damage to armor
  132. if (!damagesource.ignoresArmor()) {
  133. float armorDamage = (float) (event.getDamage() + event.getDamage(DamageModifier.BLOCKING) + event.getDamage(DamageModifier.HARD_HAT));
  134. this.damageArmor(damagesource, armorDamage);
  135. }
  136.  
  137. // Apply blocking code // PAIL: steal from above
  138. if (event.getDamage(DamageModifier.BLOCKING) < 0) {
  139. this.world.broadcastEntityEffect(this, (byte) 29); // SPIGOT-4635 - shield damage sound
  140. this.damageShield((float) -event.getDamage(DamageModifier.BLOCKING));
  141. Entity entity = damagesource.j();
  142.  
  143. if (entity instanceof EntityLiving) {
  144. this.shieldBlock((EntityLiving) entity);
  145. }
  146. }
  147.  
  148. absorptionModifier = (float) -event.getDamage(DamageModifier.ABSORPTION);
  149. this.setAbsorptionHearts(Math.max(this.getAbsorptionHearts() - absorptionModifier, 0.0F));
  150. float f2 = absorptionModifier;
  151.  
  152. if (f2 > 0.0F && f2 < 3.4028235E37F && this instanceof EntityHuman) {
  153. ((EntityHuman) this).a(StatisticList.DAMAGE_ABSORBED, Math.round(f2 * 10.0F));
  154. }
  155. if (f2 > 0.0F && f2 < 3.4028235E37F && damagesource.getEntity() instanceof EntityPlayer) {
  156. ((EntityPlayer) damagesource.getEntity()).a(StatisticList.DAMAGE_DEALT_ABSORBED, Math.round(f2 * 10.0F));
  157. }
  158.  
  159. if (f > 0 || !human) {
  160. if (human) {
  161. // PAIL: Be sure to drag all this code from the EntityHuman subclass each update.
  162. ((EntityHuman) this).applyExhaustion(damagesource.getExhaustionCost(), org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.DAMAGED); // CraftBukkit - EntityExhaustionEvent
  163. if (f < 3.4028235E37F) {
  164. ((EntityHuman) this).a(StatisticList.DAMAGE_TAKEN, Math.round(f * 10.0F));
  165. }
  166. }
  167. // CraftBukkit end
  168. float f3 = this.getHealth();
  169.  
  170. this.setHealth(f3 - f);
  171. this.getCombatTracker().trackDamage(damagesource, f3, f);
  172. // CraftBukkit start
  173. if (!human) {
  174. this.setAbsorptionHearts(this.getAbsorptionHearts() - f);
  175. }
  176.  
  177. return true;
  178. } else {
  179. // Duplicate triggers if blocking
  180. if (event.getDamage(DamageModifier.BLOCKING) < 0) {
  181. if (this instanceof EntityPlayer) {
  182. CriterionTriggers.h.a((EntityPlayer) this, damagesource, f, originalDamage, true);
  183. f2 = (float) -event.getDamage(DamageModifier.BLOCKING);
  184. if (f2 > 0.0F && f2 < 3.4028235E37F) {
  185. ((EntityPlayer) this).a(StatisticList.DAMAGE_BLOCKED_BY_SHIELD, Math.round(originalDamage * 10.0F));
  186. }
  187. }
  188.  
  189. if (damagesource.getEntity() instanceof EntityPlayer) {
  190. CriterionTriggers.g.a((EntityPlayer) damagesource.getEntity(), this, damagesource, f, originalDamage, true);
  191. }
  192.  
  193. return false;
  194. } else {
  195. return originalDamage > 0;
  196. }
  197. // CraftBukkit end
  198. }
  199. }
  200. return false; // CraftBukkit
  201. }
Add Comment
Please, Sign In to add comment