package net.minecraft.client.data.models.blockstates; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; import java.util.List; import java.util.stream.Stream; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.renderer.block.model.multipart.Condition; import net.minecraft.client.renderer.block.model.multipart.KeyValueCondition; import net.minecraft.world.level.block.state.properties.Property; @Environment(EnvType.CLIENT) public class ConditionBuilder { private final Builder terms = ImmutableMap.builder(); private > void putValue(Property property, KeyValueCondition.Terms terms) { this.terms.put(property.getName(), terms); } public final > ConditionBuilder term(Property property, T value) { this.putValue(property, new KeyValueCondition.Terms(List.of(new KeyValueCondition.Term(property.getName(value), false)))); return this; } @SafeVarargs public final > ConditionBuilder term(Property property, T value, T... otherValues) { List list = Stream.concat(Stream.of(value), Stream.of(otherValues)) .map(property::getName) .sorted() .distinct() .map(string -> new KeyValueCondition.Term(string, false)) .toList(); this.putValue(property, new KeyValueCondition.Terms(list)); return this; } public final > ConditionBuilder negatedTerm(Property property, T value) { this.putValue(property, new KeyValueCondition.Terms(List.of(new KeyValueCondition.Term(property.getName(value), true)))); return this; } public Condition build() { return new KeyValueCondition(this.terms.buildOrThrow()); } }