Normalize 1.21.x attributes (#41)

This commit is contained in:
Grooble
2025-01-26 23:15:23 +01:00
committed by GitHub
parent 4ea199aa5a
commit 73e4742a4f
2 changed files with 15 additions and 4 deletions
@@ -22,8 +22,12 @@ public class AttributesDataGenerator implements IDataGenerator {
var registry = DGU.getWorld().getRegistryManager().getOrThrow(RegistryKeys.ATTRIBUTE); var registry = DGU.getWorld().getRegistryManager().getOrThrow(RegistryKeys.ATTRIBUTE);
for (EntityAttribute attribute : registry) { for (EntityAttribute attribute : registry) {
JsonObject obj = new JsonObject(); JsonObject obj = new JsonObject();
obj.addProperty("name", Objects.requireNonNull(registry.getId(attribute)).toShortTranslationKey()); String name = Objects.requireNonNull(registry.getId(attribute)).getPath();
obj.addProperty("resource", Objects.requireNonNull(registry.getId(attribute)).toTranslationKey()); while(name.contains("_")) {
name = name.replaceFirst("_[a-z]", String.valueOf(Character.toUpperCase(name.charAt(name.indexOf("_") + 1))));
}
obj.addProperty("name", name);
obj.addProperty("resource", Objects.requireNonNull(registry.getId(attribute)).toString());
obj.addProperty("min", ((ClampedEntityAttribute) attribute).getMinValue()); obj.addProperty("min", ((ClampedEntityAttribute) attribute).getMinValue());
obj.addProperty("max", ((ClampedEntityAttribute) attribute).getMaxValue()); obj.addProperty("max", ((ClampedEntityAttribute) attribute).getMaxValue());
obj.addProperty("default", attribute.getDefaultValue()); obj.addProperty("default", attribute.getDefaultValue());
@@ -8,6 +8,8 @@ import net.minecraft.entity.attribute.ClampedEntityAttribute;
import net.minecraft.entity.attribute.EntityAttribute; import net.minecraft.entity.attribute.EntityAttribute;
import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.RegistryKeys;
import java.util.Objects;
public class AttributesDataGenerator implements IDataGenerator { public class AttributesDataGenerator implements IDataGenerator {
@Override @Override
public String getDataName() { public String getDataName() {
@@ -20,8 +22,13 @@ public class AttributesDataGenerator implements IDataGenerator {
var registry = DGU.getWorld().getRegistryManager().get(RegistryKeys.ATTRIBUTE); var registry = DGU.getWorld().getRegistryManager().get(RegistryKeys.ATTRIBUTE);
for (EntityAttribute attribute : registry) { for (EntityAttribute attribute : registry) {
JsonObject obj = new JsonObject(); JsonObject obj = new JsonObject();
obj.addProperty("name", registry.getId(attribute).getPath().split("\\.")[1]); String[] parts = Objects.requireNonNull(registry.getId(attribute)).getPath().split("\\.");
obj.addProperty("resource", registry.getId(attribute).getPath()); String name = parts[0].equals("generic") ? parts[1] : parts[0] + "_" + parts[1];
while(name.contains("_")) {
name = name.replaceFirst("_[a-z]", String.valueOf(Character.toUpperCase(name.charAt(name.indexOf("_") + 1))));
}
obj.addProperty("name", name);
obj.addProperty("resource", Objects.requireNonNull(registry.getId(attribute)).toString());
obj.addProperty("min", ((ClampedEntityAttribute) attribute).getMinValue()); obj.addProperty("min", ((ClampedEntityAttribute) attribute).getMinValue());
obj.addProperty("max", ((ClampedEntityAttribute) attribute).getMaxValue()); obj.addProperty("max", ((ClampedEntityAttribute) attribute).getMaxValue());
obj.addProperty("default", attribute.getDefaultValue()); obj.addProperty("default", attribute.getDefaultValue());