Skip to content

Commit

Permalink
Fixed #2781
Browse files Browse the repository at this point in the history
  • Loading branch information
Mgazul committed Jan 22, 2024
1 parent 06a5d7f commit fa3e4ed
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 76 deletions.
155 changes: 80 additions & 75 deletions patches/minecraft/net/minecraft/entity/LivingEntity.java.patch
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- a/net/minecraft/entity/LivingEntity.java
+++ b/net/minecraft/entity/LivingEntity.java
@@ -1,26 +_,49 @@
@@ -1,26 +_,50 @@
package net.minecraft.entity;

+import com.google.common.base.Function;
Expand All @@ -24,6 +24,7 @@
import java.util.Random;
+import java.util.Set;
import java.util.UUID;
+import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Predicate;
+
import javax.annotation.Nullable;
Expand Down Expand Up @@ -565,7 +566,7 @@
float f1 = 0.0F;
if (p_70097_2_ > 0.0F && this.func_184583_d(p_70097_1_)) {
this.func_184590_k(p_70097_2_);
@@ -955,22 +_,48 @@
@@ -955,22 +_,42 @@

this.field_70721_aZ = 1.5F;
boolean flag1 = true;
Expand All @@ -576,31 +577,24 @@
return false;
}

- this.func_70665_d(p_70097_1_, p_70097_2_ - this.field_110153_bc);
+ // CraftBukkit start
+ if (this instanceof PlayerEntity) {
+ this.func_70665_d(p_70097_1_, p_70097_2_ - this.field_110153_bc);
+ } else {
+ if (!this.damageEntity0(p_70097_1_, p_70097_2_ - this.field_110153_bc)) {
+ return false;
+ }
this.func_70665_d(p_70097_1_, p_70097_2_ - this.field_110153_bc);
+ if (!this.canDamage()) {
+ return false;
+ }
+ // CraftBukkit end
this.field_110153_bc = p_70097_2_;
flag1 = false;
} else {
- this.field_110153_bc = p_70097_2_;
- this.field_70172_ad = 20;
+ // CraftBukkit start
+ if (this instanceof PlayerEntity) {
+ this.func_70665_d(p_70097_1_, p_70097_2_);
+ } else {
+ if (!this.damageEntity0(p_70097_1_, p_70097_2_)) {
+ return false;
+ }
this.func_70665_d(p_70097_1_, p_70097_2_);
+ if (!this.canDamage()) {
+ return false;
+ }
+ // CraftBukkit end
this.field_110153_bc = p_70097_2_;
- this.field_70172_ad = 20;
- this.func_70665_d(p_70097_1_, p_70097_2_);
+ this.field_110153_bc = p_70097_2_;
+ this.field_70172_ad = this.field_70771_an; // CraftBukkit - restore use of maxNoDamageTicks
this.field_70738_aO = 10;
this.field_70737_aN = this.field_70738_aO;
Expand Down Expand Up @@ -914,11 +908,10 @@
}

if (p_70672_2_ <= 0.0F) {
@@ -1447,23 +_,140 @@
}
@@ -1448,22 +_,152 @@

protected void func_70665_d(DamageSource p_70665_1_, float p_70665_2_) {
- if (!this.func_180431_b(p_70665_1_)) {
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_);
- float f2 = Math.max(p_70665_2_ - this.func_110139_bj(), 0.0F);
Expand All @@ -933,140 +926,152 @@
- this.func_70606_j(f1 - f2);
- this.func_110142_aN().func_94547_a(p_70665_1_, f1, f2);
- this.func_110149_m(this.func_110139_bj() - f2);
+ damageEntity0(p_70665_1_, p_70665_2_);
+ }
+
+ // CraftBukkit start
+ 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;
+ final float originalDamage = damageAmount;
+ final float originalDamage = p_70665_2_;
+ // Cauldron start - apply forge damage hook
+ damageAmount = ForgeHooks.onLivingHurt(this, damagesource, damageAmount);
+ p_70665_2_ = ForgeHooks.onLivingHurt(this, p_70665_1_, p_70665_2_);
+ // If the damage is negative return true
+ if (damageAmount < 0) return true;
+ if (p_70665_2_ < 0) {
+ this.canDamage.set(true);
+ return;
+ }
+ // Thermos detect null damage
+ final boolean nulldmg = damageAmount == 0;
+ final boolean nulldmg = p_70665_2_ == 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()) {
+ if ((p_70665_1_ == DamageSource.field_82728_o || p_70665_1_ == DamageSource.field_82729_p) && !LivingEntity.this.func_184582_a(EquipmentSlotType.HEAD).func_190926_b()) {
+ return -(f - (f * 0.75F));
+ }
+ return -0.0;
+ };
+ 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;
+ float hardHatModifier = hardHat.apply((double) p_70665_2_).floatValue();
+ p_70665_2_ += hardHatModifier;
+ Function<Double, Double> blocking = f -> -((LivingEntity.this.func_184583_d(p_70665_1_)) ? f : 0.0);
+ float blockingModifier = blocking.apply((double) p_70665_2_).floatValue();
+ p_70665_2_ += blockingModifier;
+ Function<Double, Double> armor = f -> -(f - LivingEntity.this.func_70655_b(p_70665_1_, f.floatValue()));
+ float armorModifier = armor.apply((double) p_70665_2_).floatValue();
+ p_70665_2_ += 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) {
+ if (!p_70665_1_.func_151517_h() && LivingEntity.this.func_70644_a(Effects.field_76429_m) && p_70665_1_ != 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 = f.floatValue() * (float) j;
+ return -(f - (f1 / 25.0F));
+ }
+ return -0.0;
+ };
+ 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;
+ float resistanceModifier = resistance.apply((double) p_70665_2_).floatValue();
+ p_70665_2_ += resistanceModifier;
+ Function<Double, Double> magic = f -> -(f - LivingEntity.this.func_70672_c(p_70665_1_, f.floatValue()));
+ float magicModifier = magic.apply((double) p_70665_2_).floatValue();
+ p_70665_2_ += 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);
+ float absorptionModifier0 = absorption.apply((double) p_70665_2_).floatValue();
+ EntityDamageEvent event = CraftEventFactory.handleLivingEntityDamageEvent(this, p_70665_1_, originalDamage, hardHatModifier, blockingModifier, armorModifier, resistanceModifier, magicModifier, absorptionModifier0, hardHat, blocking, armor, resistance, magic, absorption);
+
+ if (event.isCancelled()) {
+ return false;
+ this.canDamage.set(false);
+ return;
+ }
+ damageAmount = (float) event.getFinalDamage();
+
+ if (nulldmg) return true; // Preclude any stupidity with null head items
+ p_70665_2_ = (float) event.getFinalDamage();
+
+ // Resistance
+ if (event.getDamage(EntityDamageEvent.DamageModifier.RESISTANCE) < 0) {
+ float f3 = (float) -event.getDamage(EntityDamageEvent.DamageModifier.RESISTANCE);
+ if (f3 > 0.0F && f3 < 3.4028235E37F) {
+ if (this instanceof ServerPlayerEntity) {
+ ((ServerPlayerEntity) this).func_195067_a(Stats.field_212739_K, Math.round(f3 * 10.0F));
+ } else if (damagesource.func_76346_g() instanceof ServerPlayerEntity) {
+ ((ServerPlayerEntity) damagesource.func_76346_g()).func_195067_a(Stats.field_212736_G, Math.round(f3 * 10.0F));
+ } else if (p_70665_1_.func_76346_g() instanceof ServerPlayerEntity) {
+ ((ServerPlayerEntity) p_70665_1_.func_76346_g()).func_195067_a(Stats.field_212736_G, Math.round(f3 * 10.0F));
+ }
+ }
+ }
+ // Apply damage to helmet
+ if ((damagesource == DamageSource.field_82728_o || damagesource == DamageSource.field_82729_p) && this.func_184582_a(EquipmentSlotType.HEAD) != null) {
+ if ((p_70665_1_ == DamageSource.field_82728_o || p_70665_1_ == 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));
+ }
+ // Apply damage to armor
+ if (!damagesource.func_76363_c()) {
+ if (!p_70665_1_.func_76363_c()) {
+ float armorDamage = (float) (event.getDamage() + event.getDamage(EntityDamageEvent.DamageModifier.BLOCKING) + event.getDamage(EntityDamageEvent.DamageModifier.HARD_HAT));
+ this.func_230294_b_(damagesource, armorDamage);
+ this.func_230294_b_(p_70665_1_, armorDamage);
+ }
+
+ // Apply blocking code // PAIL: steal from above
+ if (event.getDamage(EntityDamageEvent.DamageModifier.BLOCKING) < 0) {
+ 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();
+ Entity entity = p_70665_1_.func_76364_f();
+ if (entity instanceof LivingEntity) {
+ this.func_190629_c((LivingEntity) entity);
+ }
+ }
+ damageAmount = Math.max(damageAmount - this.func_110139_bj(), 0.0F);
+ p_70665_2_ = Math.max(p_70665_2_ - 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));
+ if (f2 > 0.0F && f2 < 3.4028235E37F && p_70665_1_.func_76346_g() instanceof ServerPlayerEntity) {
+ ((ServerPlayerEntity) p_70665_1_.func_76346_g()).func_195067_a(Stats.field_212735_F, Math.round(f2 * 10.0F));
+ }
+ if (damageAmount > 0 || !human) {
+ if (p_70665_2_ > 0 || !human) {
+ if (human) {
+ // PAIL: Be sure to drag all this code from the EntityHuman subclass each update.
+ ((PlayerEntity) this).func_71020_j(damagesource.func_76345_d());
+ if (damageAmount < 3.4028235E37F) {
+ ((PlayerEntity) this).func_195067_a(Stats.field_188112_z, Math.round(damageAmount * 10.0F));
+ ((PlayerEntity) this).func_71020_j(p_70665_1_.func_76345_d());
+ if (p_70665_2_ < 3.4028235E37F) {
+ ((PlayerEntity) this).func_195067_a(Stats.field_188112_z, Math.round(p_70665_2_ * 10.0F));
+ }
+ }
+ // CraftBukkit end
+ float f3 = this.func_110143_aJ();
+ this.func_70606_j(f3 - damageAmount);
+ this.func_110142_aN().func_94547_a(damagesource, f3, damageAmount);
+ this.func_70606_j(f3 - p_70665_2_);
+ this.func_110142_aN().func_94547_a(p_70665_1_, f3, p_70665_2_);
+ // CraftBukkit start
+ if (!human) {
+ this.func_110149_m(this.func_110139_bj() - damageAmount);
+ this.func_110149_m(this.func_110139_bj() - p_70665_2_);
+ }
+ return true;
+ this.canDamage.set(true);
+ return;
+ } 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, damageAmount, originalDamage, true);
+ CriteriaTriggers.field_192128_h.func_192200_a((ServerPlayerEntity) this, p_70665_1_, p_70665_2_, 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, damageAmount, originalDamage, true);
+ if (p_70665_1_.func_76346_g() instanceof ServerPlayerEntity) {
+ CriteriaTriggers.field_192127_g.func_192220_a((ServerPlayerEntity) p_70665_1_.func_76346_g(), this, p_70665_1_, p_70665_2_, originalDamage, true);
+ }
+ return false;
+ this.canDamage.set(false);
+ return;
+ } else {
+ return originalDamage > 0;
+ boolean flag = originalDamage > 0;
+ this.canDamage.set(flag);
+ return;
+ }
+ // CraftBukkit end
}
}
+ return false; // CraftBukkit
+ this.canDamage.set(false);
+ }
+
+ public AtomicBoolean canDamage = new AtomicBoolean(true);
+ public boolean canDamage() {
+ return canDamage.getAndSet(true);
+ }
+ // Mohist end
+
+ // CraftBukkit start
+ protected boolean damageEntity0(final DamageSource damagesource, float damageAmount) { // void -> boolean, add final
+ this.func_70665_d(damagesource, damageAmount);
+ return canDamage();
}

public CombatTracker func_110142_aN() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,11 @@
});
if (this.field_184627_bm.func_190926_b()) {
if (hand == Hand.MAIN_HAND) {
@@ -846,6 +_,10 @@
@@ -845,7 +_,12 @@
}
}

+ // #2871 TODO
protected void func_70665_d(DamageSource p_70665_1_, float p_70665_2_) {
+ if (true) {
+ this.damageEntity0(p_70665_1_, p_70665_2_);
Expand Down

0 comments on commit fa3e4ed

Please sign in to comment.