Tick Attribute Tracker

This commit is contained in:
Kam committed 2025-02-25 16:46:05 -05:00
1 parent 0c1ce7ed7a
commit f1b77fe94f
4 files changed
+9 -36

No files matched your search

@@ -23,6 +23,7 @@ import net.minecraftforge.event.entity.player.*;
import net.minecraftforge.event.world.BlockEvent;
import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.api.item.IItemCustomizable;
import noppes.npcs.attribute.PlayerAttributeManager;
import noppes.npcs.constants.EnumQuestType;
import noppes.npcs.controllers.CustomEffectController;
import noppes.npcs.controllers.PartyController;
@@ -47,7 +48,7 @@ public class ScriptPlayerEventHandler {
if (event.side == Side.SERVER && event.phase == TickEvent.Phase.START) {
EntityPlayer player = event.player;
if (player.ticksExisted%10 == 0) {
if (player.ticksExisted % 10 == 0) {
PlayerDataScript handler = ScriptController.Instance.playerScripts;
IPlayer scriptPlayer = (IPlayer) NpcAPI.Instance().getIEntity(player);
EventHooks.onPlayerTick(handler, scriptPlayer);
@@ -59,6 +60,8 @@ public class ScriptPlayerEventHandler {
EventHooks.onScriptItemUpdate(isw, player);
}
}
PlayerAttributeManager.getTracker(player.getUniqueID()).updateIfChanged(player);
}
if (PlayerDataController.Instance != null) {
@@ -16,15 +16,15 @@ public class ModAttributes {
public static final AttributeDefinition MAGIC_RESISTANCE_PERCENT;
static {
MAIN_ATTACK_FLAT = AttributeController.registerAttribute(AttributeKeys.MAIN_ATTACK_FLAT, "Main Attack Damage (Flat)", AttributeValueType.FLAT);
MAIN_ATTACK_FLAT = AttributeController.registerAttribute(AttributeKeys.MAIN_ATTACK_FLAT, "Main Attack Damage", AttributeValueType.FLAT);
MAIN_ATTACK_PERCENT = AttributeController.registerAttribute(AttributeKeys.MAIN_ATTACK_PERCENT, "Main Attack Damage (%)", AttributeValueType.PERCENT);
HEALTH = AttributeController.registerAttribute(AttributeKeys.HEALTH, "Health", AttributeValueType.FLAT);
CRITICAL_CHANCE_PERCENT = AttributeController.registerAttribute(AttributeKeys.CRITICAL_CHANCE_PERCENT, "Critical Chance (%)", AttributeValueType.PERCENT);
CRITICAL_DAMAGE_FLAT = AttributeController.registerAttribute(AttributeKeys.CRITICAL_DAMAGE_FLAT, "Critical Damage Bonus (Flat)", AttributeValueType.FLAT);
CRITICAL_DAMAGE_FLAT = AttributeController.registerAttribute(AttributeKeys.CRITICAL_DAMAGE_FLAT, "Critical Damage Bonus", AttributeValueType.FLAT);
MAGIC_DAMAGE_FLAT = AttributeController.registerAttribute(AttributeKeys.MAGIC_DAMAGE_FLAT, "Magic Damage (Flat)", AttributeValueType.MAGIC);
MAGIC_DAMAGE_FLAT = AttributeController.registerAttribute(AttributeKeys.MAGIC_DAMAGE_FLAT, "Magic Damage", AttributeValueType.MAGIC);
MAGIC_DAMAGE_PERCENT = AttributeController.registerAttribute(AttributeKeys.MAGIC_DAMAGE_PERCENT, "Magic Damage (%)", AttributeValueType.MAGIC);
MAGIC_DEFENSE_FLAT = AttributeController.registerAttribute(AttributeKeys.MAGIC_DEFENSE_FLAT, "Magic Defense (Flat)", AttributeValueType.MAGIC);
MAGIC_DEFENSE_FLAT = AttributeController.registerAttribute(AttributeKeys.MAGIC_DEFENSE_FLAT, "Magic Defense", AttributeValueType.MAGIC);
MAGIC_RESISTANCE_PERCENT = AttributeController.registerAttribute(AttributeKeys.MAGIC_RESISTANCE_PERCENT, "Magic Resistance (%)", AttributeValueType.MAGIC);
}
}
@@ -1,22 +0,0 @@
package noppes.npcs.attribute;
import net.minecraft.server.MinecraftServer;
import net.minecraft.entity.player.EntityPlayer;
/**
* Tick handler that runs every tick and, every 10 ticks, checks all players
* for equipment changes to update their attribute trackers.
*/
public class PlayerAttributeTickHandler {
private int tickCount = 0;
public void onTick() {
tickCount++;
if (tickCount % 10 == 0) {
for (Object o : MinecraftServer.getServer().getConfigurationManager().playerEntityList) {
EntityPlayer player = (EntityPlayer) o;
PlayerAttributeManager.getTracker(player.getUniqueID()).updateIfChanged(player);
}
}
}
}
@@ -44,15 +44,7 @@ public class PlayerAttributeTracker {
* are aggregated by summing values from their NBT maps.
*/
public void recalcAttributes(EntityPlayer player) {
// Start with a fresh attribute map.
CustomAttributeMap newMap = new CustomAttributeMap();
// Pre-register core non-magic attributes (if they appear on items).
newMap.registerAttribute(ModAttributes.MAIN_ATTACK_FLAT, 0.0);
newMap.registerAttribute(ModAttributes.MAIN_ATTACK_PERCENT, 0.0);
newMap.registerAttribute(ModAttributes.CRITICAL_CHANCE_PERCENT, 0.0);
newMap.registerAttribute(ModAttributes.CRITICAL_DAMAGE_FLAT, 0.0);
// (HEALTH is handled separately.)
aggregatedAttributes = newMap;
aggregatedAttributes = new CustomAttributeMap();
// Reset magic aggregates.
aggregatedMagicDamageFlat.clear();