Skip to content

Commit

Permalink
Fix #2458
Browse files Browse the repository at this point in the history
  • Loading branch information
Mgazul committed Jul 5, 2023
1 parent 6e39cd4 commit 7affa21
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 63 deletions.
110 changes: 47 additions & 63 deletions patches/minecraft/net/minecraft/entity/LivingEntity.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@
protected float func_70672_c(DamageSource p_70672_1_, float p_70672_2_) {
if (p_70672_1_.func_151517_h()) {
return p_70672_2_;
@@ -1447,23 +_,156 @@
@@ -1447,23 +_,140 @@
}

protected void func_70665_d(DamageSource p_70665_1_, float p_70665_2_) {
Expand All @@ -910,57 +910,57 @@
+ }
+
+ // CraftBukkit start
+ protected boolean damageEntity0(final DamageSource damagesource, float f) { // void -> boolean, add final
+ protected boolean damageEntity0(final DamageSource damagesource, float damageAmount) { // void -> boolean, add final
+ if (!this.func_180431_b(damagesource)) {
+ // Check if entity is a "human" aka player
+ final boolean human = this instanceof PlayerEntity;
+ f = net.minecraftforge.common.ForgeHooks.onLivingHurt(this, damagesource, f);
+ if (f <= 0) return true;
+ float originalDamage = f;
+ Function<Double, Double> hardHat = f12 -> {
+ final float originalDamage = damageAmount;
+ // Cauldron start - apply forge damage hook
+ damageAmount = ForgeHooks.onLivingHurt(this, damagesource, damageAmount);
+ // If the damage is negative return true
+ if (damageAmount < 0) return true;
+ // Thermos detect null damage
+ final boolean nulldmg = damageAmount == 0;
+ // Cauldron end
+
+ Function<Double, Double> hardHat = f -> {
+ if ((damagesource == DamageSource.field_82728_o || damagesource == DamageSource.field_82729_p) && !LivingEntity.this.func_184582_a(EquipmentSlotType.HEAD).func_190926_b()) {
+ return -(f12 - (f12 * 0.75F));
+ return -(f - (f * 0.75F));
+ }
+ return -0.0;
+ };
+ float hardHatModifier = hardHat.apply((double) f).floatValue();
+ f += hardHatModifier;
+
+ Function<Double, Double> blocking = f13 -> -((LivingEntity.this.func_184583_d(damagesource)) ? f13 : 0.0);
+ float blockingModifier = blocking.apply((double) f).floatValue();
+ f += blockingModifier;
+
+ Function<Double, Double> armor = f14 -> -(f14 - LivingEntity.this.getDamageAfterArmorAbsorb(damagesource, f14.floatValue(), true));
+ float armorModifier = armor.apply((double) f).floatValue();
+ f += armorModifier;
+
+ Function<Double, Double> resistance = f15 -> {
+ float hardHatModifier = hardHat.apply((double) damageAmount).floatValue();
+ damageAmount += hardHatModifier;
+ Function<Double, Double> blocking = f -> -((LivingEntity.this.func_184583_d(damagesource)) ? f : 0.0);
+ float blockingModifier = blocking.apply((double) damageAmount).floatValue();
+ damageAmount += blockingModifier;
+ Function<Double, Double> armor = f -> -(f - LivingEntity.this.func_70655_b(damagesource, f.floatValue()));
+ float armorModifier = armor.apply((double) damageAmount).floatValue();
+ damageAmount += armorModifier;
+ Function<Double, Double> resistance = f -> {
+ if (!damagesource.func_151517_h() && LivingEntity.this.func_70644_a(Effects.field_76429_m) && damagesource != DamageSource.field_76380_i) {
+ int i = (LivingEntity.this.func_70660_b(Effects.field_76429_m).func_76458_c() + 1) * 5;
+ int j = 25 - i;
+ float f1 = f15.floatValue() * (float) j;
+ return -(f15 - (f1 / 25.0F));
+ float f1 = f.floatValue() * (float) j;
+ return -(f - (f1 / 25.0F));
+ }
+ return -0.0;
+ };
+ float resistanceModifier = resistance.apply((double) f).floatValue();
+ f += resistanceModifier;
+
+ Function<Double, Double> magic = f16 -> -(f16 - LivingEntity.this.func_70672_c(damagesource, f16.floatValue()));
+ float magicModifier = magic.apply((double) f).floatValue();
+ f += magicModifier;
+
+ Function<Double, Double> absorption = f17 -> -(Math.max(f17 - Math.max(f17 - LivingEntity.this.func_110139_bj(), 0.0F), 0.0F));
+ float absorptionModifier = absorption.apply((double) f).floatValue();
+ float resistanceModifier = resistance.apply((double) damageAmount).floatValue();
+ damageAmount += resistanceModifier;
+ Function<Double, Double> magic = f -> -(f - LivingEntity.this.func_70672_c(damagesource, f.floatValue()));
+ float magicModifier = magic.apply((double) damageAmount).floatValue();
+ damageAmount += magicModifier;
+ Function<Double, Double> absorption = f -> -(Math.max(f - Math.max(f - LivingEntity.this.func_110139_bj(), 0.0F), 0.0F));
+ float absorptionModifier0 = absorption.apply((double) damageAmount).floatValue();
+ EntityDamageEvent event = CraftEventFactory.handleLivingEntityDamageEvent(this, damagesource, originalDamage, hardHatModifier, blockingModifier, armorModifier, resistanceModifier, magicModifier, absorptionModifier0, hardHat, blocking, armor, resistance, magic, absorption);
+
+ EntityDamageEvent event = CraftEventFactory.handleLivingEntityDamageEvent(this, damagesource, originalDamage, hardHatModifier, blockingModifier, armorModifier, resistanceModifier, magicModifier, absorptionModifier, hardHat, blocking, armor, resistance, magic, absorption);
+ if (damagesource.func_76346_g() instanceof PlayerEntity) {
+ ((PlayerEntity) damagesource.func_76346_g()).func_184821_cY(); // Moved from EntityHuman in order to make the cooldown reset get called after the damage event is fired
+ }
+ if (event.isCancelled()) {
+ return false;
+ }
+ damageAmount = (float) event.getFinalDamage();
+
+ f = (float) event.getFinalDamage();
+ if (nulldmg) return true; // Preclude any stupidity with null head items
+
+ // Resistance
+ if (event.getDamage(EntityDamageEvent.DamageModifier.RESISTANCE) < 0) {
Expand All @@ -973,15 +973,10 @@
+ }
+ }
+ }
+
+
+ // Apply damage to helmet
+ if ((damagesource == DamageSource.field_82728_o || damagesource == DamageSource.field_82729_p) && this.func_184582_a(EquipmentSlotType.HEAD) != null) {
+ this.func_184582_a(EquipmentSlotType.HEAD).func_222118_a((int) (event.getDamage() * 4.0F + this.field_70146_Z.nextFloat() * event.getDamage() * 2.0F), this, (entityliving) -> {
+ entityliving.func_213361_c(EquipmentSlotType.HEAD);
+ });
+ this.func_184582_a(EquipmentSlotType.HEAD).func_222118_a((int) (event.getDamage() * 4.0F + this.field_70146_Z.nextFloat() * event.getDamage() * 2.0F), this, (entityliving) -> entityliving.func_213361_c(EquipmentSlotType.HEAD));
+ }
+
+ // Apply damage to armor
+ if (!damagesource.func_76363_c()) {
+ float armorDamage = (float) (event.getDamage() + event.getDamage(EntityDamageEvent.DamageModifier.BLOCKING) + event.getDamage(EntityDamageEvent.DamageModifier.HARD_HAT));
Expand All @@ -993,61 +988,50 @@
+ this.field_70170_p.func_72960_a(this, (byte) 29); // SPIGOT-4635 - shield damage sound
+ this.func_184590_k((float) -event.getDamage(EntityDamageEvent.DamageModifier.BLOCKING));
+ Entity entity = damagesource.func_76364_f();
+
+ if (entity instanceof LivingEntity) {
+ this.func_190629_c((LivingEntity) entity);
+ }
+ }
+
+ absorptionModifier = (float) -event.getDamage(EntityDamageEvent.DamageModifier.ABSORPTION);
+ damageAmount = Math.max(damageAmount - this.func_110139_bj(), 0.0F);
+ float absorptionModifier = (float) -event.getDamage(EntityDamageEvent.DamageModifier.ABSORPTION);
+ this.func_110149_m(Math.max(this.func_110139_bj() - absorptionModifier, 0.0F));
+ float f2 = absorptionModifier;
+
+ if (f2 > 0.0F && f2 < 3.4028235E37F && this instanceof PlayerEntity) {
+ ((PlayerEntity) this).func_195067_a(Stats.field_212738_J, Math.round(f2 * 10.0F));
+ }
+ if (f2 > 0.0F && f2 < 3.4028235E37F && damagesource.func_76346_g() instanceof ServerPlayerEntity) {
+ ((ServerPlayerEntity) damagesource.func_76346_g()).func_195067_a(Stats.field_212735_F, Math.round(f2 * 10.0F));
+ }
+
+ f = ForgeHooks.onLivingDamage(this, damagesource, f);
+
+ if (f > 0 || !human) {
+ if (damageAmount > 0 || !human) {
+ if (human) {
+ // PAIL: Be sure to drag all this code from the EntityPlayer subclass each update.
+ ((PlayerEntity) this).withExhaustionReason(org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.DAMAGED);
+ // PAIL: Be sure to drag all this code from the EntityHuman subclass each update.
+ ((PlayerEntity) this).func_71020_j(damagesource.func_76345_d());
+ ((PlayerEntity) this).setDefaultExhaustionReason();
+ if (f < 3.4028235E37F) {
+ ((PlayerEntity) this).func_195067_a(Stats.field_188112_z, Math.round(f * 10.0F));
+ if (damageAmount < 3.4028235E37F) {
+ ((PlayerEntity) this).func_195067_a(Stats.field_188112_z, Math.round(damageAmount * 10.0F));
+ }
+ }
+ // CraftBukkit end
+ float f3 = this.func_110143_aJ();
+
+ this.func_110142_aN().func_94547_a(damagesource, f3, f);
+ this.func_70606_j(f3 - f); // Forge: moved to fix MC-121048
+ this.func_70606_j(f3 - damageAmount);
+ this.func_110142_aN().func_94547_a(damagesource, f3, damageAmount);
+ // CraftBukkit start
+ if (!human) {
+ this.func_110149_m(this.func_110139_bj() - f);
+ this.func_110149_m(this.func_110139_bj() - damageAmount);
+ }
+
+ return true;
+ } else {
+ // Duplicate triggers if blocking
+ if (event.getDamage(EntityDamageEvent.DamageModifier.BLOCKING) < 0) {
+ if (this instanceof ServerPlayerEntity) {
+ CriteriaTriggers.field_192128_h.func_192200_a((ServerPlayerEntity) this, damagesource, f, originalDamage, true);
+ CriteriaTriggers.field_192128_h.func_192200_a((ServerPlayerEntity) this, damagesource, damageAmount, originalDamage, true);
+ f2 = (float) -event.getDamage(EntityDamageEvent.DamageModifier.BLOCKING);
+ if (f2 > 0.0F && f2 < 3.4028235E37F) {
+ ((ServerPlayerEntity) this).func_195067_a(Stats.field_212737_I, Math.round(originalDamage * 10.0F));
+ }
+ }
+
+ if (damagesource.func_76346_g() instanceof ServerPlayerEntity) {
+ CriteriaTriggers.field_192127_g.func_192220_a((ServerPlayerEntity) damagesource.func_76346_g(), this, damagesource, f, originalDamage, true);
+ CriteriaTriggers.field_192127_g.func_192220_a((ServerPlayerEntity) damagesource.func_76346_g(), this, damagesource, damageAmount, originalDamage, true);
+ }
+
+ return false;
+ } else {
+ return originalDamage > 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,17 @@
});
if (this.field_184627_bm.func_190926_b()) {
if (hand == Hand.MAIN_HAND) {
@@ -846,6 +_,10 @@
}

protected void func_70665_d(DamageSource p_70665_1_, float p_70665_2_) {
+ if (true) {
+ this.damageEntity0(p_70665_1_, p_70665_2_);
+ return;
+ }
if (!this.func_180431_b(p_70665_1_)) {
p_70665_2_ = this.func_70655_b(p_70665_1_, p_70665_2_);
p_70665_2_ = this.func_70672_c(p_70665_1_, p_70665_2_);
@@ -859,15 +_,50 @@
if (f2 != 0.0F) {
this.func_71020_j(p_70665_1_.func_76345_d());
Expand Down

0 comments on commit 7affa21

Please sign in to comment.