diff --git a/forge/src/mixins/resources/mixins.spongeforge.core.shared.json b/forge/src/mixins/resources/mixins.spongeforge.core.shared.json index 00b184cccaa..b322779182e 100644 --- a/forge/src/mixins/resources/mixins.spongeforge.core.shared.json +++ b/forge/src/mixins/resources/mixins.spongeforge.core.shared.json @@ -5,6 +5,8 @@ "priority": 1301, "mixins": [ "server.level.ServerEntityMixin_Shared", + "world.entity.LivingEntityMixin_Shared_Attack_Impl", + "world.entity.player.PlayerMixin_Shared_Attack_Impl", "world.entity.projectile.FishingHookMixin_Shared" ], "overwrites": { diff --git a/neoforge/src/mixins/java/org/spongepowered/neoforge/mixin/core/world/entity/LivingEntityMixin_Neo_Attack_Impl.java b/neoforge/src/mixins/java/org/spongepowered/neoforge/mixin/core/world/entity/LivingEntityMixin_Neo_Attack_Impl.java index ef6b1ea8674..0701bb119c5 100644 --- a/neoforge/src/mixins/java/org/spongepowered/neoforge/mixin/core/world/entity/LivingEntityMixin_Neo_Attack_Impl.java +++ b/neoforge/src/mixins/java/org/spongepowered/neoforge/mixin/core/world/entity/LivingEntityMixin_Neo_Attack_Impl.java @@ -29,11 +29,27 @@ import net.minecraft.world.entity.LivingEntity; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyVariable; import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.common.util.DamageEventUtil; @Mixin(LivingEntity.class) public class LivingEntityMixin_Neo_Attack_Impl { + protected DamageEventUtil.DamageEventResult attackImpl$actuallyHurtResult; + + /** + * Set absorbed damage after calling {@link LivingEntity#setAbsorptionAmount} in which we called the event + */ + @ModifyVariable(method = "actuallyHurt", ordinal = 2, + at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;setAbsorptionAmount(F)V", shift = At.Shift.AFTER)) + public float attackImpl$setAbsorbed(final float value) { + if (this.attackImpl$actuallyHurtResult.event().isCancelled()) { + return 0; + } + return this.attackImpl$actuallyHurtResult.damageAbsorbed().orElse(0f); + } + /** * Prevents {@link ServerPlayer#awardStat} from running before event */ diff --git a/neoforge/src/mixins/java/org/spongepowered/neoforge/mixin/core/world/entity/player/PlayerMixin_Neo_Attack_Impl.java b/neoforge/src/mixins/java/org/spongepowered/neoforge/mixin/core/world/entity/player/PlayerMixin_Neo_Attack_Impl.java index 6226fbfb361..4973ee5e62b 100644 --- a/neoforge/src/mixins/java/org/spongepowered/neoforge/mixin/core/world/entity/player/PlayerMixin_Neo_Attack_Impl.java +++ b/neoforge/src/mixins/java/org/spongepowered/neoforge/mixin/core/world/entity/player/PlayerMixin_Neo_Attack_Impl.java @@ -28,11 +28,13 @@ import net.neoforged.neoforge.event.entity.player.CriticalHitEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyVariable; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.common.util.DamageEventUtil; +import org.spongepowered.neoforge.mixin.core.world.entity.LivingEntityMixin_Neo_Attack_Impl; @Mixin(Player.class) -public class PlayerMixin_Neo_Attack_Impl { +public class PlayerMixin_Neo_Attack_Impl extends LivingEntityMixin_Neo_Attack_Impl { private DamageEventUtil.Attack attackImpl$attack; @Redirect(method = "attack", at = @At(value = "INVOKE", target = "Lnet/neoforged/neoforge/event/entity/player/CriticalHitEvent;isCriticalHit()Z")) @@ -43,4 +45,16 @@ public class PlayerMixin_Neo_Attack_Impl { } return false; } + + /** + * Set absorbed damage after calling {@link Player#setAbsorptionAmount} in which we called the event + */ + @ModifyVariable(method = "actuallyHurt", ordinal = 2, + at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;setAbsorptionAmount(F)V", shift = At.Shift.AFTER)) + public float attackImpl$setAbsorbed(final float value) { + if (this.attackImpl$actuallyHurtResult.event().isCancelled()) { + return 0; + } + return this.attackImpl$actuallyHurtResult.damageAbsorbed().orElse(0f); + } } diff --git a/src/mixins/java/org/spongepowered/common/mixin/core/world/entity/LivingEntityMixin_Shared_Attack_Impl.java b/src/mixins/java/org/spongepowered/common/mixin/core/world/entity/LivingEntityMixin_Shared_Attack_Impl.java index 98559353838..323ee6c6143 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/core/world/entity/LivingEntityMixin_Shared_Attack_Impl.java +++ b/src/mixins/java/org/spongepowered/common/mixin/core/world/entity/LivingEntityMixin_Shared_Attack_Impl.java @@ -31,7 +31,6 @@ import org.spongepowered.asm.mixin.injection.Slice; import org.spongepowered.common.util.DamageEventUtil; -// TODO NeoForge // Forge and Vanilla @Mixin(value = LivingEntity.class, priority = 900) public class LivingEntityMixin_Shared_Attack_Impl { diff --git a/src/mixins/java/org/spongepowered/common/mixin/core/world/entity/player/PlayerMixin_Shared_Attack_Impl.java b/src/mixins/java/org/spongepowered/common/mixin/core/world/entity/player/PlayerMixin_Shared_Attack_Impl.java index ce52f75c5ca..fb7aceaf7b3 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/core/world/entity/player/PlayerMixin_Shared_Attack_Impl.java +++ b/src/mixins/java/org/spongepowered/common/mixin/core/world/entity/player/PlayerMixin_Shared_Attack_Impl.java @@ -31,7 +31,6 @@ import org.spongepowered.asm.mixin.injection.Slice; import org.spongepowered.common.mixin.core.world.entity.LivingEntityMixin_Attack_Impl; -// TODO NeoForge // Forge and Vanilla @Mixin(value = Player.class, priority = 900) public abstract class PlayerMixin_Shared_Attack_Impl extends LivingEntityMixin_Attack_Impl { diff --git a/vanilla/src/mixins/resources/mixins.spongevanilla.core.shared.json b/vanilla/src/mixins/resources/mixins.spongevanilla.core.shared.json index 00b184cccaa..b322779182e 100644 --- a/vanilla/src/mixins/resources/mixins.spongevanilla.core.shared.json +++ b/vanilla/src/mixins/resources/mixins.spongevanilla.core.shared.json @@ -5,6 +5,8 @@ "priority": 1301, "mixins": [ "server.level.ServerEntityMixin_Shared", + "world.entity.LivingEntityMixin_Shared_Attack_Impl", + "world.entity.player.PlayerMixin_Shared_Attack_Impl", "world.entity.projectile.FishingHookMixin_Shared" ], "overwrites": {