ConditionBuilder .java

net.minecraft.client.data.models.blockstates.ConditionBuilder (class): members: negatedTerm, term, terms, build. imports: KeyValueCondition, Condition.

net.minecraft.client.data.models.blockstatesclass47 linesclient1.8 KB

API Surface (4)

<T extends Comparable<T>> ConditionBuilder term(final Property<T> property, final T value)
<T extends Comparable<T>> ConditionBuilder term(final Property<T> property, final T value, final T... values)
<T extends Comparable<T>> ConditionBuilder negatedTerm(final Property<T> property, final T value)
Condition build()

Fields & Constants (1)

terms

Code Graph: Dependencies (3)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

ConditionBuilder.java47 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.data.models.blockstates;
2
3
import com.google.common.collect.ImmutableMap;
4
import com.google.common.collect.ImmutableMap.Builder;
5
import java.util.List;
6
import java.util.stream.Stream;
7
import net.fabricmc.api.EnvType;
8
import net.fabricmc.api.Environment;
9
import net.minecraft.client.renderer.block.dispatch.multipart.Condition;
10
import net.minecraft.client.renderer.block.dispatch.multipart.KeyValueCondition;
11
import net.minecraft.world.level.block.state.properties.Property;
12
13
@Environment(EnvType.CLIENT)
14
public class ConditionBuilder {
15
	private final Builder<String, KeyValueCondition.Terms> terms = ImmutableMap.builder();
16
17
	private <T extends Comparable<T>> void putValue(final Property<T> property, final KeyValueCondition.Terms term) {
18
		this.terms.put(property.getName(), term);
19
	}
20
21
	public final <T extends Comparable<T>> ConditionBuilder term(final Property<T> property, final T value) {
22
		this.putValue(property, new KeyValueCondition.Terms(List.of(new KeyValueCondition.Term(property.getName(value), false))));
23
		return this;
24
	}
25
26
	@SafeVarargs
27
	public final <T extends Comparable<T>> ConditionBuilder term(final Property<T> property, final T value, final T... values) {
28
		List<KeyValueCondition.Term> terms = Stream.concat(Stream.of(value), Stream.of(values))
29
			.map(property::getName)
30
			.sorted()
31
			.distinct()
32
			.map(v -> new KeyValueCondition.Term(v, false))
33
			.toList();
34
		this.putValue(property, new KeyValueCondition.Terms(terms));
35
		return this;
36
	}
37
38
	public final <T extends Comparable<T>> ConditionBuilder negatedTerm(final Property<T> property, final T value) {
39
		this.putValue(property, new KeyValueCondition.Terms(List.of(new KeyValueCondition.Term(property.getName(value), true))));
40
		return this;
41
	}
42
43
	public Condition build() {
44
		return new KeyValueCondition(this.terms.buildOrThrow());
45
	}
46
}
47

Decompiled Minecraft 26.3 source of ConditionBuilder (net/minecraft/client/data/models/blockstates/ConditionBuilder.java) with Mojang official mappings, stored verbatim on the site.