From c168702970b666f4bfe357e2f163cfefdba9d3eb Mon Sep 17 00:00:00 2001 From: Vidal Date: Sun, 1 Feb 2026 20:09:12 -0300 Subject: [PATCH] WIP Animations Register --- .../controllers/data/ability/Ability.java | 6 ++-- src/main/java/kamkeel/npcs/util/Register.java | 20 ++++++++++++- .../gui/advanced/SubGuiAbilityConfig.java | 2 +- .../npcs/controllers/AnimationController.java | 29 +++++++++++++------ 4 files changed, 43 insertions(+), 14 deletions(-) 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 b33426ba9..f7325a24f 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/Ability.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/Ability.java @@ -1098,7 +1098,7 @@ public abstract class Ability implements IAbility { // Built-in animation by name takes priority if (windUpAnimationName != null && !windUpAnimationName.isEmpty()) { - return (Animation) AnimationController.Instance.get(windUpAnimationName); + return (Animation) AnimationController.Instance.get(windUpAnimationName, true); } // Fall back to user animation by ID if (windUpAnimationId >= 0) { @@ -1128,7 +1128,7 @@ public abstract class Ability implements IAbility { // Built-in animation by name takes priority if (activeAnimationName != null && !activeAnimationName.isEmpty()) { - return (Animation) AnimationController.Instance.get(activeAnimationName); + return (Animation) AnimationController.Instance.get(activeAnimationName, true); } // Fall back to user animation by ID if (activeAnimationId >= 0) { @@ -1260,7 +1260,7 @@ public abstract class Ability implements IAbility { Animation animation = null; // Check for built-in animation (by name) first if (windUpAnimationName != null && !windUpAnimationName.isEmpty()) { - animation = (Animation) AnimationController.Instance.get(windUpAnimationName); + animation = (Animation) AnimationController.Instance.get(windUpAnimationName, true); } // Fall back to user animation (by ID) else if (windUpAnimationId >= 0) { diff --git a/src/main/java/kamkeel/npcs/util/Register.java b/src/main/java/kamkeel/npcs/util/Register.java index 6485b9b81..aebfd4255 100644 --- a/src/main/java/kamkeel/npcs/util/Register.java +++ b/src/main/java/kamkeel/npcs/util/Register.java @@ -2,6 +2,9 @@ package kamkeel.npcs.util; import kamkeel.npcs.controllers.data.ability.Ability; import kamkeel.npcs.controllers.data.ability.AbilityController; +import noppes.npcs.LogWriter; +import noppes.npcs.controllers.AnimationController; +import noppes.npcs.controllers.data.Animation; import java.util.LinkedHashMap; import java.util.Map; @@ -34,5 +37,20 @@ public class Register { } } - // TODO ADD ANIMATION REGISTER + public static class Animations extends Register { + private final Class modClass; + private final String animationsPath; + + public Animations(Class modClass, String animationsPath, String namespace) { + super("ability", namespace); + this.animationsPath = animationsPath; + this.modClass = modClass; + } + + public void register() throws Exception { + for (Map.Entry> entry : entries.entrySet()) { + AnimationController.Instance.loadBuiltInAnimation(modClass, animationsPath, entry.getKey()); + } + } + } } diff --git a/src/main/java/noppes/npcs/client/gui/advanced/SubGuiAbilityConfig.java b/src/main/java/noppes/npcs/client/gui/advanced/SubGuiAbilityConfig.java index ef799961d..32cfc51b2 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/SubGuiAbilityConfig.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/SubGuiAbilityConfig.java @@ -1003,7 +1003,7 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi Animation animation = null; // Check for built-in animation (by name) first if (windUpAnimationName != null && !windUpAnimationName.isEmpty()) { - animation = (Animation) AnimationController.Instance.get(windUpAnimationName); + animation = (Animation) AnimationController.Instance.get(windUpAnimationName, true); } // Fall back to user animation (by ID) else if (windUpAnimationId >= 0) { diff --git a/src/main/java/noppes/npcs/controllers/AnimationController.java b/src/main/java/noppes/npcs/controllers/AnimationController.java index c6837b6c7..b4203b452 100644 --- a/src/main/java/noppes/npcs/controllers/AnimationController.java +++ b/src/main/java/noppes/npcs/controllers/AnimationController.java @@ -120,12 +120,9 @@ public class AnimationController implements IAnimationHandler { } } - /** - * Load a single built-in animation by name from assets folder. - */ - private void loadBuiltInAnimation(String animName) throws Exception { - String resourcePath = BUILTIN_ANIMATIONS_PATH + "/" + animName + ".json"; - try (InputStream stream = CustomNpcs.class.getResourceAsStream(resourcePath)) { + public void loadBuiltInAnimation(Class modClass, String path, String animName) throws Exception { + String resourcePath = path + "/" + animName + ".json"; + try (InputStream stream = modClass.getResourceAsStream(resourcePath)) { if (stream == null) { return; } @@ -150,6 +147,13 @@ public class AnimationController implements IAnimationHandler { } } + /** + * Load a single built-in animation by name from assets folder. + */ + private void loadBuiltInAnimation(String animName) throws Exception { + loadBuiltInAnimation(CustomNpcs.class, BUILTIN_ANIMATIONS_PATH, animName); + } + private void loadAnimations() { animations.clear(); @@ -314,6 +318,10 @@ public class AnimationController implements IAnimationHandler { } public IAnimation get(String name) { + return get(name, false); + } + + public IAnimation get(String name, boolean builtIn) { // Check user/custom animations first (allows overriding built-in) for (Map.Entry entry : animations.entrySet()) { if (entry.getValue().name.equalsIgnoreCase(name)) { @@ -321,10 +329,13 @@ public class AnimationController implements IAnimationHandler { } } // Then check built-in animations - BuiltInAnimation builtIn = builtInAnimations.get(name.toLowerCase()); - if (builtIn != null) { - return builtIn; + if (builtIn) { + BuiltInAnimation builtInAnim = builtInAnimations.get(name.toLowerCase()); + if (builtInAnim != null) { + return builtInAnim; + } } + return null; }