SectionCopy .java

net.minecraft.client.renderer.chunk.SectionCopy (class): members: debug, blockEntities, section, levelHeightAccessor, getBlockEntity, getBlockState.

net.minecraft.client.renderer.chunkclass81 linesclient2.8 KB

API Surface (1)

BlockState getBlockState(final BlockPos pos)

Fields & Constants (4)

blockEntities
section
debug
levelHeightAccessor

String literals (3)

"Getting block state"
"Block being got"
"Location"

Full Source

SectionCopy.java81 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.renderer.chunk;
2
3
import com.google.common.collect.ImmutableMap;
4
import java.util.Map;
5
import net.fabricmc.api.EnvType;
6
import net.fabricmc.api.Environment;
7
import net.minecraft.CrashReport;
8
import net.minecraft.CrashReportCategory;
9
import net.minecraft.ReportedException;
10
import net.minecraft.core.BlockPos;
11
import net.minecraft.world.level.LevelHeightAccessor;
12
import net.minecraft.world.level.block.Blocks;
13
import net.minecraft.world.level.block.entity.BlockEntity;
14
import net.minecraft.world.level.block.state.BlockState;
15
import net.minecraft.world.level.chunk.EmptyLevelChunk;
16
import net.minecraft.world.level.chunk.LevelChunk;
17
import net.minecraft.world.level.chunk.LevelChunkSection;
18
import net.minecraft.world.level.chunk.PalettedContainer;
19
import net.minecraft.world.level.levelgen.DebugLevelSource;
20
import org.jspecify.annotations.Nullable;
21
22
@Environment(EnvType.CLIENT)
23
public class SectionCopy {
24
	private final Map<BlockPos, BlockEntity> blockEntities;
25
	private final @Nullable PalettedContainer<BlockState> section;
26
	private final boolean debug;
27
	private final LevelHeightAccessor levelHeightAccessor;
28
29
	public SectionCopy(final LevelChunk levelChunk, final int sectionIndex) {
30
		this.levelHeightAccessor = levelChunk;
31
		this.debug = levelChunk.getLevel().isDebug();
32
		this.blockEntities = ImmutableMap.copyOf(levelChunk.getBlockEntities());
33
		if (levelChunk instanceof EmptyLevelChunk) {
34
			this.section = null;
35
		} else {
36
			LevelChunkSection[] sections = levelChunk.getSections();
37
			if (sectionIndex >= 0 && sectionIndex < sections.length) {
38
				LevelChunkSection levelChunkSection = sections[sectionIndex];
39
				this.section = levelChunkSection.hasOnlyAir() ? null : levelChunkSection.getStates().copy();
40
			} else {
41
				this.section = null;
42
			}
43
		}
44
	}
45
46
	public @Nullable BlockEntity getBlockEntity(final BlockPos pos) {
47
		return this.blockEntities.get(pos);
48
	}
49
50
	public BlockState getBlockState(final BlockPos pos) {
51
		int x = pos.getX();
52
		int y = pos.getY();
53
		int z = pos.getZ();
54
		if (this.debug) {
55
			BlockState blockState = null;
56
			if (y == 60) {
57
				blockState = Blocks.BARRIER.defaultBlockState();
58
			}
59
60
			if (y == 70) {
61
				blockState = DebugLevelSource.getBlockStateFor(x, z);
62
			}
63
64
			return blockState == null ? Blocks.AIR.defaultBlockState() : blockState;
65
		} else {
66
			if (this.section == null) {
67
				return Blocks.AIR.defaultBlockState();
68
			}
69
70
			try {
71
				return this.section.get(x & 15, y & 15, z & 15);
72
			} catch (Throwable t) {
73
				CrashReport report = CrashReport.forThrowable(t, "Getting block state");
74
				CrashReportCategory category = report.addCategory("Block being got");
75
				category.setDetail("Location", () -> CrashReportCategory.formatLocation(this.levelHeightAccessor, x, y, z));
76
				throw new ReportedException(report);
77
			}
78
		}
79
	}
80
}
81

Decompiled Minecraft 26.3 source of SectionCopy (net/minecraft/client/renderer/chunk/SectionCopy.java) with Mojang official mappings, stored verbatim on the site.