package com.xfestudio.mydimensionlord.platform;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.ai.attributes.*;
import java.nio.charset.StandardCharsets;
import java.util.UUID;
/** Named transient modifiers are idempotent and never persist a removed set bonus. */
public final class EquipmentAttributes {
public enum Bonus { VITALITY, ANCHOR, POWER, HASTE, STRIDE }
private EquipmentAttributes() {}
public static double armorLimit(Attribute attribute) {
if (attribute == Attributes.ARMOR) return com.xfestudio.mydimensionlord.equipment.GearSet.LORD.totalProtection();
if (attribute == Attributes.ARMOR_TOUGHNESS) return com.xfestudio.mydimensionlord.equipment.GearSet.LORD.toughness() * 4;
return 0;
}
private static Attribute type(Bonus bonus) {
return switch (bonus) { case VITALITY -> Attributes.MAX_HEALTH; case ANCHOR -> Attributes.KNOCKBACK_RESISTANCE;
case POWER -> Attributes.ATTACK_DAMAGE; case HASTE -> Attributes.ATTACK_SPEED; case STRIDE -> Attributes.MOVEMENT_SPEED; };
}
private static UUID id(Bonus bonus) { return UUID.nameUUIDFromBytes(("mydimension_lord:full_set_" + bonus.name()).getBytes(StandardCharsets.UTF_8)); }
public static void apply(Player player, Bonus bonus, double amount) {
var attribute = player.getAttribute(type(bonus));
if (attribute == null) return;
var existing = attribute.getModifier(id(bonus));
if (amount == 0) { if (existing != null) attribute.removeModifier(id(bonus)); return; }
if (existing != null && existing.getAmount() == amount) return;
if (existing != null) attribute.removeModifier(id(bonus));
attribute.addTransientModifier(new AttributeModifier(id(bonus), "Dimension Lord " + bonus, amount,
bonus == Bonus.STRIDE ? AttributeModifier.Operation.MULTIPLY_TOTAL : AttributeModifier.Operation.ADDITION));
}
public static double value(Player player, Bonus bonus) { return player.getAttributeValue(type(bonus)); }
}
package com.xfestudio.mydimensionlord.platform;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.ai.attributes.*;
import java.nio.charset.StandardCharsets;
import java.util.UUID;
/** Named transient modifiers are idempotent and never persist a removed set bonus. */
public final class EquipmentAttributes {
public enum Bonus { VITALITY, ANCHOR, POWER, HASTE, STRIDE }
private EquipmentAttributes() {}
public static double armorLimit(Attribute attribute) {
if (attribute == Attributes.ARMOR) return com.xfestudio.mydimensionlord.equipment.GearSet.LORD.totalProtection();
if (attribute == Attributes.ARMOR_TOUGHNESS) return com.xfestudio.mydimensionlord.equipment.GearSet.LORD.toughness() * 4;
return 0;
}
private static Attribute type(Bonus bonus) {
return switch (bonus) { case VITALITY -> Attributes.MAX_HEALTH; case ANCHOR -> Attributes.KNOCKBACK_RESISTANCE;
case POWER -> Attributes.ATTACK_DAMAGE; case HASTE -> Attributes.ATTACK_SPEED; case STRIDE -> Attributes.MOVEMENT_SPEED; };
}
private static UUID id(Bonus bonus) { return UUID.nameUUIDFromBytes(("mydimension_lord:full_set_" + bonus.name()).getBytes(StandardCharsets.UTF_8)); }
public static void apply(Player player, Bonus bonus, double amount) {
var attribute = player.getAttribute(type(bonus));
if (attribute == null) return;
var existing = attribute.getModifier(id(bonus));
if (amount == 0) { if (existing != null) attribute.removeModifier(id(bonus)); return; }
if (existing != null && existing.getAmount() == amount) return;
if (existing != null) attribute.removeModifier(id(bonus));
attribute.addTransientModifier(new AttributeModifier(id(bonus), "Dimension Lord " + bonus, amount,
bonus == Bonus.STRIDE ? AttributeModifier.Operation.MULTIPLY_TOTAL : AttributeModifier.Operation.ADDITION));
}
public static double value(Player player, Bonus bonus) { return player.getAttributeValue(type(bonus)); }
}