NeighborsUpdateRenderer .java

net.minecraft.client.renderer.debug.NeighborsUpdateRenderer (class, 60 lines): members: LastUpdate, frustum, emitGizmos. imports: GizmoStyle, Gizmos.

net.minecraft.client.renderer.debugclass60 linesclient2.5 KB

Implements

API Surface (2)

void emitGizmos(final double camX, final double camY, final double camZ, final DebugValueAccess debugValues, final Frustum frustum, final float partialTicks)
NeighborsUpdateRenderer.LastUpdate tryCount(final int age)

Fields & Constants (1)

frustum

Full Source

NeighborsUpdateRenderer.java60 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.renderer.debug;
2
3
import java.util.HashMap;
4
import java.util.Map;
5
import java.util.Map.Entry;
6
import net.fabricmc.api.EnvType;
7
import net.fabricmc.api.Environment;
8
import net.minecraft.client.renderer.culling.Frustum;
9
import net.minecraft.core.BlockPos;
10
import net.minecraft.gizmos.GizmoStyle;
11
import net.minecraft.gizmos.Gizmos;
12
import net.minecraft.gizmos.TextGizmo.Style;
13
import net.minecraft.util.debug.DebugSubscriptions;
14
import net.minecraft.util.debug.DebugValueAccess;
15
import net.minecraft.world.phys.AABB;
16
import net.minecraft.world.phys.Vec3;
17
18
@Environment(EnvType.CLIENT)
19
public class NeighborsUpdateRenderer implements DebugRenderer.SimpleDebugRenderer {
20
	@Override
21
	public void emitGizmos(
22
		final double camX, final double camY, final double camZ, final DebugValueAccess debugValues, final Frustum frustum, final float partialTicks
23
	) {
24
		int shrinkTime = DebugSubscriptions.NEIGHBOR_UPDATES.expireAfterTicks();
25
		double shrinkSpeed = 1.0 / (shrinkTime * 2);
26
		Map<BlockPos, NeighborsUpdateRenderer.LastUpdate> lastUpdates = new HashMap<>();
27
		debugValues.forEachEvent(DebugSubscriptions.NEIGHBOR_UPDATES, (blockPos, remainingTicks, totalLifetime) -> {
28
			long age = totalLifetime - remainingTicks;
29
			NeighborsUpdateRenderer.LastUpdate lastUpdatex = lastUpdates.getOrDefault(blockPos, NeighborsUpdateRenderer.LastUpdate.NONE);
30
			lastUpdates.put(blockPos, lastUpdatex.tryCount((int)age));
31
		});
32
33
		for (Entry<BlockPos, NeighborsUpdateRenderer.LastUpdate> entry : lastUpdates.entrySet()) {
34
			BlockPos pos = entry.getKey();
35
			NeighborsUpdateRenderer.LastUpdate lastUpdate = entry.getValue();
36
			AABB aabb = new AABB(pos).inflate(0.002).deflate(shrinkSpeed * lastUpdate.age);
37
			Gizmos.cuboid(aabb, GizmoStyle.stroke(-1));
38
		}
39
40
		for (Entry<BlockPos, NeighborsUpdateRenderer.LastUpdate> entry : lastUpdates.entrySet()) {
41
			BlockPos pos = entry.getKey();
42
			NeighborsUpdateRenderer.LastUpdate lastUpdate = entry.getValue();
43
			Gizmos.billboardText(String.valueOf(lastUpdate.count), Vec3.atCenterOf(pos), Style.whiteAndCentered());
44
		}
45
	}
46
47
	@Environment(EnvType.CLIENT)
48
	private record LastUpdate(int count, int age) {
49
		private static final NeighborsUpdateRenderer.LastUpdate NONE = new NeighborsUpdateRenderer.LastUpdate(0, Integer.MAX_VALUE);
50
51
		public NeighborsUpdateRenderer.LastUpdate tryCount(final int age) {
52
			if (age == this.age) {
53
				return new NeighborsUpdateRenderer.LastUpdate(this.count + 1, age);
54
			} else {
55
				return age < this.age ? new NeighborsUpdateRenderer.LastUpdate(1, age) : this;
56
			}
57
		}
58
	}
59
}
60

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