mirror of
https://github.com/Xiao-MoMi/Custom-Nameplates.git
synced 2025-12-19 15:09:23 +00:00
improved scale support
This commit is contained in:
@@ -310,15 +310,46 @@ public class BukkitPlatform implements Platform {
|
||||
Object attributeHolder = Reflections.field$ClientboundUpdateAttributesPacket$AttributeSnapshot$attribute.get(attributeSnapshot);
|
||||
Object attribute = Reflections.method$Holder$value.invoke(attributeHolder);
|
||||
String id = (String) Reflections.field$Attribute$id.get(attribute);
|
||||
if (id.equals("attribute.name.generic.scale") || id.equals("attribute.name.scale")) {
|
||||
if (id.endsWith("scale")) {
|
||||
double baseValue = (double) Reflections.field$ClientboundUpdateAttributesPacket$AttributeSnapshot$base.get(attributeSnapshot);
|
||||
@SuppressWarnings("unchecked")
|
||||
Collection<Object> modifiers = (Collection<Object>) Reflections.field$ClientboundUpdateAttributesPacket$AttributeSnapshot$modifiers.get(attributeSnapshot);
|
||||
for (Object modifier : modifiers) {
|
||||
double amount = (double) Reflections.field$AttributeModifier$amount.get(modifier);
|
||||
baseValue += amount;
|
||||
int left = modifiers.size();
|
||||
if (left > 0) {
|
||||
for (Object modifier : modifiers) {
|
||||
Object operation = Reflections.field$AttributeModifier$operation.get(modifier);
|
||||
if (operation == Reflections.instance$AttributeModifier$Operation$ADD_VALUE) {
|
||||
double amount = (double) Reflections.field$AttributeModifier$amount.get(modifier);
|
||||
baseValue += amount;
|
||||
left--;
|
||||
if (left == 0) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
CustomNameplates.getInstance().getUnlimitedTagManager().onPlayerAttributeSet(another, player, baseValue);
|
||||
double finalValue = baseValue;
|
||||
if (left > 0) {
|
||||
for (Object modifier : modifiers) {
|
||||
Object operation = Reflections.field$AttributeModifier$operation.get(modifier);
|
||||
if (operation == Reflections.instance$AttributeModifier$Operation$ADD_MULTIPLIED_BASE) {
|
||||
double amount = (double) Reflections.field$AttributeModifier$amount.get(modifier);
|
||||
finalValue += amount * baseValue;
|
||||
left--;
|
||||
if (left == 0) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (left > 0) {
|
||||
for (Object modifier : modifiers) {
|
||||
Object operation = Reflections.field$AttributeModifier$operation.get(modifier);
|
||||
if (operation == Reflections.instance$AttributeModifier$Operation$ADD_MULTIPLIED_TOTAL) {
|
||||
double amount = (double) Reflections.field$AttributeModifier$amount.get(modifier);
|
||||
finalValue *= 1.0 + amount;
|
||||
left--;
|
||||
if (left == 0) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
CustomNameplates.getInstance().getUnlimitedTagManager().onPlayerAttributeSet(another, player, finalValue);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1097,4 +1097,37 @@ public class Reflections {
|
||||
}
|
||||
field$ServerConnectionListener$channels = requireNonNull(f);
|
||||
}
|
||||
|
||||
public static final Class<?> clazz$AttributeModifier$Operation = requireNonNull(
|
||||
ReflectionUtils.getClazz(
|
||||
BukkitReflectionUtils.assembleMCClass("world.entity.ai.attributes.AttributeModifier$Operation")
|
||||
)
|
||||
);
|
||||
|
||||
public static final Method method$AttributeModifier$Operation$values = requireNonNull(
|
||||
ReflectionUtils.getStaticMethod(
|
||||
clazz$AttributeModifier$Operation, clazz$AttributeModifier$Operation.arrayType()
|
||||
)
|
||||
);
|
||||
|
||||
public static final Object instance$AttributeModifier$Operation$ADD_VALUE;
|
||||
public static final Object instance$AttributeModifier$Operation$ADD_MULTIPLIED_BASE;
|
||||
public static final Object instance$AttributeModifier$Operation$ADD_MULTIPLIED_TOTAL;
|
||||
|
||||
static {
|
||||
try {
|
||||
Object[] values = (Object[]) method$AttributeModifier$Operation$values.invoke(null);
|
||||
instance$AttributeModifier$Operation$ADD_VALUE = values[0];
|
||||
instance$AttributeModifier$Operation$ADD_MULTIPLIED_BASE = values[1];
|
||||
instance$AttributeModifier$Operation$ADD_MULTIPLIED_TOTAL = values[2];
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static final Field field$AttributeModifier$operation = requireNonNull(
|
||||
ReflectionUtils.getDeclaredField(
|
||||
clazz$AttributeModifier, clazz$AttributeModifier$Operation, 0
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user