diff --git a/src/api b/src/api index f969b9f54..22135344e 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit f969b9f5403836489c815cef025d0a55b821eaf3 +Subproject commit 22135344e85a368af2cacc622bc7f50f32505b72 diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/Ability.java b/src/main/java/kamkeel/npcs/controllers/data/ability/Ability.java index 70e286298..270d4ede7 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/Ability.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/Ability.java @@ -85,6 +85,7 @@ public abstract class Ability implements IAbility, IAbilityAction { // Interruption protected boolean interruptible = true; protected InvulnerableMode invulnerableMode = InvulnerableMode.NONE; + protected boolean ignoreIFrames = false; // Feedback protected LockMode lockMovement = LockMode.WINDUP; @@ -365,22 +366,11 @@ public abstract class Ability implements IAbility, IAbilityAction { return true; } - public void onWindUpTick(EntityLivingBase caster, EntityLivingBase target, int tick) { - } + public void onWindUpTick(EntityLivingBase caster, EntityLivingBase target, int tick) {} - /** - * Whether this execution is a burst refire (not the first execution). - * Useful in onExecute() to detect when windup was skipped and entities need fresh creation. - */ - public boolean isBurstRefire() { - return burstEnabled && burstIndex > 0; - } + public void onInterrupt(EntityLivingBase caster, DamageSource source, float damage) {} - public void onInterrupt(EntityLivingBase caster, DamageSource source, float damage) { - } - - public void onComplete(EntityLivingBase caster, EntityLivingBase target) { - } + public void onComplete(EntityLivingBase caster, EntityLivingBase target) {} /** * Called when the ability enters BURST_DELAY between burst iterations. @@ -409,24 +399,6 @@ public abstract class Ability implements IAbility, IAbilityAction { return applyAbilityDamageInternal(caster, hitEntity, damage, knockback, 0.0f, dx, dz); } - /** - * Apply damage to an entity with ability hit event support and vertical knockback. - * Fires the abilityHit script event, allowing scripts to modify or cancel the damage. - * - * @param caster The entity executing the ability (NPC or Player) - * @param hitEntity The entity being hit - * @param damage The damage amount - * @param knockback The horizontal knockback - * @param knockbackUp The vertical knockback - * @return true if damage was applied (not cancelled), false if cancelled - */ - protected boolean applyAbilityDamage(EntityLivingBase caster, EntityLivingBase hitEntity, - float damage, float knockback, float knockbackUp) { - double dx = hitEntity.posX - caster.posX; - double dz = hitEntity.posZ - caster.posZ; - return applyAbilityDamageInternal(caster, hitEntity, damage, knockback, knockbackUp, dx, dz); - } - /** * Apply damage to an entity with ability hit event support and custom knockback direction. * Fires the abilityHit script event, allowing scripts to modify or cancel the damage. @@ -445,6 +417,28 @@ public abstract class Ability implements IAbility, IAbilityAction { return applyAbilityDamageInternal(caster, hitEntity, damage, knockback, 0.0f, knockbackDirX, knockbackDirZ); } + /** + * Clears hurt resistance before damage and returns the previous value so it can be restored later. + */ + public static int clearHurtResistanceIfNeeded(EntityLivingBase target, boolean ignoreIFrames) { + if (!ignoreIFrames || target == null) { + return -1; + } + int previous = target.hurtResistantTime; + target.hurtResistantTime = 0; + return previous; + } + + /** + * Restores hurt resistance after damage when {@link #clearHurtResistanceIfNeeded} was used. + */ + public static void restoreHurtResistanceIfNeeded(EntityLivingBase target, boolean ignoreIFrames, int previous) { + if (!ignoreIFrames || target == null || previous < 0) { + return; + } + target.hurtResistantTime = previous; + } + /** * Internal unified damage application method. * All public damage methods delegate to this. @@ -470,19 +464,24 @@ public abstract class Ability implements IAbility, IAbilityAction { // Apply damage if (damage > 0) { - // Check for ability extenders (e.g., DBC Addon damage routing) - boolean handled = AbilityController.Instance.fireOnAbilityDamage( - this, caster, hitEntity, damage, knockback, knockbackUp, - knockbackDirX, knockbackDirZ, 1.0f); - if (!handled) { - // Default damage path - if (caster instanceof EntityNPCInterface) { - hitEntity.attackEntityFrom(new NpcDamageSource("mob", (EntityNPCInterface) caster), damage); - } else if (caster instanceof EntityPlayer) { - hitEntity.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) caster), damage); - } else { - hitEntity.attackEntityFrom(DamageSource.causeMobDamage(caster), damage); + int previousHurtResistantTime = clearHurtResistanceIfNeeded(hitEntity, ignoreIFrames); + try { + // Check for ability extenders (e.g., DBC Addon damage routing) + boolean handled = AbilityController.Instance.fireOnAbilityDamage( + this, caster, hitEntity, damage, knockback, knockbackUp, + knockbackDirX, knockbackDirZ, 1.0f); + if (!handled) { + // Default damage path + if (caster instanceof EntityNPCInterface) { + hitEntity.attackEntityFrom(new NpcDamageSource("mob", (EntityNPCInterface) caster), damage); + } else if (caster instanceof EntityPlayer) { + hitEntity.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) caster), damage); + } else { + hitEntity.attackEntityFrom(DamageSource.causeMobDamage(caster), damage); + } } + } finally { + restoreHurtResistanceIfNeeded(hitEntity, ignoreIFrames, previousHurtResistantTime); } } @@ -591,14 +590,6 @@ public abstract class Ability implements IAbility, IAbilityAction { return null; } - /** - * Returns true if the telegraph type for this ability is locked and cannot be changed. - * Telegraph type is inherent to how the ability works (e.g., Charge uses LINE, Slam uses CIRCLE). - */ - public boolean isTelegraphTypeLocked() { - return true; - } - /** * Add field definitions for this ability's GUI. * Override in subclasses to add type-specific fields. The list already contains @@ -716,6 +707,10 @@ public abstract class Ability implements IAbility, IAbilityAction { }) .hover("ability.hover.invulnerable") .tab("General")); + defs.add(FieldDef.boolField("ability.ignoreIFrames", this::isIgnoreIFrames, this::setIgnoreIFrames) + .hover("ability.hover.ignoreIFrames") + .visibleWhen(this::hasDamage) + .tab("General")); // ── Burst section ──────────────────────────────────────────── if (allowBurst()) { @@ -1035,43 +1030,6 @@ public abstract class Ability implements IAbility, IAbilityAction { return startY - 0.5; } - /** - * Calculates offset position near the given coordinates. - * Used to place effects near a target rather than exactly on them. - * - * @param baseX Base X coordinate - * @param baseY Base Y coordinate - * @param baseZ Base Z coordinate - * @param minOffset Minimum offset distance - * @param maxOffset Maximum offset distance - * @param randomOffset Whether to use random offset within range, or fixed at max - * @param random Random instance to use - * @return Array of [x, y, z] with offset applied - */ - public static double[] calculateOffsetPosition(double baseX, double baseY, double baseZ, - float minOffset, float maxOffset, - boolean randomOffset, java.util.Random random) { - if (maxOffset <= 0) { - return new double[]{baseX, baseY, baseZ}; - } - - double offsetDist; - double offsetAngle; - - if (randomOffset) { - offsetDist = minOffset + random.nextDouble() * (maxOffset - minOffset); - offsetAngle = random.nextDouble() * Math.PI * 2; - } else { - offsetDist = maxOffset; - offsetAngle = random.nextDouble() * Math.PI * 2; - } - - double offsetX = Math.cos(offsetAngle) * offsetDist; - double offsetZ = Math.sin(offsetAngle) * offsetDist; - - return new double[]{baseX + offsetX, baseY, baseZ + offsetZ}; - } - /** * Get the current telegraph instances. */ @@ -1426,6 +1384,7 @@ public abstract class Ability implements IAbility, IAbilityAction { nbt.setInteger("recovery", dazedTicks); nbt.setBoolean("interruptible", interruptible); nbt.setInteger("invulnerableMode", invulnerableMode.ordinal()); + nbt.setBoolean("ignoreIFrames", ignoreIFrames); nbt.setInteger("lockMovement", lockMovement.ordinal()); nbt.setInteger("rotationMode", rotationMode.ordinal()); nbt.setInteger("rotationPhase", rotationPhase.ordinal()); @@ -1519,6 +1478,7 @@ public abstract class Ability implements IAbility, IAbilityAction { invulnerableMode = nbt.hasKey("invulnerableMode") ? InvulnerableMode.fromOrdinal(nbt.getInteger("invulnerableMode")) : InvulnerableMode.NONE; + ignoreIFrames = nbt.hasKey("ignoreIFrames") && nbt.getBoolean("ignoreIFrames"); lockMovement = LockMode.fromOrdinal(nbt.getInteger("lockMovement")); rotationMode = RotationMode.fromOrdinal(nbt.getInteger("rotationMode")); rotationPhase = LockMode.fromOrdinal(nbt.getInteger("rotationPhase")); @@ -1823,6 +1783,16 @@ public abstract class Ability implements IAbility, IAbilityAction { return invulnerableMode.invulnerableDuringActive(); } + @Override + public boolean isIgnoreIFrames() { + return ignoreIFrames; + } + + @Override + public void setIgnoreIFrames(boolean ignore) { + this.ignoreIFrames = ignore; + } + public LockMode getLockMovement() { return lockMovement; } 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));
diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityHazard.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityHazard.java
index 23ff298db..a37df738e 100644
--- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityHazard.java
+++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityHazard.java
@@ -20,7 +20,6 @@ public class AbilityHazard extends AbilityZone implements IAbilityHazard {
private float radius = 2.0f;
private float damagePerSecond = 1.0f;
private int damageInterval = 20;
- private boolean ignoreInvulnFrames = false;
private boolean affectsCaster = false;
public AbilityHazard() {
@@ -75,7 +74,7 @@ public class AbilityHazard extends AbilityZone implements IAbilityHazard {
zoneShape,
radius,
damagePerSecond, damageInterval,
- ignoreInvulnFrames, affectsCaster,
+ isIgnoreIFrames(), affectsCaster,
durationTicks,
colorData.innerColor, colorData.outerColor, colorData.outerColorEnabled,
zoneHeight,
@@ -99,7 +98,6 @@ public class AbilityHazard extends AbilityZone implements IAbilityHazard {
nbt.setFloat("radius", radius);
nbt.setFloat("damagePerSecond", damagePerSecond);
nbt.setInteger("damageInterval", damageInterval);
- nbt.setBoolean("ignoreInvulnFrames", ignoreInvulnFrames);
nbt.setBoolean("affectsCaster", affectsCaster);
}
@@ -109,7 +107,6 @@ public class AbilityHazard extends AbilityZone implements IAbilityHazard {
this.radius = nbt.getFloat("radius");
this.damagePerSecond = nbt.getFloat("damagePerSecond");
this.damageInterval = nbt.getInteger("damageInterval");
- this.ignoreInvulnFrames = nbt.getBoolean("ignoreInvulnFrames");
this.affectsCaster = nbt.getBoolean("affectsCaster");
}
@@ -137,14 +134,6 @@ public class AbilityHazard extends AbilityZone implements IAbilityHazard {
this.damageInterval = damageInterval;
}
- public boolean isIgnoreInvulnFrames() {
- return ignoreInvulnFrames;
- }
-
- public void setIgnoreInvulnFrames(boolean ignoreInvulnFrames) {
- this.ignoreInvulnFrames = ignoreInvulnFrames;
- }
-
public boolean isAffectsCaster() {
return affectsCaster;
}
@@ -176,7 +165,6 @@ public class AbilityHazard extends AbilityZone implements IAbilityHazard {
FieldDef.floatField("gui.dps", this::getDamagePerSecond, this::setDamagePerSecond),
FieldDef.intField("gui.interval", this::getDamageInterval, this::setDamageInterval)
),
- FieldDef.boolField("ability.ignoreInvulnFrames", this::isIgnoreInvulnFrames, this::setIgnoreInvulnFrames),
FieldDef.boolField("ability.affectsCaster", this::isAffectsCaster, this::setAffectsCaster)
.hover("ability.hover.affectsCaster"),
AbilityFieldDefs.effectsListField("ability.effects", this::getEffects, this::setEffects)
diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityTrap.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityTrap.java
index 21b5ff0e7..1ed357d94 100644
--- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityTrap.java
+++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityTrap.java
@@ -80,6 +80,7 @@ public class AbilityTrap extends AbilityZone implements IAbilityTrap {
zoneShape,
triggerRadius, armTime, maxTriggers, triggerCooldown,
damage, damageRadius, knockback, durationTicks,
+ isIgnoreIFrames(),
colorData.innerColor, colorData.outerColor, colorData.outerColorEnabled,
zoneHeight,
particleDensity, particleScale, animSpeed, lightningDensity,
diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityVortex.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityVortex.java
index d6d813a63..03c54ef71 100644
--- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityVortex.java
+++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityVortex.java
@@ -263,7 +263,6 @@ public class AbilityVortex extends Ability implements IAbilityVortex {
state.lastZ = entity.posZ;
if (shouldDealPullDamage) {
- entity.hurtResistantTime = 0;
applyAbilityDamage(caster, entity, pullDamage * 0.5f, 0);
}
}
diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/energy/AbilityEnergyProjectile.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/energy/AbilityEnergyProjectile.java
index 80dfb8a9b..0e08fab02 100644
--- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/energy/AbilityEnergyProjectile.java
+++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/energy/AbilityEnergyProjectile.java
@@ -212,6 +212,7 @@ public abstract class AbilityEnergyProjectile