From f6a8edfef1de201bd73cd221a52e0ec33a5cd03e Mon Sep 17 00:00:00 2001 From: Kam Date: Mon, 2 Mar 2026 02:58:03 -0500 Subject: [PATCH] Fix Guard with DBC Damage --- .../data/ability/type/AbilityDefend.java | 27 ++++++++++++++----- .../data/ability/type/AbilityGuard.java | 9 +++++++ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityDefend.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityDefend.java index 7ca8aa3e7..ac51ca92f 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityDefend.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityDefend.java @@ -19,8 +19,11 @@ import java.util.List; /** * Abstract base class for defensive abilities (Guard, Counter, Dodge). *

- * {@link #onDefend} handles shared checks (physical melee only) then delegates - * to {@link #performDefend(EntityLivingBase, float)} which subclasses override for their specific behavior. + * {@link #onDefend} handles shared checks then delegates to {@link #performDefend(EntityLivingBase, float)} + * which subclasses override for their specific behavior. + *

+ * Damage source filtering is controlled by {@link #isValidDamageSource(DamageSource)}. + * By default only physical melee is accepted; subclasses can override to widen (e.g. Guard accepts all). */ public abstract class AbilityDefend extends Ability implements IAbilityDefend { @@ -97,12 +100,13 @@ public abstract class AbilityDefend extends Ability implements IAbilityDefend { /** * Called when the caster is hit while defending. - * Checks for physical melee damage only, then delegates to {@link #performDefend(float)}. + * Checks damage source validity via {@link #isValidDamageSource}, then delegates + * to {@link #performDefend(EntityLivingBase, float)}. * * @param attacker The entity that hit the caster * @param source The damage source * @param amount The original incoming damage - * @return The modified damage to apply (unchanged if not physical melee) + * @return The modified damage to apply (unchanged if source is invalid) */ public final float onDefend(EntityLivingBase attacker, DamageSource source, float amount) { if (!isDefending()) { @@ -112,8 +116,7 @@ public abstract class AbilityDefend extends Ability implements IAbilityDefend { return amount; } - // Only react to physical melee damage - if (source.isMagicDamage() || source.isFireDamage() || source.isExplosion() || source.isProjectile()) { + if (!isValidDamageSource(source)) { return amount; } @@ -149,7 +152,8 @@ public abstract class AbilityDefend extends Ability implements IAbilityDefend { } /** - * Subclass-specific defend behavior. Called only for physical melee hits while defending. + * Subclass-specific defend behavior. Called only for valid hits while defending + * (as determined by {@link #isValidDamageSource}). * * @param attacker The entity that hit the caster * @param amount The incoming damage @@ -157,6 +161,15 @@ public abstract class AbilityDefend extends Ability implements IAbilityDefend { */ protected abstract float performDefend(EntityLivingBase attacker, float amount); + /** + * Determines whether this defend ability reacts to the given damage source. + * Default implementation accepts only physical melee damage (rejects magic, fire, explosion, projectile). + * Subclasses can override to accept additional damage types (e.g. Guard accepts all). + */ + protected boolean isValidDamageSource(DamageSource source) { + return !source.isMagicDamage() && !source.isFireDamage() && !source.isExplosion() && !source.isProjectile(); + } + // ═══════════════════════════════════════════════════════════════════ // SUBCLASS HOOKS // ═══════════════════════════════════════════════════════════════════ diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityGuard.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityGuard.java index 636c02f3c..62d0dc1e1 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityGuard.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityGuard.java @@ -5,6 +5,7 @@ import cpw.mods.fml.relauncher.SideOnly; import kamkeel.npcs.controllers.data.ability.enums.UserType; import net.minecraft.entity.EntityLivingBase; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.DamageSource; import noppes.npcs.api.ability.type.IAbilityGuard; import noppes.npcs.client.gui.builder.FieldDef; @@ -33,6 +34,14 @@ public class AbilityGuard extends AbilityDefend implements IAbilityGuard { // DEFEND HOOKS // ═══════════════════════════════════════════════════════════════════ + /** + * Guard accepts ALL damage types (melee, projectile, magic, fire, explosion). + */ + @Override + protected boolean isValidDamageSource(DamageSource source) { + return true; + } + @Override protected float performDefend(EntityLivingBase attacker, float amount) { return Math.max(0, amount * (1.0f - damageReduction));