LevelSettings .java

net.minecraft.world.level.LevelSettings (record, 70 lines): members: levelName, gameType, difficultySettings, allowCommands, dataConfiguration, copy.

net.minecraft.world.levelrecord70 linescommon2.9 KB

API Surface (9)

record LevelSettings(String levelName, GameType gameType, LevelSettings.DifficultySettings difficultySettings, boolean allowCommands, WorldDataConfiguration dataConfiguration)
LevelSettings parse(final Dynamic<?> input, final WorldDataConfiguration loadConfig)
LevelSettings withGameType(final GameType gameType)
LevelSettings withAllowCommands(final boolean allowCommands)
LevelSettings withDifficulty(final Difficulty difficulty)
LevelSettings withDifficultyLock(final boolean locked)
LevelSettings withDataConfiguration(final WorldDataConfiguration dataConfiguration)
LevelSettings copy()
record DifficultySettings(Difficulty difficulty, boolean hardcore, boolean locked)

String literals (7)

"GameType"
"LevelName"
"difficulty_settings"
"allowCommands"
"difficulty"
"hardcore"
"locked"

Code Graph: Dependencies (3)

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

Full Source

LevelSettings.java70 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level;
2
3
import com.mojang.serialization.Codec;
4
import com.mojang.serialization.Dynamic;
5
import com.mojang.serialization.codecs.RecordCodecBuilder;
6
import net.minecraft.world.Difficulty;
7
8
public record LevelSettings(
9
	String levelName, GameType gameType, LevelSettings.DifficultySettings difficultySettings, boolean allowCommands, WorldDataConfiguration dataConfiguration
10
) {
11
	public static LevelSettings parse(final Dynamic<?> input, final WorldDataConfiguration loadConfig) {
12
		GameType gameType = GameType.byId(input.get("GameType").asInt(0));
13
		return new LevelSettings(
14
			input.get("LevelName").asString(""),
15
			gameType,
16
			input.get("difficulty_settings").read(LevelSettings.DifficultySettings.CODEC).result().orElse(LevelSettings.DifficultySettings.DEFAULT),
17
			input.get("allowCommands").asBoolean(gameType == GameType.CREATIVE),
18
			loadConfig
19
		);
20
	}
21
22
	public LevelSettings withGameType(final GameType gameType) {
23
		return new LevelSettings(this.levelName, gameType, this.difficultySettings, this.allowCommands, this.dataConfiguration);
24
	}
25
26
	public LevelSettings withAllowCommands(final boolean allowCommands) {
27
		return new LevelSettings(this.levelName, this.gameType, this.difficultySettings, allowCommands, this.dataConfiguration);
28
	}
29
30
	public LevelSettings withDifficulty(final Difficulty difficulty) {
31
		return new LevelSettings(
32
			this.levelName,
33
			this.gameType,
34
			new LevelSettings.DifficultySettings(difficulty, this.difficultySettings.hardcore(), this.difficultySettings.locked()),
35
			this.allowCommands,
36
			this.dataConfiguration
37
		);
38
	}
39
40
	public LevelSettings withDifficultyLock(final boolean locked) {
41
		return new LevelSettings(
42
			this.levelName,
43
			this.gameType,
44
			new LevelSettings.DifficultySettings(this.difficultySettings.difficulty(), this.difficultySettings.hardcore(), locked),
45
			this.allowCommands,
46
			this.dataConfiguration
47
		);
48
	}
49
50
	public LevelSettings withDataConfiguration(final WorldDataConfiguration dataConfiguration) {
51
		return new LevelSettings(this.levelName, this.gameType, this.difficultySettings, this.allowCommands, dataConfiguration);
52
	}
53
54
	public LevelSettings copy() {
55
		return new LevelSettings(this.levelName, this.gameType, this.difficultySettings, this.allowCommands, this.dataConfiguration);
56
	}
57
58
	public record DifficultySettings(Difficulty difficulty, boolean hardcore, boolean locked) {
59
		public static final LevelSettings.DifficultySettings DEFAULT = new LevelSettings.DifficultySettings(Difficulty.NORMAL, false, false);
60
		public static final Codec<LevelSettings.DifficultySettings> CODEC = RecordCodecBuilder.create(
61
			i -> i.group(
62
					Difficulty.CODEC.fieldOf("difficulty").forGetter(LevelSettings.DifficultySettings::difficulty),
63
					Codec.BOOL.fieldOf("hardcore").forGetter(LevelSettings.DifficultySettings::hardcore),
64
					Codec.BOOL.fieldOf("locked").forGetter(LevelSettings.DifficultySettings::locked)
65
				)
66
				.apply(i, LevelSettings.DifficultySettings::new)
67
		);
68
	}
69
}
70

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