KeybindContents .java

net.minecraft.network.chat.contents.KeybindContents (class, 67 lines): members: nameResolver, visit, hashCode, equals, getName, name, MAP_CODEC, codec.

net.minecraft.network.chat.contentsclass67 linescommon1.8 KB

Implements

API Surface (7)

<T> Optional<T> visit(final FormattedText.ContentConsumer<T> output)
<T> Optional<T> visit(final FormattedText.StyledContentConsumer<T> output, final Style currentStyle)
boolean equals(final Object o)
int hashCode()
String toString()
String getName()
MapCodec<KeybindContents> codec()

Fields & Constants (3)

MAP_CODEC
name
nameResolver

String literals (2)

"keybind"
"keybind{"

Code Graph: Dependencies (4)

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

Full Source

KeybindContents.java67 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.network.chat.contents;
2
3
import com.mojang.serialization.Codec;
4
import com.mojang.serialization.MapCodec;
5
import com.mojang.serialization.codecs.RecordCodecBuilder;
6
import java.util.Optional;
7
import java.util.function.Supplier;
8
import net.minecraft.network.chat.Component;
9
import net.minecraft.network.chat.ComponentContents;
10
import net.minecraft.network.chat.FormattedText;
11
import net.minecraft.network.chat.Style;
12
import org.jspecify.annotations.Nullable;
13
14
public class KeybindContents implements ComponentContents {
15
	public static final MapCodec<KeybindContents> MAP_CODEC = RecordCodecBuilder.mapCodec(
16
		i -> i.group(Codec.STRING.fieldOf("keybind").forGetter(o -> o.name)).apply(i, KeybindContents::new)
17
	);
18
	private final String name;
19
	private @Nullable Supplier<Component> nameResolver;
20
21
	public KeybindContents(final String name) {
22
		this.name = name;
23
	}
24
25
	private Component getNestedComponent() {
26
		if (this.nameResolver == null) {
27
			this.nameResolver = KeybindResolver.keyResolver.apply(this.name);
28
		}
29
30
		return this.nameResolver.get();
31
	}
32
33
	@Override
34
	public <T> Optional<T> visit(final FormattedText.ContentConsumer<T> output) {
35
		return this.getNestedComponent().visit(output);
36
	}
37
38
	@Override
39
	public <T> Optional<T> visit(final FormattedText.StyledContentConsumer<T> output, final Style currentStyle) {
40
		return this.getNestedComponent().visit(output, currentStyle);
41
	}
42
43
	@Override
44
	public boolean equals(final Object o) {
45
		return this == o ? true : o instanceof KeybindContents that && this.name.equals(that.name);
46
	}
47
48
	@Override
49
	public int hashCode() {
50
		return this.name.hashCode();
51
	}
52
53
	@Override
54
	public String toString() {
55
		return "keybind{" + this.name + "}";
56
	}
57
58
	public String getName() {
59
		return this.name;
60
	}
61
62
	@Override
63
	public MapCodec<KeybindContents> codec() {
64
		return MAP_CODEC;
65
	}
66
}
67

Decompiled Minecraft 26.3 source of KeybindContents (net/minecraft/network/chat/contents/KeybindContents.java) with Mojang official mappings, stored verbatim on the site.