mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 06:07:27 +00:00
Add Recalc Event for Listeners in Other Mods
This commit is contained in:
1 parent
e27aade87d
commit
93bb6243db
8 files changed
+59
-11
No files matched your search
@@ -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;
|
||||
}
|
||||
|
||||
+27
@@ -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<IAttributeRecalcListener> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
@@ -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);
|
||||
}
|
||||
+3
@@ -110,6 +110,9 @@ public class PlayerAttributeTracker {
|
||||
extraHealth = getAttributeValue(CustomAttributes.HEALTH);
|
||||
|
||||
updatePlayerMaxHealth(player);
|
||||
|
||||
// Post Recalculation Event to Listeners
|
||||
AttributeRecalcEvent.post(player, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in new issue
Block a user