HeightMapRenderer .java

net.minecraft.client.renderer.debug.HeightMapRenderer (class): members: CHUNK_DIST, BOX_HEIGHT, frustum, emitGizmos, minecraft. imports: Types, GizmoStyle.

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

Implements

API Surface (1)

void emitGizmos(final double camX, final double camY, final double camZ, final DebugValueAccess debugValues, final Frustum frustum, final float partialTicks)

Fields & Constants (4)

CHUNK_DIST
BOX_HEIGHT
minecraft
frustum

Full Source

HeightMapRenderer.java75 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.renderer.debug;
2
3
import java.util.Map.Entry;
4
import net.fabricmc.api.EnvType;
5
import net.fabricmc.api.Environment;
6
import net.minecraft.client.Minecraft;
7
import net.minecraft.client.renderer.culling.Frustum;
8
import net.minecraft.core.BlockPos;
9
import net.minecraft.core.SectionPos;
10
import net.minecraft.gizmos.GizmoStyle;
11
import net.minecraft.gizmos.Gizmos;
12
import net.minecraft.util.ARGB;
13
import net.minecraft.util.debug.DebugValueAccess;
14
import net.minecraft.world.level.ChunkPos;
15
import net.minecraft.world.level.LevelAccessor;
16
import net.minecraft.world.level.chunk.ChunkAccess;
17
import net.minecraft.world.level.levelgen.Heightmap;
18
import net.minecraft.world.level.levelgen.Heightmap.Types;
19
import net.minecraft.world.phys.AABB;
20
import org.joml.Vector3f;
21
22
@Environment(EnvType.CLIENT)
23
public class HeightMapRenderer implements DebugRenderer.SimpleDebugRenderer {
24
	private final Minecraft minecraft;
25
	private static final int CHUNK_DIST = 2;
26
	private static final float BOX_HEIGHT = 0.09375F;
27
28
	public HeightMapRenderer(final Minecraft minecraft) {
29
		this.minecraft = minecraft;
30
	}
31
32
	@Override
33
	public void emitGizmos(
34
		final double camX, final double camY, final double camZ, final DebugValueAccess debugValues, final Frustum frustum, final float partialTicks
35
	) {
36
		LevelAccessor level = this.minecraft.level;
37
		BlockPos playerPos = BlockPos.containing(camX, 0.0, camZ);
38
39
		for (int chunkX = -2; chunkX <= 2; chunkX++) {
40
			for (int chunkZ = -2; chunkZ <= 2; chunkZ++) {
41
				ChunkAccess chunk = level.getChunk(playerPos.offset(chunkX * 16, 0, chunkZ * 16));
42
43
				for (Entry<Types, Heightmap> heightmapEntry : chunk.getHeightmaps()) {
44
					Types type = heightmapEntry.getKey();
45
					ChunkPos chunkPos = chunk.getPos();
46
					Vector3f color = this.getColor(type);
47
48
					for (int relativeX = 0; relativeX < 16; relativeX++) {
49
						for (int relativeZ = 0; relativeZ < 16; relativeZ++) {
50
							int xx = SectionPos.sectionToBlockCoord(chunkPos.x(), relativeX);
51
							int zz = SectionPos.sectionToBlockCoord(chunkPos.z(), relativeZ);
52
							float height = level.getHeight(type, xx, zz) + type.ordinal() * 0.09375F;
53
							Gizmos.cuboid(
54
								new AABB(xx + 0.25F, height, zz + 0.25F, xx + 0.75F, height + 0.09375F, zz + 0.75F),
55
								GizmoStyle.fill(ARGB.colorFromFloat(1.0F, color.x(), color.y(), color.z()))
56
							);
57
						}
58
					}
59
				}
60
			}
61
		}
62
	}
63
64
	private Vector3f getColor(final Types type) {
65
		return switch (type) {
66
			case WORLD_SURFACE_WG -> new Vector3f(1.0F, 1.0F, 0.0F);
67
			case OCEAN_FLOOR_WG -> new Vector3f(1.0F, 0.0F, 1.0F);
68
			case WORLD_SURFACE -> new Vector3f(0.0F, 0.7F, 0.0F);
69
			case OCEAN_FLOOR -> new Vector3f(0.0F, 0.0F, 0.5F);
70
			case MOTION_BLOCKING -> new Vector3f(0.0F, 0.3F, 0.3F);
71
			case MOTION_BLOCKING_NO_LEAVES -> new Vector3f(0.0F, 0.5F, 0.5F);
72
		};
73
	}
74
}
75

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