LevelData .java

net.minecraft.world.level.storage.LevelData (interface): members: RespawnData, isDifficultyLocked, getGameTime, getRespawnData, getDifficulty, isHardcore.

net.minecraft.world.level.storageinterface67 linescommon2.5 KB

API Surface (3)

LevelData.RespawnData of(final ResourceKey<Level> dimension, final BlockPos pos, final float yaw, final float pitch)
ResourceKey<Level> dimension()
BlockPos pos()

String literals (2)

"Level spawn location"
"pitch"

Full Source

LevelData.java67 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.storage;
2
3
import com.mojang.serialization.Codec;
4
import com.mojang.serialization.MapCodec;
5
import com.mojang.serialization.codecs.RecordCodecBuilder;
6
import io.netty.buffer.ByteBuf;
7
import net.minecraft.CrashReportCategory;
8
import net.minecraft.core.BlockPos;
9
import net.minecraft.core.GlobalPos;
10
import net.minecraft.network.codec.ByteBufCodecs;
11
import net.minecraft.network.codec.StreamCodec;
12
import net.minecraft.resources.ResourceKey;
13
import net.minecraft.util.Mth;
14
import net.minecraft.world.Difficulty;
15
import net.minecraft.world.level.Level;
16
import net.minecraft.world.level.LevelHeightAccessor;
17
18
public interface LevelData {
19
	LevelData.RespawnData getRespawnData();
20
21
	long getGameTime();
22
23
	boolean isHardcore();
24
25
	Difficulty getDifficulty();
26
27
	boolean isDifficultyLocked();
28
29
	default void fillCrashReportCategory(final CrashReportCategory category, final LevelHeightAccessor levelHeightAccessor) {
30
		category.setDetail("Level spawn location", () -> CrashReportCategory.formatLocation(levelHeightAccessor, this.getRespawnData().pos()));
31
	}
32
33
	record RespawnData(GlobalPos globalPos, float yaw, float pitch) {
34
		public static final LevelData.RespawnData DEFAULT = new LevelData.RespawnData(GlobalPos.of(Level.OVERWORLD, BlockPos.ZERO), 0.0F, 0.0F);
35
		public static final MapCodec<LevelData.RespawnData> MAP_CODEC = RecordCodecBuilder.mapCodec(
36
			i -> i.group(
37
					GlobalPos.MAP_CODEC.forGetter(LevelData.RespawnData::globalPos),
38
					Codec.floatRange(-180.0F, 180.0F).fieldOf("yaw").forGetter(LevelData.RespawnData::yaw),
39
					Codec.floatRange(-90.0F, 90.0F).fieldOf("pitch").forGetter(LevelData.RespawnData::pitch)
40
				)
41
				.apply(i, LevelData.RespawnData::new)
42
		);
43
		public static final Codec<LevelData.RespawnData> CODEC = MAP_CODEC.codec();
44
		public static final StreamCodec<ByteBuf, LevelData.RespawnData> STREAM_CODEC = StreamCodec.composite(
45
			GlobalPos.STREAM_CODEC,
46
			LevelData.RespawnData::globalPos,
47
			ByteBufCodecs.FLOAT,
48
			LevelData.RespawnData::yaw,
49
			ByteBufCodecs.FLOAT,
50
			LevelData.RespawnData::pitch,
51
			LevelData.RespawnData::new
52
		);
53
54
		public static LevelData.RespawnData of(final ResourceKey<Level> dimension, final BlockPos pos, final float yaw, final float pitch) {
55
			return new LevelData.RespawnData(GlobalPos.of(dimension, pos.immutable()), Mth.wrapDegrees(yaw), Mth.clamp(pitch, -90.0F, 90.0F));
56
		}
57
58
		public ResourceKey<Level> dimension() {
59
			return this.globalPos.dimension();
60
		}
61
62
		public BlockPos pos() {
63
			return this.globalPos.pos();
64
		}
65
	}
66
}
67

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