diff --git a/build.gradle b/build.gradle index 30013f9b8..ccc6e2c49 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { id 'idea' } -version = "1.10-beta1" +version = "1.10-beta4" group= "kamkeel.customnpc-plus" archivesBaseName = "CustomNPC-Plus" diff --git a/gradle.properties b/gradle.properties index fb3e039b4..83a8d5e6c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -199,4 +199,4 @@ disableCheckstyle = true # ideaCheckSpotlessOnBuild = true # Non-GTNH properties -modVersion = 1.9.3 +modVersion = 1.10 diff --git a/src/main/java/kamkeel/npcs/controllers/data/attribute/AttributeDefinition.java b/src/main/java/kamkeel/npcs/controllers/data/attribute/AttributeDefinition.java index 27d928f86..8987c9aa3 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/attribute/AttributeDefinition.java +++ b/src/main/java/kamkeel/npcs/controllers/data/attribute/AttributeDefinition.java @@ -1,7 +1,8 @@ package kamkeel.npcs.controllers.data.attribute; public class AttributeDefinition { - private final String key; // e.g., "main_attack_flat" + private final String key; + private String translationKey;// e.g., "main_attack_flat" private final String displayName; // Human‑readable name private final char colorCode; private final AttributeValueType attributeValueType; @@ -9,6 +10,7 @@ public class AttributeDefinition { public AttributeDefinition(String key, String displayName, char colorCode, AttributeValueType attributeValueType, AttributeSection section) { this.key = key; + this.translationKey = "rpgcore:attribute." + key; this.displayName = displayName; this.attributeValueType = attributeValueType; this.section = section; @@ -23,6 +25,14 @@ public class AttributeDefinition { return displayName; } + public String getTranslationKey() { + return translationKey; + } + + public void setTranslationKey(String translationKey) { + this.translationKey = translationKey; + } + public AttributeValueType getValueType() { return attributeValueType; } diff --git a/src/main/java/kamkeel/npcs/controllers/data/attribute/tracker/AttributeRecalcEvent.java b/src/main/java/kamkeel/npcs/controllers/data/attribute/tracker/AttributeRecalcEvent.java new file mode 100644 index 000000000..f8f8fa473 --- /dev/null +++ b/src/main/java/kamkeel/npcs/controllers/data/attribute/tracker/AttributeRecalcEvent.java @@ -0,0 +1,27 @@ +package kamkeel.npcs.controllers.data.attribute.tracker; + +import java.util.ArrayList; +import java.util.List; +import net.minecraft.entity.player.EntityPlayer; + +public class AttributeRecalcEvent { + private static final List listeners = new ArrayList<>(); + + /** + * Allows other mods to register a listener that is called after attribute recalculation. + */ + public static void registerListener(IAttributeRecalcListener listener) { + if (listener != null && !listeners.contains(listener)) { + listeners.add(listener); + } + } + + /** + * Posts an event to all registered listeners. + */ + public static void post(EntityPlayer player, PlayerAttributeTracker tracker) { + for (IAttributeRecalcListener listener : listeners) { + listener.onAttributesRecalculated(player, tracker); + } + } +} diff --git a/src/main/java/kamkeel/npcs/controllers/data/attribute/tracker/IAttributeRecalcListener.java b/src/main/java/kamkeel/npcs/controllers/data/attribute/tracker/IAttributeRecalcListener.java new file mode 100644 index 000000000..618787cb3 --- /dev/null +++ b/src/main/java/kamkeel/npcs/controllers/data/attribute/tracker/IAttributeRecalcListener.java @@ -0,0 +1,10 @@ +package kamkeel.npcs.controllers.data.attribute.tracker; + +import net.minecraft.entity.player.EntityPlayer; + +/** + * Implement this interface to receive a callback after a player's attributes have been recalculated. + */ +public interface IAttributeRecalcListener { + void onAttributesRecalculated(EntityPlayer player, PlayerAttributeTracker tracker); +} diff --git a/src/main/java/kamkeel/npcs/controllers/data/attribute/tracker/PlayerAttributeTracker.java b/src/main/java/kamkeel/npcs/controllers/data/attribute/tracker/PlayerAttributeTracker.java index 0e4c5395f..4a2466ad0 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/attribute/tracker/PlayerAttributeTracker.java +++ b/src/main/java/kamkeel/npcs/controllers/data/attribute/tracker/PlayerAttributeTracker.java @@ -110,6 +110,9 @@ public class PlayerAttributeTracker { extraHealth = getAttributeValue(CustomAttributes.HEALTH); updatePlayerMaxHealth(player); + + // Post Recalculation Event to Listeners + AttributeRecalcEvent.post(player, this); } } diff --git a/src/main/java/kamkeel/npcs/util/AttributeItemUtil.java b/src/main/java/kamkeel/npcs/util/AttributeItemUtil.java index 8b8bcc05a..8d2a48207 100644 --- a/src/main/java/kamkeel/npcs/util/AttributeItemUtil.java +++ b/src/main/java/kamkeel/npcs/util/AttributeItemUtil.java @@ -279,14 +279,12 @@ public class AttributeItemUtil { */ @SideOnly(Side.CLIENT) private static String getTranslatedAttributeName(String key, AttributeDefinition def) { + key = def != null ? def.getTranslationKey() : key; + String translation = null; - if (key.contains(":")) { - if (StatCollector.canTranslate(key)) - translation = StatCollector.translateToLocal(key); - } else { - if (StatCollector.canTranslate("rpgcore:attribute." + key)) - translation = StatCollector.translateToLocal("rpgcore:attribute." + key); - } + if (StatCollector.canTranslate(key)) + translation = StatCollector.translateToLocal(key); + if (translation == null && def != null) translation = def.getDisplayName(); else if (translation == null) diff --git a/src/main/java/noppes/npcs/CustomNpcs.java b/src/main/java/noppes/npcs/CustomNpcs.java index c8dddba3d..8e3626e16 100644 --- a/src/main/java/noppes/npcs/CustomNpcs.java +++ b/src/main/java/noppes/npcs/CustomNpcs.java @@ -41,7 +41,7 @@ import noppes.npcs.scripted.NpcAPI; import java.io.File; import java.util.Set; -@Mod(modid = "customnpcs", name = "CustomNPC+", version = "1.9.4-beta1") +@Mod(modid = "customnpcs", name = "CustomNPC+", version = "1.10-beta4") public class CustomNpcs { @SidedProxy(clientSide = "noppes.npcs.client.ClientProxy", serverSide = "noppes.npcs.CommonProxy")