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

@@ -0,0 +1,54 @@
package noppes.npcs.controllers.data;
import kamkeel.npcs.network.packets.request.script.AbilityScriptPacket;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.constants.ScriptContext;
/**
* Script handler for ability scripts.
* Manages a single script container for ability hooks (abilityStart, abilityTick, abilityComplete, etc.).
*/
public class AbilityScript extends SingleScriptHandler implements IScriptHandlerPacket {
/**
* The ability ID (UUID) for packet communication. Empty if not bound.
*/
private String abilityId = "";
/**
* Create an unbound AbilityScript (for server-side use).
*/
public AbilityScript() {
}
/**
* Create an AbilityScript bound to a specific ability (for GUI use).
*
* @param abilityId The UUID of the ability
*/
public AbilityScript(String abilityId) {
this.abilityId = abilityId != null ? abilityId : "";
}
@Override
public ScriptContext getContext() {
return ScriptContext.ABILITY;
}
@Override
public String noticeString() {
return !abilityId.isEmpty() ? "Ability[" + abilityId + "]" : "Ability";
}
@Override
public void requestData() {
if (!abilityId.isEmpty())
AbilityScriptPacket.Get(abilityId);
}
@Override
public void sendSavePacket(int index, int totalCount, NBTTagCompound nbt) {
if (!abilityId.isEmpty())
AbilityScriptPacket.Save(abilityId, index, totalCount, nbt);
}
}
@@ -0,0 +1,54 @@
package noppes.npcs.controllers.data;
import kamkeel.npcs.network.packets.request.script.ChainedAbilityScriptPacket;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.constants.ScriptContext;
/**
* Script handler for chained ability scripts.
* Manages a single script container for chained ability hooks.
*/
public class ChainedAbilityScript extends SingleScriptHandler implements IScriptHandlerPacket {
/**
* The chained ability ID (UUID) for packet communication. Empty if not bound.
*/
private String chainId = "";
/**
* Create an unbound ChainedAbilityScript (for server-side use).
*/
public ChainedAbilityScript() {
}
/**
* Create a ChainedAbilityScript bound to a specific chained ability (for GUI use).
*
* @param chainId The UUID of the chained ability
*/
public ChainedAbilityScript(String chainId) {
this.chainId = chainId != null ? chainId : "";
}
@Override
public ScriptContext getContext() {
return ScriptContext.CHAINED_ABILITY;
}
@Override
public String noticeString() {
return !chainId.isEmpty() ? "ChainedAbility[" + chainId + "]" : "ChainedAbility";
}
@Override
public void requestData() {
if (!chainId.isEmpty())
ChainedAbilityScriptPacket.Get(chainId);
}
@Override
public void sendSavePacket(int index, int totalCount, NBTTagCompound nbt) {
if (!chainId.isEmpty())
ChainedAbilityScriptPacket.Save(chainId, index, totalCount, nbt);
}
}
@@ -26,12 +26,6 @@ public class CustomEffect implements ICustomEffect {
public String icon = "";
public int iconX = 0, iconY = 0;
/**
* Experimental script stuff.
*/
public Consumer<PlayerEvent.EffectEvent.Added> onAddedConsumer;
public Consumer<PlayerEvent.EffectEvent.Ticked> onTickConsumer;
public Consumer<PlayerEvent.EffectEvent.Removed> onRemovedConsumer;
public String menuName = "§aNEW EFFECT";
public int width = 16, height = 16;
@@ -169,26 +163,10 @@ public class CustomEffect implements ICustomEffect {
}
public void onAdded(Consumer<PlayerEvent.EffectEvent.Added> function) {
onAddedConsumer = function;
}
public void onTick(Consumer<PlayerEvent.EffectEvent.Ticked> function) {
onTickConsumer = function;
}
public void onRemoved(Consumer<PlayerEvent.EffectEvent.Removed> function) {
onRemovedConsumer = function;
}
public void onAdded(EntityPlayer player, PlayerEffect playerEffect) {
IPlayer iPlayer = NoppesUtilServer.getIPlayer(player);
if (playerEffect.index == 0) {
PlayerEvent.EffectEvent.Added event = new PlayerEvent.EffectEvent.Added(iPlayer, playerEffect);
if (onAddedConsumer != null)
onAddedConsumer.accept(event);
EffectScript script = getScriptHandler();
if (script == null) {
return;
@@ -204,11 +182,6 @@ public class CustomEffect implements ICustomEffect {
IPlayer iPlayer = NoppesUtilServer.getIPlayer(player);
if (playerEffect.index == 0) {
PlayerEvent.EffectEvent.Ticked event = new PlayerEvent.EffectEvent.Ticked(iPlayer, playerEffect);
if (onTickConsumer != null) {
onTickConsumer.accept(event);
}
EffectScript script = getScriptHandler();
if (script == null) {
return;
@@ -225,11 +198,6 @@ public class CustomEffect implements ICustomEffect {
if (playerEffect.index == 0) {
PlayerEvent.EffectEvent.Removed event = new PlayerEvent.EffectEvent.Removed(iPlayer, playerEffect, type);
if (onRemovedConsumer != null) {
onRemovedConsumer.accept(event);
}
EffectScript script = getScriptHandler();
if (script == null) {
return;
@@ -25,10 +25,6 @@ import noppes.npcs.AbstractDataAbilities;
import noppes.npcs.EventHooks;
import noppes.npcs.LogWriter;
import noppes.npcs.api.ability.IPlayerAbilityData;
import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.controllers.ScriptController;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.event.player.PlayerAbilityEvent;
import java.util.ArrayList;
import java.util.Iterator;
@@ -129,53 +125,6 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
return player != null ? player.worldObj.getTotalWorldTime() : 0;
}
@Override
protected void fireTickEvent(Ability ability, EntityLivingBase target) {
EntityPlayer player = playerData.player;
if (ScriptController.Instance == null || player == null) return;
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts(player);
if (handler == null) return;
IPlayer iPlayer = (IPlayer) NpcAPI.Instance().getIEntity(player);
PlayerAbilityEvent.TickEvent event = new PlayerAbilityEvent.TickEvent(
iPlayer, ability, target, ability.getPhase().ordinal(), ability.getCurrentTick());
EventHooks.onPlayerAbilityTick(handler, event);
}
@Override
protected boolean fireExecuteEvent(Ability ability, EntityLivingBase target) {
EntityPlayer player = playerData.player;
if (ScriptController.Instance == null || player == null) return false;
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts(player);
if (handler == null) return false;
IPlayer iPlayer = (IPlayer) NpcAPI.Instance().getIEntity(player);
PlayerAbilityEvent.ExecuteEvent event = new PlayerAbilityEvent.ExecuteEvent(iPlayer, ability, target);
return EventHooks.onPlayerAbilityExecute(handler, event);
}
@Override
protected void fireCompleteEvent(Ability ability, EntityLivingBase target) {
EntityPlayer player = playerData.player;
if (ScriptController.Instance == null || player == null) return;
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts(player);
if (handler == null) return;
IPlayer iPlayer = (IPlayer) NpcAPI.Instance().getIEntity(player);
PlayerAbilityEvent.CompleteEvent event = new PlayerAbilityEvent.CompleteEvent(iPlayer, ability, target);
EventHooks.onPlayerAbilityComplete(handler, event);
}
@Override
protected void fireInterruptEvent(Ability ability, EntityLivingBase target,
DamageSource source, float damage) {
EntityPlayer player = playerData.player;
if (ScriptController.Instance == null || player == null) return;
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts(player);
if (handler == null) return;
IPlayer iPlayer = (IPlayer) NpcAPI.Instance().getIEntity(player);
PlayerAbilityEvent.InterruptEvent event = new PlayerAbilityEvent.InterruptEvent(
iPlayer, ability, target, source, damage);
EventHooks.onPlayerAbilityInterrupt(handler, event);
}
@Override
protected void spawnTelegraph(Ability ability, EntityLivingBase target) {
EntityPlayer player = playerData.player;
@@ -423,7 +372,7 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
}
// Fire start event (cancelable)
if (firePlayerStartEvent(player, ability)) {
if (EventHooks.onAbilityStart(ability, player, null)) {
return false; // Cancelled
}
@@ -491,29 +440,6 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
protected void onToggleStateChanged(String key, boolean active, int state) {
}
@Override
protected boolean fireToggleEvent(Ability ability, int oldState, int newState) {
EntityPlayer player = playerData.player;
if (ScriptController.Instance == null || player == null) return false;
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts(player);
if (handler == null) return false;
IPlayer iPlayer = (IPlayer) NpcAPI.Instance().getIEntity(player);
PlayerAbilityEvent.ToggleEvent event = new PlayerAbilityEvent.ToggleEvent(iPlayer, ability, oldState, newState);
return EventHooks.onPlayerAbilityToggle(handler, event);
}
@Override
protected boolean fireToggleUpdateEvent(Ability ability, int tick, int state) {
EntityPlayer player = playerData.player;
if (ScriptController.Instance == null || player == null) return true;
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts(player);
if (handler == null) return true;
IPlayer iPlayer = (IPlayer) NpcAPI.Instance().getIEntity(player);
PlayerAbilityEvent.ToggleUpdateEvent event = new PlayerAbilityEvent.ToggleUpdateEvent(iPlayer, ability, tick, state);
EventHooks.onPlayerAbilityToggleUpdate(handler, event);
return event.isEnabled();
}
// ═══════════════════════════════════════════════════════════════════
// SELECTION
// ═══════════════════════════════════════════════════════════════════
@@ -1035,22 +961,6 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
}
}
// ═══════════════════════════════════════════════════════════════════
// SCRIPT EVENTS (Player-specific: start event only, others via abstract)
// ═══════════════════════════════════════════════════════════════════
/**
* Fire the ability start event. Returns true if cancelled.
*/
private boolean firePlayerStartEvent(EntityPlayer player, Ability ability) {
if (ScriptController.Instance == null) return false;
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts(player);
if (handler == null) return false;
IPlayer iPlayer = (IPlayer) NpcAPI.Instance().getIEntity(player);
PlayerAbilityEvent.StartEvent event = new PlayerAbilityEvent.StartEvent(iPlayer, ability, null);
return EventHooks.onPlayerAbilityStart(handler, event);
}
// ═══════════════════════════════════════════════════════════════════
// NBT SERIALIZATION
// ═══════════════════════════════════════════════════════════════════
@@ -1096,7 +1006,7 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
}
playingAbilityAnimation = compound.getBoolean("AbilityAnimating");
// Active toggles - restore state directly (no onToggleOn callback during load)
// Active toggles - restore state directly (no onToggle callback during load)
activeToggles.clear();
if (compound.hasKey("ActiveToggles")) {
NBTTagList toggleNbt = compound.getTagList("ActiveToggles", 10); // 10 = TAG_COMPOUND