Add attack speed check to NPC's attackEntityFrom before immunity check

The LivingAttackEvent handler was firing too late for NPCs because
EntityNPCInterface.attackEntityFrom() has its own immunity check that
runs BEFORE calling super (which fires LivingAttackEvent).

Now the attack speed bypass is checked directly in the NPC's
attackEntityFrom() method, before the immunity check at line 658.
This commit is contained in:
Claude committed 2025-12-31 01:00:33 +00:00
1 parent d06e680350
commit 9b654621e8
1 file changed
+17
@@ -159,6 +159,7 @@ import noppes.npcs.roles.RoleInterface;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.entity.ScriptNpc;
import noppes.npcs.scripted.event.NpcEvent;
import noppes.npcs.scripted.item.ScriptCustomizableItem;
import noppes.npcs.util.GameProfileAlt;
import noppes.npcs.util.NPCMountUtil;
@@ -638,6 +639,22 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
reset();
}
// Check for custom weapon attack speed - bypass immunity if enough time has passed
Entity sourceEntity = damagesource.getEntity();
if (sourceEntity instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) sourceEntity;
ItemStack heldItem = player.getHeldItem();
if (heldItem != null) {
IItemStack itemStack = NpcAPI.Instance().getIItemStack(heldItem);
if (itemStack instanceof ScriptCustomizableItem) {
int attackSpeed = ((ScriptCustomizableItem) itemStack).getAttackSpeed();
if (this.hurtResistantTime <= this.maxHurtResistantTime - attackSpeed) {
this.hurtResistantTime = 0;
}
}
}
}
if ((float) this.hurtResistantTime > (float) this.maxHurtResistantTime / 2.0F && i <= this.lastDamage)
return false;