Skip to content

Commit

Permalink
PR cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
LatvianModder committed Aug 18, 2024
1 parent 7578f05 commit c2a14e3
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/main/java/dev/latvian/mods/kubejs/entity/AttributeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
@SuppressWarnings("unused")
@ReturnsSelf
public class AttributeBuilder extends BuilderBase<Attribute> {
public record Range(double defaultValue, double min, double max) {
}

private final List<Predicate<EntityType<?>>> predicateList = new ArrayList<>();
private Either<Range, Boolean> defaultValue;
private boolean syncable = true;
Expand Down Expand Up @@ -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<?>> entityType) {
predicateList.add(entityType);
return this;
Expand Down Expand Up @@ -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<Attribute,Attribute> 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;
}
}

0 comments on commit c2a14e3

Please sign in to comment.