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 3bd078617..4d3268568 100644 --- a/src/main/java/dev/latvian/mods/kubejs/entity/AttributeBuilder.java +++ b/src/main/java/dev/latvian/mods/kubejs/entity/AttributeBuilder.java @@ -19,6 +19,9 @@ @SuppressWarnings("unused") @ReturnsSelf 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; @@ -48,6 +51,14 @@ public AttributeBuilder sentiment(Attribute.Sentiment sentiment) { return this; } + public AttributeBuilder negativeSentiment() { + return sentiment(Attribute.Sentiment.NEGATIVE); + } + + public AttributeBuilder neutralSentiment() { + return sentiment(Attribute.Sentiment.NEUTRAL); + } + public AttributeBuilder attachTo(Predicate> entityType) { predicateList.add(entityType); return this; @@ -78,23 +89,24 @@ public Attribute createObject() { if (defaultValue == null) { throw new IllegalArgumentException("Not possible to create a Boolean or Ranged Attribute. Use bool() or range() methods."); } - Either either = defaultValue.mapBoth( + + 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)); - Attribute attribute = Either.unwrap(either); + r -> new BooleanAttribute(this.id.toLanguageKey(), r)) + ); if (syncable) { attribute.setSyncable(true); } + if (sentiment != null) { attribute.setSentiment(sentiment); } + if (predicateList.isEmpty()) { predicateList.add(Predicates.alwaysTrue()); } - return attribute; - } - record Range(double defaultValue, double min, double max) { + return attribute; } }