RenderRegionCache .java

net.minecraft.client.renderer.chunk.RenderRegionCache (class, 47 lines): members: sectionCopyCache, createRegion. imports: Long2ObjectMap, LevelChunk.

net.minecraft.client.renderer.chunkclass47 linesclient2.0 KB

API Surface (1)

RenderSectionRegion createRegion(final ClientLevel level, final long sectionNode)

Fields & Constants (1)

sectionCopyCache

Code Graph: Dependencies (6)

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

Full Source

RenderRegionCache.java47 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.renderer.chunk;
2
3
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
4
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
5
import net.fabricmc.api.EnvType;
6
import net.fabricmc.api.Environment;
7
import net.minecraft.client.multiplayer.ClientLevel;
8
import net.minecraft.core.SectionPos;
9
import net.minecraft.world.level.Level;
10
import net.minecraft.world.level.chunk.LevelChunk;
11
12
@Environment(EnvType.CLIENT)
13
public class RenderRegionCache {
14
	private final Long2ObjectMap<SectionCopy> sectionCopyCache = new Long2ObjectOpenHashMap<>();
15
16
	public RenderSectionRegion createRegion(final ClientLevel level, final long sectionNode) {
17
		int sectionX = SectionPos.x(sectionNode);
18
		int sectionY = SectionPos.y(sectionNode);
19
		int sectionZ = SectionPos.z(sectionNode);
20
		int minSectionX = sectionX - 1;
21
		int minSectionY = sectionY - 1;
22
		int minSectionZ = sectionZ - 1;
23
		int maxSectionX = sectionX + 1;
24
		int maxSectionY = sectionY + 1;
25
		int maxSectionZ = sectionZ + 1;
26
		SectionCopy[] regionSections = new SectionCopy[27];
27
28
		for (int regionSectionZ = minSectionZ; regionSectionZ <= maxSectionZ; regionSectionZ++) {
29
			for (int regionSectionY = minSectionY; regionSectionY <= maxSectionY; regionSectionY++) {
30
				for (int regionSectionX = minSectionX; regionSectionX <= maxSectionX; regionSectionX++) {
31
					int index = RenderSectionRegion.index(minSectionX, minSectionY, minSectionZ, regionSectionX, regionSectionY, regionSectionZ);
32
					regionSections[index] = this.getSectionDataCopy(level, regionSectionX, regionSectionY, regionSectionZ);
33
				}
34
			}
35
		}
36
37
		return new RenderSectionRegion(level, minSectionX, minSectionY, minSectionZ, regionSections);
38
	}
39
40
	private SectionCopy getSectionDataCopy(final Level level, final int sectionX, final int sectionY, final int sectionZ) {
41
		return this.sectionCopyCache.computeIfAbsent(SectionPos.asLong(sectionX, sectionY, sectionZ), k -> {
42
			LevelChunk chunk = level.getChunk(sectionX, sectionZ);
43
			return new SectionCopy(chunk, chunk.getSectionIndexFromSectionY(sectionY));
44
		});
45
	}
46
}
47

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