Scale melee damage dealt to barriers

Barriers are plain entities, so no LivingHurtEvent fires for them and nothing
scaled an incoming melee hit - vanilla handed over the bare attackDamage
attribute and a dome took one point per swing however strong the attacker was.
Attributes now apply, and modifyBarrierMeleeDamage gives addons the same seam
they already have for barrier health.
This commit is contained in:
KAMKEEL committed 2026-08-11 03:43:38 -04:00
1 parent 6477ede022
commit 4341c15cf4
3 files changed
+43 -1

No files matched your search

@@ -46,6 +46,7 @@ import noppes.npcs.controllers.data.AbilityScript;
import noppes.npcs.controllers.data.ChainedAbilityScript;
import net.minecraft.entity.EntityLivingBase;
import kamkeel.npcs.controllers.sync.handlers.PlayerAbilitySyncHelper;
import kamkeel.npcs.entity.EntityEnergyBarrier;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
@@ -1381,6 +1382,17 @@ public class AbilityController implements IAbilityHandler {
return health;
}
/**
* Fire modifyBarrierMeleeDamage on all extenders. Cumulative — each extender's output feeds the next.
*/
public float fireModifyBarrierMeleeDamage(EntityEnergyBarrier barrier, EntityLivingBase attacker, float baseDamage) {
float damage = baseDamage;
for (IAbilityExtender ext : extenders) {
damage = ext.modifyBarrierMeleeDamage(barrier, attacker, damage);
}
return damage;
}
/**
* Fire onAbilityHeal on all extenders. Chain of responsibility — first true wins.
*/
@@ -3,6 +3,7 @@ package kamkeel.npcs.controllers.data.ability.extender;
import kamkeel.npcs.controllers.data.ability.conditions.AbilityCondition;
import kamkeel.npcs.controllers.data.ability.enums.AbilityPhase;
import kamkeel.npcs.controllers.data.ability.Ability;
import kamkeel.npcs.entity.EntityEnergyBarrier;
import net.minecraft.entity.EntityLivingBase;
/**
@@ -108,6 +109,21 @@ public interface IAbilityExtender {
return baseHealth;
}
/**
* Called when a barrier entity takes a melee hit, allowing extenders to scale the damage.
* A barrier is a plain Entity, so no LivingHurtEvent fires for it and an extender has no
* other opportunity to scale melee against it the way it scales {@link #modifyBarrierHealth}.
* Cumulative: all extenders apply in sequence, each receiving the previous output.
*
* @param barrier The barrier being hit
* @param attacker The entity dealing the hit
* @param baseDamage The damage after the barrier's own melee multiplier
* @return The modified damage value
*/
default float modifyBarrierMeleeDamage(EntityEnergyBarrier barrier, EntityLivingBase attacker, float baseDamage) {
return baseDamage;
}
/**
* Called when an ability is about to heal an entity.
* Return true to handle the healing (skip default entity.heal()).
@@ -1,5 +1,7 @@
package kamkeel.npcs.entity;
import kamkeel.npcs.addon.DBCAddon;
import kamkeel.npcs.controllers.AbilityController;
import kamkeel.npcs.controllers.data.ability.util.AbilityTargetHelper;
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyBarrierData;
import kamkeel.npcs.network.packets.data.energy.BarrierClientSyncPacket;
@@ -15,6 +17,7 @@ import net.minecraft.util.DamageSource;
import net.minecraft.world.World;
import noppes.npcs.CustomNpcs;
import noppes.npcs.EventHooks;
import noppes.npcs.config.ConfigMain;
import noppes.npcs.controllers.data.MagicData;
import noppes.npcs.controllers.data.PlayerData;
import noppes.npcs.entity.EntityNPCInterface;
@@ -438,8 +441,19 @@ public abstract class EntityEnergyBarrier extends EntityEnergyAbility {
float damage = amount * barrierData.meleeDamageMultiplier;
// Apply magic interactions from attacker's magic vs barrier's magic
Entity attacker = source.getEntity();
// A barrier is a plain Entity, so no LivingHurtEvent fires for it and nothing scales the
// hit the way it would against a living target - vanilla hands us the bare attackDamage
// attribute. Run the scaling here instead, or the barrier only ever takes a point of it.
if (attacker instanceof EntityLivingBase) {
damage = AbilityController.Instance.fireModifyBarrierMeleeDamage(this, (EntityLivingBase) attacker, damage);
}
if (attacker instanceof EntityPlayer && ConfigMain.AttributesEnabled && !DBCAddon.IsAvailable()) {
damage = AttributeAttackUtil.calculateOutgoing((EntityPlayer) attacker, damage);
}
// Apply magic interactions from attacker's magic vs barrier's magic
if (attacker != null) {
MagicData attackerMagic = null;
if (attacker instanceof EntityPlayer) {