TriState .java

net.minecraft.util.TriState (enum): members: TRUE, FALSE, DEFAULT, toBoolean, getSerializedName, name, CODEC. strings: "default". imports: Either.

net.minecraft.utilenum43 linescommon1022 B

Implements

API Surface (3)

TriState from(final boolean value)
boolean toBoolean(final boolean defaultValue)
String getSerializedName()

Fields & Constants (2)

CODEC
name

String literals (1)

"default"

Code Graph: Dependencies (1)

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

Full Source

TriState.java43 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.util;
2
3
import com.mojang.datafixers.util.Either;
4
import com.mojang.serialization.Codec;
5
import java.util.function.Function;
6
7
public enum TriState implements StringRepresentable {
8
	TRUE("true"),
9
	FALSE("false"),
10
	DEFAULT("default");
11
12
	public static final Codec<TriState> CODEC = Codec.either(Codec.BOOL, StringRepresentable.fromEnum(TriState::values))
13
		.xmap(either -> either.map(TriState::from, Function.identity()), triState -> {
14
			return switch (triState) {
15
				case TRUE -> Either.left(true);
16
				case FALSE -> Either.left(false);
17
				case DEFAULT -> Either.right(triState);
18
			};
19
		});
20
	private final String name;
21
22
	TriState(final String name) {
23
		this.name = name;
24
	}
25
26
	public static TriState from(final boolean value) {
27
		return value ? TRUE : FALSE;
28
	}
29
30
	public boolean toBoolean(final boolean defaultValue) {
31
		return switch (this) {
32
			case TRUE -> true;
33
			case FALSE -> false;
34
			default -> defaultValue;
35
		};
36
	}
37
38
	@Override
39
	public String getSerializedName() {
40
		return this.name;
41
	}
42
}
43

Decompiled Minecraft 26.3 source of TriState (net/minecraft/util/TriState.java) with Mojang official mappings, stored verbatim on the site.