Add DBC ability damage handling and GUI integration with new Damage Handler Registry Systems

This commit is contained in:
Kam committed 2026-02-04 17:45:02 -05:00
1 parent ed386677ee
commit a13791c610
17 files changed
+201 -14

No files matched your search

@@ -138,6 +138,16 @@ public abstract class Ability implements IAbility {
// OPTIONAL OVERRIDES
// ═══════════════════════════════════════════════════════════════════
/**
* Returns true if this ability type deals damage.
* Override in non-damaging subclasses to return false.
* Used by external mods to determine whether to show
* damage-related configuration (e.g., DBC stats tab).
*/
public boolean hasDamage() {
return true;
}
public void onWindUpTick(EntityLivingBase caster, EntityLivingBase target, World world, int tick) {
}
@@ -247,12 +257,22 @@ public abstract class Ability implements IAbility {
// Apply damage
if (damage > 0) {
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);
// Check for external damage handler first (e.g., DBC Addon)
IAbilityDamageHandler handler = AbilityController.Instance.getDamageHandler();
boolean handled = false;
if (handler != null) {
handled = handler.handleDamage(this, caster, hitEntity, damage, knockback, knockbackUp,
knockbackDirX, knockbackDirZ);
}
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);
}
}
}
@@ -483,6 +503,11 @@ public abstract class Ability implements IAbility {
}
}
// External field providers (e.g., DBC Addon injecting a "DBC" tab)
for (IAbilityFieldProvider provider : AbilityController.Instance.getFieldProviders()) {
provider.addFieldDefinitions(this, defs);
}
return defs;
}
@@ -39,6 +39,12 @@ public class AbilityController implements IAbilityHandler {
* Used by AbilitySlot for cache invalidation. */
private int version = 0;
/** External damage handler (e.g., DBC Addon). */
private IAbilityDamageHandler damageHandler = null;
/** External field providers for ability GUI (e.g., DBC Addon). Client-side only. */
private final List<IAbilityFieldProvider> fieldProviders = new ArrayList<>();
public AbilityController() {
registerBuiltinTypes();
}
@@ -386,4 +392,39 @@ public class AbilityController implements IAbilityHandler {
registerType("cnpc:hazard", AbilityHazard::new);
registerType("cnpc:trap", AbilityTrap::new);
}
// ═══════════════════════════════════════════════════════════════════════════
// EXTERNAL DAMAGE HANDLER
// ═══════════════════════════════════════════════════════════════════════════
/**
* Register an external damage handler for abilities.
* When set, the handler is called before default damage application.
* If the handler returns true, default damage is skipped.
*/
public void registerDamageHandler(IAbilityDamageHandler handler) {
this.damageHandler = handler;
}
/** Get the registered damage handler, or null if none. */
public IAbilityDamageHandler getDamageHandler() {
return damageHandler;
}
// ═══════════════════════════════════════════════════════════════════════════
// EXTERNAL FIELD PROVIDERS
// ═══════════════════════════════════════════════════════════════════════════
/**
* Register an external field provider for ability GUIs.
* Providers are called during getAllDefinitions() to inject custom tabs/fields.
*/
public void registerFieldProvider(IAbilityFieldProvider provider) {
fieldProviders.add(provider);
}
/** Get all registered field providers. */
public List<IAbilityFieldProvider> getFieldProviders() {
return fieldProviders;
}
}
@@ -0,0 +1,27 @@
package kamkeel.npcs.controllers.data.ability;
import net.minecraft.entity.EntityLivingBase;
/**
* External damage handler for abilities.
* When registered, called AFTER script events but BEFORE default attackEntityFrom.
* If handleDamage returns true, default damage is skipped.
*/
public interface IAbilityDamageHandler {
/**
* Handle damage from an ability.
*
* @param ability The ability dealing damage
* @param caster The entity executing the ability
* @param target The entity being hit
* @param damage The damage amount (after script event modifications)
* @param knockback The horizontal knockback
* @param knockbackUp The vertical knockback
* @param knockbackDirX The X component of knockback direction
* @param knockbackDirZ The Z component of knockback direction
* @return true if damage was handled (skip default), false to use default damage
*/
boolean handleDamage(Ability ability, EntityLivingBase caster, EntityLivingBase target,
float damage, float knockback, float knockbackUp,
double knockbackDirX, double knockbackDirZ);
}
@@ -0,0 +1,25 @@
package kamkeel.npcs.controllers.data.ability;
import noppes.npcs.client.gui.builder.FieldDef;
import java.util.List;
/**
* External field definition provider for abilities.
* Called during getAllDefinitions() to allow mods to inject custom tabs/fields
* into the ability configuration GUI.
* <p>
* Note: Although this interface references FieldDef (client-only), it is safe to
* register on both sides because the generic type is erased at bytecode level.
* The addFieldDefinitions method is only ever called from client-side GUI code.
*/
public interface IAbilityFieldProvider {
/**
* Add field definitions to the ability's GUI.
* Fields added here should use .tab() to assign them to a custom tab.
*
* @param ability The ability being configured
* @param defs The mutable list of field definitions to add to
*/
void addFieldDefinitions(Ability ability, List<FieldDef> defs);
}
@@ -109,6 +109,7 @@ public class AbilityBeam extends Ability implements IAbilityEnergyBeam {
beamEntity.setupCharging(anchorData, windUpTicks, offsetDist);
beamEntity.setEffects(this.effects);
beamEntity.setSourceAbility(this);
world.spawnEntityInWorld(beamEntity);
}
}
@@ -137,6 +137,8 @@ public class AbilityBeamDual extends Ability {
beamEntity.setEffects(this.effects);
if (dualFire) beamEntity2.setEffects(this.effects);
beamEntity.setSourceAbility(this);
beamEntity2.setSourceAbility(this);
world.spawnEntityInWorld(beamEntity);
world.spawnEntityInWorld(beamEntity2);
}
@@ -111,6 +111,11 @@ public class AbilityDash extends Ability implements IAbilityDash {
this.activeSound = "mob.endermen.portal";
}
@Override
public boolean hasDamage() {
return false;
}
@Override
public boolean isTargetingModeLocked() {
return true;
@@ -110,6 +110,7 @@ public class AbilityDisc extends Ability implements IAbilityDisc {
discEntity.setupCharging(anchorData, windUpTicks);
discEntity.setEffects(this.effects);
discEntity.setSourceAbility(this);
world.spawnEntityInWorld(discEntity);
}
}
@@ -146,6 +146,8 @@ public class AbilityDiscDual extends Ability {
discEntity2.setEffects(this.effects);
}
discEntity.setSourceAbility(this);
discEntity2.setSourceAbility(this);
world.spawnEntityInWorld(discEntity);
world.spawnEntityInWorld(discEntity2);
}
@@ -65,6 +65,11 @@ public class AbilityGuard extends Ability implements IAbilityGuard {
this.counterAnimationName = "Ability_Guard_Counter";
}
@Override
public boolean hasDamage() {
return false;
}
public enum CounterType {
FLAT,
PERCENT;
@@ -58,6 +58,11 @@ public class AbilityHeal extends Ability implements IAbilityHeal {
this.showTelegraph = false;
}
@Override
public boolean hasDamage() {
return false;
}
@Override
public boolean isTargetingModeLocked() {
return true;
@@ -99,6 +99,7 @@ public class AbilityLaserShot extends Ability implements IAbilityLaserShot {
laserEntity.setupCharging(anchorData, windUpTicks);
laserEntity.setEffects(this.effects);
laserEntity.setSourceAbility(this);
world.spawnEntityInWorld(laserEntity);
}
}
@@ -104,6 +104,7 @@ public class AbilityOrb extends Ability implements IAbilityOrb {
orbEntity.setupCharging(anchorData, windUpTicks);
orbEntity.setEffects(this.effects);
orbEntity.setSourceAbility(this);
world.spawnEntityInWorld(orbEntity);
}
}
@@ -129,6 +129,7 @@ public class AbilityOrbBarrage extends Ability {
);
orbEntity.setupCharging(anchorData[i], windUpTicks);
orbEntity.setSourceAbility(this);
chargingEntities[i] = orbEntity;
world.spawnEntityInWorld(orbEntity);
@@ -179,6 +180,7 @@ public class AbilityOrbBarrage extends Ability {
orbSize, colorData, combatData, homingData, lightningData, lifespanData, trajectoryData
);
orb.setSourceAbility(this);
world.spawnEntityInWorld(orb);
orbEntities.add(orb);
@@ -133,6 +133,8 @@ public class AbilityOrbDual extends Ability {
orbEntity2.setEffects(this.effects);
}
orbEntity.setSourceAbility(this);
orbEntity2.setSourceAbility(this);
world.spawnEntityInWorld(orbEntity);
world.spawnEntityInWorld(orbEntity2);
}
@@ -84,6 +84,11 @@ public class AbilityTeleport extends Ability implements IAbilityTeleport {
this.activeSound = "mob.endermen.portal";
}
@Override
public boolean hasDamage() {
return false;
}
@Override
public boolean isTargetingModeLocked() {
return true;
@@ -4,8 +4,11 @@ import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import kamkeel.npcs.controllers.data.ability.Ability;
import kamkeel.npcs.controllers.data.ability.AbilityController;
import kamkeel.npcs.controllers.data.ability.AbilityEffect;
import kamkeel.npcs.controllers.data.ability.AnchorPoint;
import kamkeel.npcs.controllers.data.ability.IAbilityDamageHandler;
import kamkeel.npcs.controllers.data.ability.data.*;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
@@ -77,6 +80,9 @@ public abstract class EntityAbilityProjectile extends Entity implements IEnergyP
protected boolean previewMode = false; // Client-side preview mode (no damage/effects)
protected EntityLivingBase previewOwner = null; // Direct reference for GUI preview (no world lookup)
/** The ability that spawned this projectile. Transient, not saved to NBT. */
protected transient Ability sourceAbility = null;
// ==================== ROTATION INTERPOLATION ====================
public float prevRotationValX, prevRotationValY, prevRotationValZ;
public float rotationValX, rotationValY, rotationValZ;
@@ -322,14 +328,30 @@ public abstract class EntityAbilityProjectile extends Entity implements IEnergyP
if (previewMode) return; // Skip damage in preview mode
Entity owner = getOwnerEntity();
if (owner instanceof EntityNPCInterface) {
target.attackEntityFrom(new NpcDamageSource("npc_ability", (EntityNPCInterface) owner), dmg);
} else if (owner instanceof EntityPlayer) {
target.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) owner), dmg);
} else if (owner instanceof EntityLivingBase) {
target.attackEntityFrom(DamageSource.causeMobDamage((EntityLivingBase) owner), dmg);
} else {
target.attackEntityFrom(new NpcDamageSource("npc_ability", null), dmg);
// Check for external damage handler (e.g., DBC Addon)
boolean handled = false;
if (sourceAbility != null && owner instanceof EntityLivingBase) {
IAbilityDamageHandler handler = AbilityController.Instance.getDamageHandler();
if (handler != null) {
double dx = target.posX - posX;
double dz = target.posZ - posZ;
float kbUp = getKnockbackUp() > 0 ? getKnockbackUp() : 0.1f;
handled = handler.handleDamage(sourceAbility, (EntityLivingBase) owner, target,
dmg, kb, kbUp, dx, dz);
}
}
if (!handled) {
// Default damage path
if (owner instanceof EntityNPCInterface) {
target.attackEntityFrom(new NpcDamageSource("npc_ability", (EntityNPCInterface) owner), dmg);
} else if (owner instanceof EntityPlayer) {
target.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) owner), dmg);
} else if (owner instanceof EntityLivingBase) {
target.attackEntityFrom(DamageSource.causeMobDamage((EntityLivingBase) owner), dmg);
} else {
target.attackEntityFrom(new NpcDamageSource("npc_ability", null), dmg);
}
}
if (kb > 0) {
@@ -361,6 +383,21 @@ public abstract class EntityAbilityProjectile extends Entity implements IEnergyP
this.effects = effects != null ? effects : new ArrayList<>();
}
/**
* Set the source ability that spawned this projectile.
* Used by external damage handlers to access ability-specific data.
*/
public void setSourceAbility(Ability ability) {
this.sourceAbility = ability;
}
/**
* Get the source ability that spawned this projectile.
*/
public Ability getSourceAbility() {
return sourceAbility;
}
protected void doExplosion() {
if (previewMode) return; // Skip explosion in preview mode
worldObj.playSoundEffect(posX, posY, posZ, "random.explode", 1.0f, 1.0f);