NarrationThunk .java

net.minecraft.client.gui.narration.NarrationThunk (class): members: getText, converter, contents, hashCode, equals, EMPTY. imports: Unit, Component.

net.minecraft.client.gui.narrationclass53 linesclient1.6 KB

API Surface (6)

NarrationThunk<?> from(final String text)
NarrationThunk<?> from(final Component text)
NarrationThunk<?> from(final List<Component> lines)
void getText(final Consumer<String> output)
boolean equals(final Object o)
int hashCode()

Fields & Constants (3)

EMPTY
contents
converter

Code Graph: Dependencies (2)

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

Full Source

NarrationThunk.java53 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.gui.narration;
2
3
import java.util.List;
4
import java.util.function.BiConsumer;
5
import java.util.function.Consumer;
6
import net.fabricmc.api.EnvType;
7
import net.fabricmc.api.Environment;
8
import net.minecraft.network.chat.Component;
9
import net.minecraft.util.Unit;
10
11
@Environment(EnvType.CLIENT)
12
public class NarrationThunk<T> {
13
	private final T contents;
14
	private final BiConsumer<Consumer<String>, T> converter;
15
	public static final NarrationThunk<?> EMPTY = new NarrationThunk<>(Unit.INSTANCE, (o, c) -> {});
16
17
	private NarrationThunk(final T contents, final BiConsumer<Consumer<String>, T> converter) {
18
		this.contents = contents;
19
		this.converter = converter;
20
	}
21
22
	public static NarrationThunk<?> from(final String text) {
23
		return new NarrationThunk<>(text, Consumer::accept);
24
	}
25
26
	public static NarrationThunk<?> from(final Component text) {
27
		return new NarrationThunk<>(text, (o, c) -> o.accept(c.getString()));
28
	}
29
30
	public static NarrationThunk<?> from(final List<Component> lines) {
31
		return new NarrationThunk<>(lines, (o, c) -> lines.stream().map(Component::getString).forEach(o));
32
	}
33
34
	public void getText(final Consumer<String> output) {
35
		this.converter.accept(output, this.contents);
36
	}
37
38
	@Override
39
	public boolean equals(final Object o) {
40
		if (this == o) {
41
			return true;
42
		} else {
43
			return !(o instanceof NarrationThunk<?> thunk) ? false : thunk.converter == this.converter && thunk.contents.equals(this.contents);
44
		}
45
	}
46
47
	@Override
48
	public int hashCode() {
49
		int result = this.contents.hashCode();
50
		return 31 * result + this.converter.hashCode();
51
	}
52
}
53

Decompiled Minecraft 26.3 source of NarrationThunk (net/minecraft/client/gui/narration/NarrationThunk.java) with Mojang official mappings, stored verbatim on the site.