LevelReader .java

net.minecraft.world.level.LevelReader (interface, 233 lines): members: findBlocksInBoxByManhattanDistance, getPathfindingCostFromLightLevels, holderLookup.

net.minecraft.world.levelinterface233 linescommonextends BlockAndLightGetter8.0 KB

API Surface (0)

No public/protected methods detected (fields or constants only).

Full Source

LevelReader.java233 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level;
2
3
import java.util.stream.Stream;
4
import net.minecraft.core.BlockPos;
5
import net.minecraft.core.Holder;
6
import net.minecraft.core.HolderLookup;
7
import net.minecraft.core.QuartPos;
8
import net.minecraft.core.Registry;
9
import net.minecraft.core.RegistryAccess;
10
import net.minecraft.core.SectionPos;
11
import net.minecraft.resources.ResourceKey;
12
import net.minecraft.tags.FluidTags;
13
import net.minecraft.util.Mth;
14
import net.minecraft.world.attribute.EnvironmentAttributeReader;
15
import net.minecraft.world.flag.FeatureFlagSet;
16
import net.minecraft.world.level.biome.Biome;
17
import net.minecraft.world.level.biome.BiomeManager;
18
import net.minecraft.world.level.biome.BiomeResolver;
19
import net.minecraft.world.level.block.state.BlockState;
20
import net.minecraft.world.level.blockscan.BlockMatcher;
21
import net.minecraft.world.level.blockscan.BoxBlockMatcher;
22
import net.minecraft.world.level.blockscan.OrderedBlockMatcher;
23
import net.minecraft.world.level.chunk.ChunkAccess;
24
import net.minecraft.world.level.chunk.status.ChunkStatus;
25
import net.minecraft.world.level.dimension.DimensionType;
26
import net.minecraft.world.level.levelgen.Heightmap;
27
import net.minecraft.world.phys.AABB;
28
import org.jspecify.annotations.Nullable;
29
30
public interface LevelReader extends BlockAndLightGetter, CollisionGetter, SignalGetter, BiomeResolver {
31
	@Nullable ChunkAccess getChunk(final int chunkX, final int chunkZ, final ChunkStatus targetStatus, final boolean loadOrGenerate);
32
33
	@Deprecated
34
	boolean hasChunk(int chunkX, int chunkZ);
35
36
	int getHeight(Heightmap.Types type, int x, int z);
37
38
	default int getHeight(final Heightmap.Types type, final BlockPos pos) {
39
		return this.getHeight(type, pos.getX(), pos.getZ());
40
	}
41
42
	int getSkyDarken();
43
44
	BiomeManager getBiomeManager();
45
46
	default Holder<Biome> getBiome(final BlockPos pos) {
47
		return this.getBiomeManager().getBiome(pos);
48
	}
49
50
	default Stream<BlockState> getBlockStatesIfLoaded(final AABB box) {
51
		int x0 = Mth.floor(box.minX);
52
		int x1 = Mth.floor(box.maxX);
53
		int y0 = Mth.floor(box.minY);
54
		int y1 = Mth.floor(box.maxY);
55
		int z0 = Mth.floor(box.minZ);
56
		int z1 = Mth.floor(box.maxZ);
57
		return this.hasChunksAt(x0, y0, z0, x1, y1, z1) ? this.getBlockStates(box) : Stream.empty();
58
	}
59
60
	@Override
61
	default Holder<Biome> getNoiseBiome(final int quartX, final int quartY, final int quartZ) {
62
		ChunkAccess chunk = this.getChunk(QuartPos.toSection(quartX), QuartPos.toSection(quartZ), ChunkStatus.BIOMES, false);
63
		return chunk != null ? chunk.getNoiseBiome(quartX, quartY, quartZ) : this.getUncachedNoiseBiome(quartX, quartY, quartZ);
64
	}
65
66
	Holder<Biome> getUncachedNoiseBiome(int quartX, int quartY, int quartZ);
67
68
	boolean isClientSide();
69
70
	int getSeaLevel();
71
72
	DimensionType dimensionType();
73
74
	@Override
75
	default int getMinY() {
76
		return this.dimensionType().minY();
77
	}
78
79
	@Override
80
	default int getHeight() {
81
		return this.dimensionType().height();
82
	}
83
84
	default BlockPos getHeightmapPos(final Heightmap.Types type, final BlockPos pos) {
85
		return new BlockPos(pos.getX(), this.getHeight(type, pos.getX(), pos.getZ()), pos.getZ());
86
	}
87
88
	default boolean isEmptyBlock(final BlockPos pos) {
89
		return this.getBlockState(pos).isAir();
90
	}
91
92
	default boolean canSeeSkyFromBelowWater(final BlockPos pos) {
93
		if (pos.getY() >= this.getSeaLevel()) {
94
			return this.canSeeSky(pos);
95
		}
96
97
		BlockPos scanPoint = new BlockPos(pos.getX(), this.getSeaLevel(), pos.getZ());
98
		if (!this.canSeeSky(scanPoint)) {
99
			return false;
100
		}
101
102
		for (BlockPos var4 = scanPoint.below(); var4.getY() > pos.getY(); var4 = var4.below()) {
103
			BlockState state = this.getBlockState(var4);
104
			if (state.getLightDampening() > 0 && !state.liquid()) {
105
				return false;
106
			}
107
		}
108
109
		return true;
110
	}
111
112
	default float getPathfindingCostFromLightLevels(final BlockPos pos) {
113
		return this.getLightLevelDependentMagicValue(pos) - 0.5F;
114
	}
115
116
	@Deprecated
117
	default float getLightLevelDependentMagicValue(final BlockPos pos) {
118
		float v = this.getMaxLocalRawBrightness(pos) / 15.0F;
119
		float curvedV = v / (4.0F - 3.0F * v);
120
		return Mth.lerp(this.dimensionType().ambientLight(), curvedV, 1.0F);
121
	}
122
123
	default ChunkAccess getChunk(final BlockPos pos) {
124
		return this.getChunk(SectionPos.blockToSectionCoord(pos.getX()), SectionPos.blockToSectionCoord(pos.getZ()));
125
	}
126
127
	default ChunkAccess getChunk(final int chunkX, final int chunkZ) {
128
		return this.getChunk(chunkX, chunkZ, ChunkStatus.FULL, true);
129
	}
130
131
	default ChunkAccess getChunk(final int chunkX, final int chunkZ, final ChunkStatus status) {
132
		return this.getChunk(chunkX, chunkZ, status, true);
133
	}
134
135
	@Override
136
	default @Nullable BlockGetter getChunkForCollisions(final int chunkX, final int chunkZ) {
137
		return this.getChunk(chunkX, chunkZ, ChunkStatus.EMPTY, false);
138
	}
139
140
	default boolean isWaterAt(final BlockPos pos) {
141
		return this.getFluidState(pos).is(FluidTags.WATER);
142
	}
143
144
	default boolean containsAnyLiquid(final AABB box) {
145
		return this.findBlocksIn(box).filterState(state -> !state.getFluidState().isEmpty()).anyMatched();
146
	}
147
148
	default int getMaxLocalRawBrightness(final BlockPos pos) {
149
		return this.getMaxLocalRawBrightness(pos, this.getSkyDarken());
150
	}
151
152
	default int getMaxLocalRawBrightness(final BlockPos pos, final int skyDarkening) {
153
		return pos.getX() >= -30000000 && pos.getZ() >= -30000000 && pos.getX() < 30000000 && pos.getZ() < 30000000 ? this.getRawBrightness(pos, skyDarkening) : 15;
154
	}
155
156
	default int getEffectiveSkyBrightness(final BlockPos pos) {
157
		return Math.max(this.getBrightness(LightLayer.SKY, pos) - this.getSkyDarken(), 0);
158
	}
159
160
	default BlockMatcher findBlocksIn(final AABB box) {
161
		return this.findBlocksIn(BlockPos.containing(box.getMinPosition()), BlockPos.containing(box.getMaxPosition()));
162
	}
163
164
	default BlockMatcher findBlocksIn(final BlockPos from, final BlockPos to) {
165
		return new BoxBlockMatcher(this, from, to);
166
	}
167
168
	default OrderedBlockMatcher findBlocksIn(final Iterable<BlockPos> positions) {
169
		return new OrderedBlockMatcher(this, positions);
170
	}
171
172
	default OrderedBlockMatcher findBlocksInBoxByManhattanDistance(final BlockPos origin, final int range) {
173
		return this.findBlocksIn(BlockPos.withinBoxByManhattanDistance(origin, range, range, range));
174
	}
175
176
	default OrderedBlockMatcher findBlocksInBoxByManhattanDistance(final BlockPos origin, final int rangeXZ, final int rangeY) {
177
		return this.findBlocksIn(BlockPos.withinBoxByManhattanDistance(origin, rangeXZ, rangeY, rangeXZ));
178
	}
179
180
	default OrderedBlockMatcher findBlocksInManhattan(final BlockPos origin, final int range) {
181
		return this.findBlocksIn(BlockPos.withinManhattan(origin, range));
182
	}
183
184
	@Deprecated
185
	default boolean hasChunkAt(final int blockX, final int blockZ) {
186
		return this.hasChunk(SectionPos.blockToSectionCoord(blockX), SectionPos.blockToSectionCoord(blockZ));
187
	}
188
189
	@Deprecated
190
	default boolean hasChunkAt(final BlockPos pos) {
191
		return this.hasChunkAt(pos.getX(), pos.getZ());
192
	}
193
194
	@Deprecated
195
	default boolean hasChunksAt(final BlockPos pos0, final BlockPos pos1) {
196
		return this.hasChunksAt(pos0.getX(), pos0.getY(), pos0.getZ(), pos1.getX(), pos1.getY(), pos1.getZ());
197
	}
198
199
	@Deprecated
200
	default boolean hasChunksAt(final int x0, final int y0, final int z0, final int x1, final int y1, final int z1) {
201
		return y1 >= this.getMinY() && y0 <= this.getMaxY() ? this.hasChunksAt(x0, z0, x1, z1) : false;
202
	}
203
204
	@Deprecated
205
	default boolean hasChunksAt(final int x0, final int z0, final int x1, final int z1) {
206
		int chunkX0 = SectionPos.blockToSectionCoord(x0);
207
		int chunkX1 = SectionPos.blockToSectionCoord(x1);
208
		int chunkZ0 = SectionPos.blockToSectionCoord(z0);
209
		int chunkZ1 = SectionPos.blockToSectionCoord(z1);
210
211
		for (int chunkX = chunkX0; chunkX <= chunkX1; chunkX++) {
212
			for (int chunkZ = chunkZ0; chunkZ <= chunkZ1; chunkZ++) {
213
				if (!this.hasChunk(chunkX, chunkZ)) {
214
					return false;
215
				}
216
			}
217
		}
218
219
		return true;
220
	}
221
222
	RegistryAccess registryAccess();
223
224
	FeatureFlagSet enabledFeatures();
225
226
	default <T> HolderLookup<T> holderLookup(final ResourceKey<? extends Registry<? extends T>> key) {
227
		Registry<T> registry = this.registryAccess().lookupOrThrow(key);
228
		return registry.filterFeatures(this.enabledFeatures());
229
	}
230
231
	EnvironmentAttributeReader environmentAttributes();
232
}
233

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