diff --git a/src/main/java/dev/latvian/mods/kubejs/entity/AttributeBuilder.java b/src/main/java/dev/latvian/mods/kubejs/entity/AttributeBuilder.java index 4d3268568..531833866 100644 --- a/src/main/java/dev/latvian/mods/kubejs/entity/AttributeBuilder.java +++ b/src/main/java/dev/latvian/mods/kubejs/entity/AttributeBuilder.java @@ -13,6 +13,7 @@ import net.neoforged.neoforge.common.BooleanAttribute; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.function.Predicate; @@ -22,10 +23,10 @@ public class AttributeBuilder extends BuilderBase { public record Range(double defaultValue, double min, double max) { } - private final List>> predicateList = new ArrayList<>(); - private Either defaultValue; - private boolean syncable = true; - private Attribute.Sentiment sentiment; + public final List>> predicateList = new ArrayList<>(); + public Either defaultValue; + public boolean syncable = true; + public Attribute.Sentiment sentiment; public AttributeBuilder(ResourceLocation id) { super(id); @@ -81,7 +82,7 @@ public AttributeBuilder attachToCategory(MobCategory category) { @HideFromJS public List>> getPredicateList() { - return predicateList; + return Collections.unmodifiableList(predicateList); } @Override @@ -90,11 +91,14 @@ public Attribute createObject() { throw new IllegalArgumentException("Not possible to create a Boolean or Ranged Attribute. Use bool() or range() methods."); } - var attribute = Either.unwrap(defaultValue.mapBoth( - l -> new RangedAttribute(this.id.toLanguageKey(), l.defaultValue, l.min, l.max), - r -> new BooleanAttribute(this.id.toLanguageKey(), r)) + return Either.unwrap(defaultValue.mapBoth( + l -> new RangedAttribute(this.getBuilderTranslationKey(), l.defaultValue, l.min, l.max), + r -> new BooleanAttribute(this.getBuilderTranslationKey(), r)) ); + } + @Override + public Attribute transformObject(Attribute attribute) { if (syncable) { attribute.setSyncable(true); } @@ -106,7 +110,6 @@ public Attribute createObject() { if (predicateList.isEmpty()) { predicateList.add(Predicates.alwaysTrue()); } - return attribute; } } diff --git a/src/main/java/dev/latvian/mods/kubejs/registry/RegistryEventHandler.java b/src/main/java/dev/latvian/mods/kubejs/registry/RegistryEventHandler.java index 6084a8892..bd70e8025 100644 --- a/src/main/java/dev/latvian/mods/kubejs/registry/RegistryEventHandler.java +++ b/src/main/java/dev/latvian/mods/kubejs/registry/RegistryEventHandler.java @@ -34,7 +34,7 @@ public static void registerAll(RegisterEvent event) { @SubscribeEvent(priority = EventPriority.LOW) public static void registerEntityAttributes(EntityAttributeModificationEvent event) { var objStorage = RegistryObjectStorage.of(Registries.ATTRIBUTE); - List>, Holder>> predicatePair = objStorage.objects.values().stream().map(AttributeBuilder.class::cast).flatMap(b -> b.getPredicateList().stream().map(p -> Pair.of(p, BuiltInRegistries.ATTRIBUTE.wrapAsHolder(b.get())))).toList(); + List>, Holder>> predicatePair = objStorage.objects.values().stream().filter(AttributeBuilder.class::isInstance).map(AttributeBuilder.class::cast).flatMap(b -> b.getPredicateList().stream().map(p -> Pair.of(p, BuiltInRegistries.ATTRIBUTE.wrapAsHolder(b.get())))).toList(); event.getTypes().forEach(type -> predicatePair.stream().filter(p -> p.first.test(type)).forEach(p -> event.add(type, p.second))); }