Difficulty .java

net.minecraft.world.Difficulty (enum, 55 lines): members: PEACEFUL, EASY, NORMAL, HARD, getInfo, byName, byId, getDisplayName, BY_ID, key, getId, CODEC.

net.minecraft.worldenum55 linescommon1.5 KB

Implements

API Surface (5)

int getId()
Component getDisplayName()
Component getInfo()
Difficulty byId(final int id)
String getSerializedName()

Fields & Constants (5)

CODEC
BY_ID
STREAM_CODEC
id
key

String literals (6)

"peaceful"
"easy"
"normal"
"hard"
"options.difficulty."
".info"

Code Graph: Dependencies (5)

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

Full Source

Difficulty.java55 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world;
2
3
import io.netty.buffer.ByteBuf;
4
import java.util.function.IntFunction;
5
import net.minecraft.network.chat.Component;
6
import net.minecraft.network.codec.ByteBufCodecs;
7
import net.minecraft.network.codec.StreamCodec;
8
import net.minecraft.util.ByIdMap;
9
import net.minecraft.util.StringRepresentable;
10
import org.jspecify.annotations.Nullable;
11
12
public enum Difficulty implements StringRepresentable {
13
	PEACEFUL(0, "peaceful"),
14
	EASY(1, "easy"),
15
	NORMAL(2, "normal"),
16
	HARD(3, "hard");
17
18
	public static final StringRepresentable.EnumCodec<Difficulty> CODEC = StringRepresentable.fromEnum(Difficulty::values);
19
	private static final IntFunction<Difficulty> BY_ID = ByIdMap.continuous(Difficulty::getId, values(), ByIdMap.OutOfBoundsStrategy.WRAP);
20
	public static final StreamCodec<ByteBuf, Difficulty> STREAM_CODEC = ByteBufCodecs.idMapper(BY_ID, Difficulty::getId);
21
	private final int id;
22
	private final String key;
23
24
	Difficulty(final int id, final String key) {
25
		this.id = id;
26
		this.key = key;
27
	}
28
29
	public int getId() {
30
		return this.id;
31
	}
32
33
	public Component getDisplayName() {
34
		return Component.translatable("options.difficulty." + this.key);
35
	}
36
37
	public Component getInfo() {
38
		return Component.translatable("options.difficulty." + this.key + ".info");
39
	}
40
41
	@Deprecated
42
	public static Difficulty byId(final int id) {
43
		return BY_ID.apply(id);
44
	}
45
46
	public static @Nullable Difficulty byName(final String name) {
47
		return CODEC.byName(name);
48
	}
49
50
	@Override
51
	public String getSerializedName() {
52
		return this.key;
53
	}
54
}
55

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