EnchantmentNames .java

net.minecraft.client.gui.screens.inventory.EnchantmentNames (class): members: getRandomName, ROOT_STYLE, ALT_FONT, initSeed, words, getInstance, INSTANCE.

net.minecraft.client.gui.screens.inventoryclass112 linesclient2.2 KB

API Surface (3)

EnchantmentNames getInstance()
FormattedText getRandomName(final Font font, final int maxWidth)
void initSeed(final long seed)

Fields & Constants (5)

ALT_FONT
ROOT_STYLE
INSTANCE
random
words

String literals (56)

"elder"
"scrolls"
"klaatu"
"berata"
"niktu"
"xyzzy"
"bless"
"curse"
"light"
"darkness"
"fire"
"earth"
"water"
"cold"
"ignite"
"snuff"
"embiggen"
"twist"
"shorten"
"stretch"
"fiddle"
"destroy"
"imbue"
"galvanize"

Full Source

EnchantmentNames.java112 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.gui.screens.inventory;
2
3
import net.fabricmc.api.EnvType;
4
import net.fabricmc.api.Environment;
5
import net.minecraft.client.gui.Font;
6
import net.minecraft.network.chat.Component;
7
import net.minecraft.network.chat.FontDescription;
8
import net.minecraft.network.chat.FormattedText;
9
import net.minecraft.network.chat.Style;
10
import net.minecraft.network.chat.FontDescription.Resource;
11
import net.minecraft.resources.Identifier;
12
import net.minecraft.util.RandomSource;
13
import net.minecraft.util.Util;
14
15
@Environment(EnvType.CLIENT)
16
public class EnchantmentNames {
17
	private static final FontDescription ALT_FONT = new Resource(Identifier.withDefaultNamespace("alt"));
18
	private static final Style ROOT_STYLE = Style.EMPTY.withFont(ALT_FONT);
19
	private static final EnchantmentNames INSTANCE = new EnchantmentNames();
20
	private final RandomSource random = RandomSource.create();
21
	private final String[] words = new String[]{
22
		"the",
23
		"elder",
24
		"scrolls",
25
		"klaatu",
26
		"berata",
27
		"niktu",
28
		"xyzzy",
29
		"bless",
30
		"curse",
31
		"light",
32
		"darkness",
33
		"fire",
34
		"air",
35
		"earth",
36
		"water",
37
		"hot",
38
		"dry",
39
		"cold",
40
		"wet",
41
		"ignite",
42
		"snuff",
43
		"embiggen",
44
		"twist",
45
		"shorten",
46
		"stretch",
47
		"fiddle",
48
		"destroy",
49
		"imbue",
50
		"galvanize",
51
		"enchant",
52
		"free",
53
		"limited",
54
		"range",
55
		"of",
56
		"towards",
57
		"inside",
58
		"sphere",
59
		"cube",
60
		"self",
61
		"other",
62
		"ball",
63
		"mental",
64
		"physical",
65
		"grow",
66
		"shrink",
67
		"demon",
68
		"elemental",
69
		"spirit",
70
		"animal",
71
		"creature",
72
		"beast",
73
		"humanoid",
74
		"undead",
75
		"fresh",
76
		"stale",
77
		"phnglui",
78
		"mglwnafh",
79
		"cthulhu",
80
		"rlyeh",
81
		"wgahnagl",
82
		"fhtagn",
83
		"baguette"
84
	};
85
86
	private EnchantmentNames() {
87
	}
88
89
	public static EnchantmentNames getInstance() {
90
		return INSTANCE;
91
	}
92
93
	public FormattedText getRandomName(final Font font, final int maxWidth) {
94
		StringBuilder result = new StringBuilder();
95
		int wordCount = this.random.nextInt(2) + 3;
96
97
		for (int i = 0; i < wordCount; i++) {
98
			if (i != 0) {
99
				result.append(" ");
100
			}
101
102
			result.append(Util.getRandom(this.words, this.random));
103
		}
104
105
		return font.getSplitter().headByWidth(Component.literal(result.toString()).withStyle(ROOT_STYLE), maxWidth, Style.EMPTY);
106
	}
107
108
	public void initSeed(final long seed) {
109
		this.random.setSeed(seed);
110
	}
111
}
112

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