Remove all Legacy Ability Content, cleanup API.

- Add Script Tab to Abilities
- Add Custom Ability
- Add Icon Support for Abilities / Default Icon Support
- Remove Icon Tab and throw it into Effects with allowed Override
- Removed Deprecated API Sources
This commit is contained in:
Kam committed 2026-02-27 16:43:35 -05:00
1 parent 936dc7f0cc
commit 675c4ef4f9
50 files changed
+1488 -938

No files matched your search

@@ -8,22 +8,48 @@ import noppes.npcs.api.IDamageSource;
import noppes.npcs.api.ability.IAbility;
import noppes.npcs.api.entity.ICustomNpc;
import noppes.npcs.api.entity.IEntityLivingBase;
import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.api.event.IAbilityEvent;
import noppes.npcs.constants.EnumScriptType;
import noppes.npcs.scripted.NpcAPI;
/**
* Events fired during NPC ability execution lifecycle.
* Unified ability events for both NPCs and Players.
*/
public class AbilityEvent extends NpcEvent implements IAbilityEvent {
public class AbilityEvent extends CustomNPCsEvent implements IAbilityEvent {
protected final IEntityLivingBase entity;
public final IPlayer player;
public final ICustomNpc<?> npc;
protected final Ability ability;
protected final IEntityLivingBase target;
private transient IAbility abilityCopy;
public AbilityEvent(ICustomNpc npc, Ability ability, EntityLivingBase target) {
super(npc);
public AbilityEvent(EntityLivingBase entity, Ability ability, EntityLivingBase target) {
this.entity = entity != null ? (IEntityLivingBase) NpcAPI.Instance().getIEntity(entity) : null;
this.ability = ability;
this.target = target != null ? (IEntityLivingBase) NpcAPI.Instance().getIEntity(target) : null;
this.player = (this.entity instanceof IPlayer) ? (IPlayer) this.entity : null;
this.npc = (this.entity instanceof ICustomNpc) ? (ICustomNpc<?>) this.entity : null;
}
@Override
public IEntityLivingBase getEntity() {
return entity;
}
@Override
public IPlayer getPlayer() {
return player;
}
@Override
public ICustomNpc<?> getNpc() {
return npc;
}
@Override
public boolean isNPC() {
return entity instanceof ICustomNpc;
}
@Override
@@ -44,13 +70,10 @@ public class AbilityEvent extends NpcEvent implements IAbilityEvent {
return "abilityEvent";
}
/**
* Fired when an ability starts executing (enters WINDUP phase).
*/
@Cancelable
public static class StartEvent extends AbilityEvent implements IAbilityEvent.StartEvent {
public StartEvent(ICustomNpc npc, Ability ability, EntityLivingBase target) {
super(npc, ability, target);
public StartEvent(EntityLivingBase entity, Ability ability, EntityLivingBase target) {
super(entity, ability, target);
}
@Override
@@ -59,13 +82,10 @@ public class AbilityEvent extends NpcEvent implements IAbilityEvent {
}
}
/**
* Fired when an ability enters the ACTIVE phase and performs its effect.
*/
@Cancelable
public static class ExecuteEvent extends AbilityEvent implements IAbilityEvent.ExecuteEvent {
public ExecuteEvent(ICustomNpc npc, Ability ability, EntityLivingBase target) {
super(npc, ability, target);
public ExecuteEvent(EntityLivingBase entity, Ability ability, EntityLivingBase target) {
super(entity, ability, target);
}
@Override
@@ -74,16 +94,13 @@ public class AbilityEvent extends NpcEvent implements IAbilityEvent {
}
}
/**
* Fired when an ability is interrupted by damage.
*/
public static class InterruptEvent extends AbilityEvent implements IAbilityEvent.InterruptEvent {
private final IDamageSource damageSource;
private final float damage;
public InterruptEvent(ICustomNpc npc, Ability ability, EntityLivingBase target, DamageSource source, float damage) {
super(npc, ability, target);
this.damageSource = NpcAPI.Instance().getIDamageSource(source);
public InterruptEvent(EntityLivingBase entity, Ability ability, EntityLivingBase target, DamageSource source, float damage) {
super(entity, ability, target);
this.damageSource = source != null ? NpcAPI.Instance().getIDamageSource(source) : null;
this.damage = damage;
}
@@ -103,12 +120,9 @@ public class AbilityEvent extends NpcEvent implements IAbilityEvent {
}
}
/**
* Fired when an ability completes its full execution cycle.
*/
public static class CompleteEvent extends AbilityEvent implements IAbilityEvent.CompleteEvent {
public CompleteEvent(ICustomNpc npc, Ability ability, EntityLivingBase target) {
super(npc, ability, target);
public CompleteEvent(EntityLivingBase entity, Ability ability, EntityLivingBase target) {
super(entity, ability, target);
}
@Override
@@ -117,10 +131,6 @@ public class AbilityEvent extends NpcEvent implements IAbilityEvent {
}
}
/**
* Fired when an ability hits an entity with damage.
* This is a cancelable event - canceling prevents the damage from being applied.
*/
@Cancelable
public static class HitEvent extends AbilityEvent implements IAbilityEvent.HitEvent {
private final IEntityLivingBase hitEntity;
@@ -128,9 +138,9 @@ public class AbilityEvent extends NpcEvent implements IAbilityEvent {
private float knockback;
private float knockbackUp;
public HitEvent(ICustomNpc npc, Ability ability, EntityLivingBase target,
public HitEvent(EntityLivingBase entity, Ability ability, EntityLivingBase target,
EntityLivingBase hitEntity, float damage, float knockback, float knockbackUp) {
super(npc, ability, target);
super(entity, ability, target);
this.hitEntity = hitEntity != null ? (IEntityLivingBase) NpcAPI.Instance().getIEntity(hitEntity) : null;
this.damage = damage;
this.knockback = knockback;
@@ -178,16 +188,12 @@ public class AbilityEvent extends NpcEvent implements IAbilityEvent {
}
}
/**
* Fired every tick while an ability is executing.
* Provides information about the current phase and tick.
*/
public static class TickEvent extends AbilityEvent implements IAbilityEvent.TickEvent {
private final int abilityPhase;
private final int tick;
public TickEvent(ICustomNpc npc, Ability ability, EntityLivingBase target, int phase, int tick) {
super(npc, ability, target);
public TickEvent(EntityLivingBase entity, Ability ability, EntityLivingBase target, int phase, int tick) {
super(entity, ability, target);
this.abilityPhase = phase;
this.tick = tick;
}
@@ -208,17 +214,13 @@ public class AbilityEvent extends NpcEvent implements IAbilityEvent {
}
}
/**
* Fired when a toggle ability changes state.
* Canceling prevents the toggle from changing state.
*/
@Cancelable
public static class ToggleEvent extends AbilityEvent implements IAbilityEvent.ToggleEvent {
private final int oldState;
private final int newState;
public ToggleEvent(ICustomNpc npc, Ability ability, int oldState, int newState) {
super(npc, ability, null);
public ToggleEvent(EntityLivingBase entity, Ability ability, int oldState, int newState) {
super(entity, ability, null);
this.oldState = oldState;
this.newState = newState;
}
@@ -244,17 +246,13 @@ public class AbilityEvent extends NpcEvent implements IAbilityEvent {
}
}
/**
* Fired every 10 ticks for each active toggle ability.
* Scripts can set enabled to false to force-deactivate.
*/
public static class ToggleUpdateEvent extends AbilityEvent implements IAbilityEvent.ToggleUpdateEvent {
private final int tick;
private final int state;
private boolean enabled = true;
public ToggleUpdateEvent(ICustomNpc npc, Ability ability, int tick, int state) {
super(npc, ability, null);
public ToggleUpdateEvent(EntityLivingBase entity, Ability ability, int tick, int state) {
super(entity, ability, null);
this.tick = tick;
this.state = state;
}
@@ -281,7 +279,7 @@ public class AbilityEvent extends NpcEvent implements IAbilityEvent {
@Override
public String getHookName() {
return EnumScriptType.ABILITY_TOGGLE_UPDATE.function;
return EnumScriptType.ABILITY_TOGGLE_TICK.function;
}
}
}
@@ -0,0 +1,134 @@
package noppes.npcs.scripted.event;
import kamkeel.npcs.controllers.data.ability.data.ChainedAbility;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.DamageSource;
import noppes.npcs.api.IDamageSource;
import noppes.npcs.api.ability.IChainedAbility;
import noppes.npcs.api.entity.ICustomNpc;
import noppes.npcs.api.entity.IEntityLivingBase;
import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.api.event.IChainEvent;
import noppes.npcs.constants.EnumScriptType;
import noppes.npcs.scripted.NpcAPI;
/**
* Unified chain events for both NPCs and Players.
*/
public class ChainEvent extends CustomNPCsEvent implements IChainEvent {
protected final IEntityLivingBase entity;
public final IPlayer player;
public final ICustomNpc<?> npc;
protected final ChainedAbility chain;
protected final IEntityLivingBase target;
protected final int entryIndex;
public ChainEvent(EntityLivingBase entity, ChainedAbility chain, int entryIndex, EntityLivingBase target) {
this.entity = entity != null ? (IEntityLivingBase) NpcAPI.Instance().getIEntity(entity) : null;
this.chain = chain;
this.entryIndex = entryIndex;
this.target = target != null ? (IEntityLivingBase) NpcAPI.Instance().getIEntity(target) : null;
this.player = (this.entity instanceof IPlayer) ? (IPlayer) this.entity : null;
this.npc = (this.entity instanceof ICustomNpc) ? (ICustomNpc<?>) this.entity : null;
}
@Override
public IEntityLivingBase getEntity() {
return entity;
}
@Override
public IPlayer getPlayer() {
return player;
}
@Override
public ICustomNpc<?> getNpc() {
return npc;
}
@Override
public boolean isNPC() {
return entity instanceof ICustomNpc;
}
@Override
public IChainedAbility getChain() {
return chain;
}
@Override
public IEntityLivingBase getTarget() {
return target;
}
@Override
public int getEntryIndex() {
return entryIndex;
}
@Override
public String getHookName() {
return "chainEvent";
}
public static class StartEvent extends ChainEvent implements IChainEvent.StartEvent {
public StartEvent(EntityLivingBase entity, ChainedAbility chain, int entryIndex, EntityLivingBase target) {
super(entity, chain, entryIndex, target);
}
@Override
public String getHookName() {
return EnumScriptType.CHAIN_START.function;
}
}
public static class NextEvent extends ChainEvent implements IChainEvent.NextEvent {
public NextEvent(EntityLivingBase entity, ChainedAbility chain, int entryIndex, EntityLivingBase target) {
super(entity, chain, entryIndex, target);
}
@Override
public String getHookName() {
return EnumScriptType.CHAIN_NEXT.function;
}
}
public static class CompleteEvent extends ChainEvent implements IChainEvent.CompleteEvent {
public CompleteEvent(EntityLivingBase entity, ChainedAbility chain, int entryIndex, EntityLivingBase target) {
super(entity, chain, entryIndex, target);
}
@Override
public String getHookName() {
return EnumScriptType.CHAIN_COMPLETE.function;
}
}
public static class InterruptEvent extends ChainEvent implements IChainEvent.InterruptEvent {
private final IDamageSource damageSource;
private final float damage;
public InterruptEvent(EntityLivingBase entity, ChainedAbility chain, int entryIndex, EntityLivingBase target,
DamageSource source, float damage) {
super(entity, chain, entryIndex, target);
this.damageSource = source != null ? NpcAPI.Instance().getIDamageSource(source) : null;
this.damage = damage;
}
@Override
public IDamageSource getDamageSource() {
return damageSource;
}
@Override
public float getDamage() {
return damage;
}
@Override
public String getHookName() {
return EnumScriptType.CHAIN_INTERRUPT.function;
}
}
}
@@ -1,286 +0,0 @@
package noppes.npcs.scripted.event.player;
import cpw.mods.fml.common.eventhandler.Cancelable;
import kamkeel.npcs.controllers.data.ability.Ability;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.DamageSource;
import noppes.npcs.api.IDamageSource;
import noppes.npcs.api.ability.IAbility;
import noppes.npcs.api.entity.IEntityLivingBase;
import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.api.event.IPlayerAbilityEvent;
import noppes.npcs.constants.EnumScriptType;
import noppes.npcs.scripted.NpcAPI;
/**
* Events fired during player ability execution lifecycle.
*/
public class PlayerAbilityEvent extends PlayerEvent implements IPlayerAbilityEvent {
protected final Ability ability;
protected final IEntityLivingBase target;
private transient IAbility abilityCopy;
public PlayerAbilityEvent(IPlayer player, Ability ability, EntityLivingBase target) {
super(player);
this.ability = ability;
this.target = target != null ? (IEntityLivingBase) NpcAPI.Instance().getIEntity(target) : null;
}
@Override
public IAbility getAbility() {
if (abilityCopy == null && ability != null) {
abilityCopy = ability.deepCopy();
}
return abilityCopy;
}
@Override
public IEntityLivingBase getTarget() {
return target;
}
@Override
public String getHookName() {
return "playerAbilityEvent";
}
/**
* Fired when a player's ability starts executing (enters WINDUP phase).
*/
@Cancelable
public static class StartEvent extends PlayerAbilityEvent implements IPlayerAbilityEvent.StartEvent {
public StartEvent(IPlayer player, Ability ability, EntityLivingBase target) {
super(player, ability, target);
}
@Override
public String getHookName() {
return EnumScriptType.ABILITY_START.function;
}
}
/**
* Fired when a player's ability enters the ACTIVE phase and performs its effect.
*/
@Cancelable
public static class ExecuteEvent extends PlayerAbilityEvent implements IPlayerAbilityEvent.ExecuteEvent {
public ExecuteEvent(IPlayer player, Ability ability, EntityLivingBase target) {
super(player, ability, target);
}
@Override
public String getHookName() {
return EnumScriptType.ABILITY_EXECUTE.function;
}
}
/**
* Fired when a player's ability is interrupted by damage.
*/
public static class InterruptEvent extends PlayerAbilityEvent implements IPlayerAbilityEvent.InterruptEvent {
private final IDamageSource damageSource;
private final float damage;
public InterruptEvent(IPlayer player, Ability ability, EntityLivingBase target, DamageSource source, float damage) {
super(player, ability, target);
this.damageSource = source != null ? NpcAPI.Instance().getIDamageSource(source) : null;
this.damage = damage;
}
@Override
public IDamageSource getDamageSource() {
return damageSource;
}
@Override
public float getDamage() {
return damage;
}
@Override
public String getHookName() {
return EnumScriptType.ABILITY_INTERRUPT.function;
}
}
/**
* Fired when a player's ability completes its full execution cycle.
*/
public static class CompleteEvent extends PlayerAbilityEvent implements IPlayerAbilityEvent.CompleteEvent {
public CompleteEvent(IPlayer player, Ability ability, EntityLivingBase target) {
super(player, ability, target);
}
@Override
public String getHookName() {
return EnumScriptType.ABILITY_COMPLETE.function;
}
}
/**
* Fired every tick while a player's ability is executing.
*/
public static class TickEvent extends PlayerAbilityEvent implements IPlayerAbilityEvent.TickEvent {
private final int abilityPhase;
private final int tick;
public TickEvent(IPlayer player, Ability ability, EntityLivingBase target, int phase, int tick) {
super(player, ability, target);
this.abilityPhase = phase;
this.tick = tick;
}
@Override
public int getAbilityPhase() {
return abilityPhase;
}
@Override
public int getTick() {
return tick;
}
@Override
public String getHookName() {
return EnumScriptType.ABILITY_TICK.function;
}
}
/**
* Fired when a player's ability hits an entity with damage.
* Canceling prevents the damage from being applied.
*/
@Cancelable
public static class HitEvent extends PlayerAbilityEvent implements IPlayerAbilityEvent.HitEvent {
private final IEntityLivingBase hitEntity;
private float damage;
private float knockback;
private float knockbackUp;
public HitEvent(IPlayer player, Ability ability, EntityLivingBase target,
EntityLivingBase hitEntity, float damage, float knockback, float knockbackUp) {
super(player, ability, target);
this.hitEntity = hitEntity != null ? (IEntityLivingBase) NpcAPI.Instance().getIEntity(hitEntity) : null;
this.damage = damage;
this.knockback = knockback;
this.knockbackUp = knockbackUp;
}
@Override
public IEntityLivingBase getHitEntity() {
return hitEntity;
}
@Override
public float getDamage() {
return damage;
}
@Override
public void setDamage(float damage) {
this.damage = damage;
}
@Override
public float getKnockback() {
return knockback;
}
@Override
public void setKnockback(float knockback) {
this.knockback = knockback;
}
@Override
public float getKnockbackUp() {
return knockbackUp;
}
@Override
public void setKnockbackUp(float knockbackUp) {
this.knockbackUp = knockbackUp;
}
@Override
public String getHookName() {
return EnumScriptType.ABILITY_HIT.function;
}
}
/**
* Fired when a toggle ability changes state.
* Canceling prevents the toggle from changing state.
*/
@Cancelable
public static class ToggleEvent extends PlayerAbilityEvent implements IPlayerAbilityEvent.ToggleEvent {
private final int oldState;
private final int newState;
public ToggleEvent(IPlayer player, Ability ability, int oldState, int newState) {
super(player, ability, null);
this.oldState = oldState;
this.newState = newState;
}
@Override
public boolean isTogglingOn() {
return newState > 0;
}
@Override
public int getOldState() {
return oldState;
}
@Override
public int getNewState() {
return newState;
}
@Override
public String getHookName() {
return EnumScriptType.ABILITY_TOGGLE.function;
}
}
/**
* Fired every 10 ticks for each active toggle ability.
* Scripts can set enabled to false to force-deactivate.
*/
public static class ToggleUpdateEvent extends PlayerAbilityEvent implements IPlayerAbilityEvent.ToggleUpdateEvent {
private final int tick;
private final int state;
private boolean enabled = true;
public ToggleUpdateEvent(IPlayer player, Ability ability, int tick, int state) {
super(player, ability, null);
this.tick = tick;
this.state = state;
}
@Override
public int getTick() {
return tick;
}
@Override
public int getState() {
return state;
}
@Override
public boolean isEnabled() {
return enabled;
}
@Override
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
@Override
public String getHookName() {
return EnumScriptType.ABILITY_TOGGLE_UPDATE.function;
}
}
}
@@ -58,8 +58,8 @@ public class ScriptDataAbilities implements IDataAbilities {
@Override
public void addAbilityReference(String key) {
// Validate ability exists and allows NPCs
Ability ability = AbilityController.Instance.resolveAbility(key);
// Validate ability exists and allows NPCs (peek avoids deep copy)
Ability ability = AbilityController.Instance.peekAbility(key);
if (ability == null) {
return; // Ability doesn't exist
}
@@ -145,6 +145,11 @@ public class ScriptDataAbilities implements IDataAbilities {
data.interruptCurrentAbility(null, 0);
}
@Override
public void completeCurrentAbility() {
data.completeCurrentAbility();
}
@Override
public int getGlobalCooldown() {
return (int) data.getRemainingCooldown();
@@ -191,8 +196,8 @@ public class ScriptDataAbilities implements IDataAbilities {
@Override
public boolean executeAbility(String key, Object target) {
// Validate ability exists and allows NPCs
Ability ability = AbilityController.Instance.resolveAbility(key);
// Validate ability exists and allows NPCs (peek avoids deep copy)
Ability ability = AbilityController.Instance.peekAbility(key);
if (ability == null) {
return false; // Ability doesn't exist
}
@@ -28,8 +28,8 @@ public class ScriptPlayerAbilityData implements IPlayerAbilityData {
@Override
public void unlockAbility(String key) {
// Validate ability exists and allows players
Ability ability = AbilityController.Instance.resolveAbility(key);
// Validate ability exists and allows players (peek avoids deep copy)
Ability ability = AbilityController.Instance.peekAbility(key);
if (ability == null) {
return; // Ability doesn't exist
}
@@ -94,6 +94,11 @@ public class ScriptPlayerAbilityData implements IPlayerAbilityData {
data.interruptCurrentAbility();
}
@Override
public void completeCurrentAbility() {
data.completeCurrentAbility();
}
@Override
public boolean isOnCooldown() {
return data.isOnCooldown();
@@ -162,7 +167,7 @@ public class ScriptPlayerAbilityData implements IPlayerAbilityData {
* Uses the same resolution as unlockAbility: registry key for built-in, UUID for custom.
*/
private String resolveCanonicalKey(String key) {
Ability ability = AbilityController.Instance.resolveAbility(key);
Ability ability = AbilityController.Instance.peekAbility(key);
if (ability != null && ability.getId() != null) {
return ability.getId();
}