From ae57ebd620d4e1942388f50415393d192647c387 Mon Sep 17 00:00:00 2001 From: Mgazul Date: Tue, 23 Jan 2024 19:06:05 +0800 Subject: [PATCH] Fix bug --- .../minecraft/entity/LivingEntity.java.patch | 9 + .../entity/player/PlayerEntity.java.patch | 205 ++++++++++++++---- 2 files changed, 166 insertions(+), 48 deletions(-) diff --git a/patches/minecraft/net/minecraft/entity/LivingEntity.java.patch b/patches/minecraft/net/minecraft/entity/LivingEntity.java.patch index fb9286400c..ee286429ac 100644 --- a/patches/minecraft/net/minecraft/entity/LivingEntity.java.patch +++ b/patches/minecraft/net/minecraft/entity/LivingEntity.java.patch @@ -678,6 +678,15 @@ } } +@@ -1127,7 +_,7 @@ + + } + +- private boolean func_184583_d(DamageSource p_184583_1_) { ++ public boolean func_184583_d(DamageSource p_184583_1_) { + Entity entity = p_184583_1_.func_76364_f(); + boolean flag = false; + if (entity instanceof AbstractArrowEntity) { @@ -1165,6 +_,7 @@ } diff --git a/patches/minecraft/net/minecraft/entity/player/PlayerEntity.java.patch b/patches/minecraft/net/minecraft/entity/player/PlayerEntity.java.patch index 16d9130c0b..8e92d1ae05 100644 --- a/patches/minecraft/net/minecraft/entity/player/PlayerEntity.java.patch +++ b/patches/minecraft/net/minecraft/entity/player/PlayerEntity.java.patch @@ -1,5 +1,12 @@ --- a/net/minecraft/entity/player/PlayerEntity.java +++ b/net/minecraft/entity/player/PlayerEntity.java +@@ -1,5 +_,6 @@ + package net.minecraft.entity.player; + ++import com.google.common.base.Function; + import com.google.common.collect.ImmutableList; + import com.google.common.collect.ImmutableMap; + import com.google.common.collect.Lists; @@ -48,8 +_,8 @@ import net.minecraft.inventory.container.INamedContainerProvider; import net.minecraft.inventory.container.PlayerContainer; @@ -18,13 +25,14 @@ import net.minecraft.stats.Stat; import net.minecraft.stats.Stats; import net.minecraft.tags.FluidTags; -@@ -106,10 +_,24 @@ +@@ -106,10 +_,26 @@ import net.minecraft.world.GameType; import net.minecraft.world.World; import net.minecraft.world.server.ServerWorld; +import net.minecraft.world.storage.MapData; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; ++import net.minecraftforge.common.ForgeHooks; +import org.bukkit.craftbukkit.v1_16_R3.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_16_R3.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_16_R3.util.CraftVector; @@ -32,6 +40,7 @@ +import org.bukkit.entity.Player; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.EntityCombustByEntityEvent; ++import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityExhaustionEvent; +import org.bukkit.event.entity.EntityPotionEffectEvent.Cause; +import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; @@ -337,73 +346,173 @@ }); if (this.field_184627_bm.func_190926_b()) { if (hand == Hand.MAIN_HAND) { -@@ -845,7 +_,12 @@ +@@ -845,29 +_,152 @@ } } + // #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_); -+ 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()); - float f1 = this.func_110143_aJ(); +- 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); +- this.func_110149_m(this.func_110139_bj() - (p_70665_2_ - f2)); +- float f = p_70665_2_ - f2; +- if (f > 0.0F && f < 3.4028235E37F) { +- this.func_195067_a(Stats.field_212738_J, Math.round(f * 10.0F)); +- } +- +- if (f2 != 0.0F) { +- this.func_71020_j(p_70665_1_.func_76345_d()); +- float f1 = this.func_110143_aJ(); - this.func_70606_j(this.func_110143_aJ() - f2); - this.func_110142_aN().func_94547_a(p_70665_1_, f1, f2); +- this.func_110142_aN().func_94547_a(p_70665_1_, f1, f2); - if (f2 < 3.4028235E37F) { - this.func_195067_a(Stats.field_188112_z, Math.round(f2 * 10.0F)); - } - -- } -- } -- } -+ this.func_70606_j(f1 - f2); // Forge: moved to fix MC-121048 -+ if (f2 < 3.4028235E37F) { -+ this.func_195067_a(Stats.field_188112_z, Math.round(f2 * 10.0F)); ++ // Check if entity is a "human" aka player ++ final boolean human = this instanceof PlayerEntity; ++ final float originalDamage = p_70665_2_; ++ // Cauldron start - apply forge damage hook ++ p_70665_2_ = ForgeHooks.onLivingHurt(this, p_70665_1_, p_70665_2_); ++ // If the damage is negative return true ++ if (p_70665_2_ < 0) { ++ this.canDamage.set(true); ++ return; ++ } ++ // Thermos detect null damage ++ final boolean nulldmg = p_70665_2_ == 0; ++ // Cauldron end ++ ++ Function hardHat = f -> { ++ if ((p_70665_1_ == DamageSource.field_82728_o || p_70665_1_ == DamageSource.field_82729_p) && !this.func_184582_a(EquipmentSlotType.HEAD).func_190926_b()) { ++ return -(f - (f * 0.75F)); + } ++ return -0.0; ++ }; ++ float hardHatModifier = hardHat.apply((double) p_70665_2_).floatValue(); ++ p_70665_2_ += hardHatModifier; ++ Function blocking = f -> -((this.func_184583_d(p_70665_1_)) ? f : 0.0); ++ float blockingModifier = blocking.apply((double) p_70665_2_).floatValue(); ++ p_70665_2_ += blockingModifier; ++ Function armor = f -> -(f - this.func_70655_b(p_70665_1_, f.floatValue())); ++ float armorModifier = armor.apply((double) p_70665_2_).floatValue(); ++ p_70665_2_ += armorModifier; ++ Function resistance = f -> { ++ if (!p_70665_1_.func_151517_h() && this.func_70644_a(Effects.field_76429_m) && p_70665_1_ != DamageSource.field_76380_i) { ++ int i = (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) p_70665_2_).floatValue(); ++ p_70665_2_ += resistanceModifier; ++ Function magic = f -> -(f - this.func_70672_c(p_70665_1_, f.floatValue())); ++ float magicModifier = magic.apply((double) p_70665_2_).floatValue(); ++ p_70665_2_ += magicModifier; ++ Function absorption = f -> -(Math.max(f - Math.max(f - this.func_110139_bj(), 0.0F), 0.0F)); ++ 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()) { ++ this.canDamage.set(false); ++ return; + } -+ } ++ 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 (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 ((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 (!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_(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 = p_70665_1_.func_76364_f(); ++ if (entity instanceof LivingEntity) { ++ this.func_190629_c((LivingEntity) entity); ++ } ++ } ++ 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 && 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 (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(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 - 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() - p_70665_2_); ++ } ++ 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, 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 (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); ++ } ++ this.canDamage.set(false); ++ return; ++ } else { ++ boolean flag = originalDamage > 0; ++ this.canDamage.set(flag); ++ return; ++ } ++ // CraftBukkit end + } + } +- } ++ this.canDamage.set(false); + } + + + // CraftBukkit start + @Override + protected boolean damageEntity0(DamageSource damageSrc, float damageAmount) { // void -> boolean -+ if (true) { -+ return super.damageEntity0(damageSrc, damageAmount); -+ } -+ if (!this.func_180431_b(damageSrc)) { -+ damageAmount = net.minecraftforge.common.ForgeHooks.onLivingHurt(this, damageSrc, damageAmount); -+ if (damageAmount <= 0) return false; -+ damageAmount = this.func_70655_b(damageSrc, damageAmount); -+ damageAmount = this.func_70672_c(damageSrc, damageAmount); -+ float f2 = Math.max(damageAmount - this.func_110139_bj(), 0.0F); -+ this.func_110149_m(this.func_110139_bj() - (damageAmount - f2)); -+ f2 = net.minecraftforge.common.ForgeHooks.onLivingDamage(this, damageSrc, f2); -+ float f = damageAmount - f2; -+ if (f > 0.0F && f < 3.4028235E37F) { -+ this.func_195067_a(Stats.field_212738_J, Math.round(f * 10.0F)); -+ } -+ -+ if (f2 != 0.0F) { -+ this.func_71020_j(damageSrc.func_76345_d()); -+ float f1 = this.func_110143_aJ(); -+ this.func_110142_aN().func_94547_a(damageSrc, f1, f2); -+ this.func_70606_j(f1 - f2); // Forge: moved to fix MC-121048 -+ if (f2 < 3.4028235E37F) { -+ this.func_195067_a(Stats.field_188112_z, Math.round(f2 * 10.0F)); -+ } -+ -+ } -+ } -+ return false; ++ return super.damageEntity0(damageSrc, damageAmount); + } + // CraftBukkit end