Skip to content

Commit

Permalink
Fix damage absorbed injection
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeregorix committed Oct 3, 2024
1 parent ccad6b6 commit a8dd238
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Player> attackImpl$attack;

@Redirect(method = "attack", at = @At(value = "INVOKE", target = "Lnet/neoforged/neoforge/event/entity/player/CriticalHitEvent;isCriticalHit()Z"))
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit a8dd238

Please sign in to comment.