BeeDebugRenderer .java

net.minecraft.client.renderer.debug.BeeDebugRenderer (class): members: SHOW_TRAVEL_TICKS_FOR_SELECTED_BEE, MAX_RENDER_DIST_FOR_HIVE_OVERLAY, PINK, ORANGE.

net.minecraft.client.renderer.debugclass233 linesclient9.6 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 (23)

SHOW_GOAL_FOR_ALL_BEES
SHOW_NAME_FOR_ALL_BEES
SHOW_HIVE_FOR_ALL_BEES
SHOW_FLOWER_POS_FOR_ALL_BEES
SHOW_TRAVEL_TICKS_FOR_ALL_BEES
SHOW_GOAL_FOR_SELECTED_BEE
SHOW_NAME_FOR_SELECTED_BEE
SHOW_HIVE_FOR_SELECTED_BEE
SHOW_FLOWER_POS_FOR_SELECTED_BEE
SHOW_TRAVEL_TICKS_FOR_SELECTED_BEE
SHOW_HIVE_MEMBERS
SHOW_BLACKLISTS
MAX_RENDER_DIST_FOR_HIVE_OVERLAY
MAX_RENDER_DIST_FOR_BEE_OVERLAY
MAX_TARGETING_DIST
TEXT_SCALE
ORANGE
GRAY
PINK
minecraft
lastLookedAtUuid
frustum
beesWhoBlacklistThisHive

String literals (15)

"Flower"
" bees"
"Ghost Hive"
"Blacklisted by "
"Out: "
"In: 1 bee"
"Honey: "
" (sedated)"
"No hive"
"Hive: "
"No flower"
"Flower: "
"Travelling: "
" ticks"
" (dist "

Full Source

BeeDebugRenderer.java233 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.renderer.debug;
2
3
import com.google.common.collect.Lists;
4
import java.util.Collection;
5
import java.util.HashMap;
6
import java.util.HashSet;
7
import java.util.List;
8
import java.util.Map;
9
import java.util.Objects;
10
import java.util.Set;
11
import java.util.UUID;
12
import java.util.stream.Collectors;
13
import net.fabricmc.api.EnvType;
14
import net.fabricmc.api.Environment;
15
import net.minecraft.client.Camera;
16
import net.minecraft.client.Minecraft;
17
import net.minecraft.client.renderer.culling.Frustum;
18
import net.minecraft.core.BlockPos;
19
import net.minecraft.gizmos.GizmoStyle;
20
import net.minecraft.gizmos.Gizmos;
21
import net.minecraft.network.protocol.game.DebugEntityNameGenerator;
22
import net.minecraft.util.ARGB;
23
import net.minecraft.util.debug.DebugBeeInfo;
24
import net.minecraft.util.debug.DebugGoalInfo;
25
import net.minecraft.util.debug.DebugHiveInfo;
26
import net.minecraft.util.debug.DebugSubscriptions;
27
import net.minecraft.util.debug.DebugValueAccess;
28
import net.minecraft.util.debug.DebugGoalInfo.DebugGoal;
29
import net.minecraft.world.entity.Entity;
30
import org.jspecify.annotations.Nullable;
31
32
@Environment(EnvType.CLIENT)
33
public class BeeDebugRenderer implements DebugRenderer.SimpleDebugRenderer {
34
	private static final boolean SHOW_GOAL_FOR_ALL_BEES = true;
35
	private static final boolean SHOW_NAME_FOR_ALL_BEES = true;
36
	private static final boolean SHOW_HIVE_FOR_ALL_BEES = true;
37
	private static final boolean SHOW_FLOWER_POS_FOR_ALL_BEES = true;
38
	private static final boolean SHOW_TRAVEL_TICKS_FOR_ALL_BEES = true;
39
	private static final boolean SHOW_GOAL_FOR_SELECTED_BEE = true;
40
	private static final boolean SHOW_NAME_FOR_SELECTED_BEE = true;
41
	private static final boolean SHOW_HIVE_FOR_SELECTED_BEE = true;
42
	private static final boolean SHOW_FLOWER_POS_FOR_SELECTED_BEE = true;
43
	private static final boolean SHOW_TRAVEL_TICKS_FOR_SELECTED_BEE = true;
44
	private static final boolean SHOW_HIVE_MEMBERS = true;
45
	private static final boolean SHOW_BLACKLISTS = true;
46
	private static final int MAX_RENDER_DIST_FOR_HIVE_OVERLAY = 30;
47
	private static final int MAX_RENDER_DIST_FOR_BEE_OVERLAY = 30;
48
	private static final int MAX_TARGETING_DIST = 8;
49
	private static final float TEXT_SCALE = 0.32F;
50
	private static final int ORANGE = -23296;
51
	private static final int GRAY = -3355444;
52
	private static final int PINK = -98404;
53
	private final Minecraft minecraft;
54
	private @Nullable UUID lastLookedAtUuid;
55
56
	public BeeDebugRenderer(final Minecraft minecraft) {
57
		this.minecraft = minecraft;
58
	}
59
60
	@Override
61
	public void emitGizmos(
62
		final double camX, final double camY, final double camZ, final DebugValueAccess debugValues, final Frustum frustum, final float partialTicks
63
	) {
64
		this.doRender(debugValues);
65
		if (!this.minecraft.player.isSpectator()) {
66
			this.updateLastLookedAtUuid();
67
		}
68
	}
69
70
	private void doRender(final DebugValueAccess debugValues) {
71
		BlockPos playerPos = this.getCamera().blockPosition();
72
		debugValues.forEachEntity(DebugSubscriptions.BEES, (entity, beeInfo) -> {
73
			if (this.minecraft.player.closerThan(entity, 30.0)) {
74
				DebugGoalInfo goalInfo = debugValues.getEntityValue(DebugSubscriptions.GOAL_SELECTORS, entity);
75
				this.renderBeeInfo(entity, beeInfo, goalInfo);
76
			}
77
		});
78
		this.renderFlowerInfos(debugValues);
79
		Map<BlockPos, Set<UUID>> hiveBlacklistMap = this.createHiveBlacklistMap(debugValues);
80
		debugValues.forEachBlock(DebugSubscriptions.BEE_HIVES, (pos, hive) -> {
81
			if (playerPos.closerThan(pos, 30.0)) {
82
				highlightHive(pos);
83
				Set<UUID> beesWhoBlacklistThisHive = hiveBlacklistMap.getOrDefault(pos, Set.of());
84
				this.renderHiveInfo(pos, hive, beesWhoBlacklistThisHive, debugValues);
85
			}
86
		});
87
		this.getGhostHives(debugValues).forEach((ghostHivePos, value) -> {
88
			if (playerPos.closerThan(ghostHivePos, 30.0)) {
89
				this.renderGhostHive(ghostHivePos, (List<String>)value);
90
			}
91
		});
92
	}
93
94
	private Map<BlockPos, Set<UUID>> createHiveBlacklistMap(final DebugValueAccess debugValues) {
95
		Map<BlockPos, Set<UUID>> hiveBlacklistMap = new HashMap<>();
96
		debugValues.forEachEntity(DebugSubscriptions.BEES, (entity, bee) -> {
97
			for (BlockPos blacklistedFlowerPos : bee.blacklistedHives()) {
98
				hiveBlacklistMap.computeIfAbsent(blacklistedFlowerPos, k -> new HashSet<>()).add(entity.getUUID());
99
			}
100
		});
101
		return hiveBlacklistMap;
102
	}
103
104
	private void renderFlowerInfos(final DebugValueAccess debugValues) {
105
		Map<BlockPos, Set<UUID>> beesPerFlower = new HashMap<>();
106
		debugValues.forEachEntity(DebugSubscriptions.BEES, (entity, bee) -> {
107
			if (bee.flowerPos().isPresent()) {
108
				beesPerFlower.computeIfAbsent(bee.flowerPos().get(), k -> new HashSet<>()).add(entity.getUUID());
109
			}
110
		});
111
		beesPerFlower.forEach((flowerPos, beesWithThisFlower) -> {
112
			Set<String> beeNames = beesWithThisFlower.stream().map(DebugEntityNameGenerator::getEntityName).collect(Collectors.toSet());
113
			int row = 1;
114
			Gizmos.billboardTextOverBlock(beeNames.toString(), flowerPos, row++, -256, 0.32F);
115
			Gizmos.billboardTextOverBlock("Flower", flowerPos, row++, -1, 0.32F);
116
			Gizmos.cuboid(flowerPos, 0.05F, GizmoStyle.fill(ARGB.colorFromFloat(0.3F, 0.8F, 0.8F, 0.0F)));
117
		});
118
	}
119
120
	private static String getBeeUuidsAsString(final Collection<UUID> uuids) {
121
		if (uuids.isEmpty()) {
122
			return "-";
123
		} else {
124
			return uuids.size() > 3 ? uuids.size() + " bees" : uuids.stream().map(DebugEntityNameGenerator::getEntityName).collect(Collectors.toSet()).toString();
125
		}
126
	}
127
128
	private static void highlightHive(final BlockPos hivePos) {
129
		float padding = 0.05F;
130
		Gizmos.cuboid(hivePos, 0.05F, GizmoStyle.fill(ARGB.colorFromFloat(0.3F, 0.2F, 0.2F, 1.0F)));
131
	}
132
133
	private void renderGhostHive(final BlockPos ghostHivePos, final List<String> hiveMemberNames) {
134
		float padding = 0.05F;
135
		Gizmos.cuboid(ghostHivePos, 0.05F, GizmoStyle.fill(ARGB.colorFromFloat(0.3F, 0.2F, 0.2F, 1.0F)));
136
		Gizmos.billboardTextOverBlock(hiveMemberNames.toString(), ghostHivePos, 0, -256, 0.32F);
137
		Gizmos.billboardTextOverBlock("Ghost Hive", ghostHivePos, 1, -65536, 0.32F);
138
	}
139
140
	private void renderHiveInfo(
141
		final BlockPos hivePos, final DebugHiveInfo hive, final Collection<UUID> beesWhoBlacklistThisHive, final DebugValueAccess debugValues
142
	) {
143
		int row = 0;
144
		if (!beesWhoBlacklistThisHive.isEmpty()) {
145
			renderTextOverHive("Blacklisted by " + getBeeUuidsAsString(beesWhoBlacklistThisHive), hivePos, row++, -65536);
146
		}
147
148
		renderTextOverHive("Out: " + getBeeUuidsAsString(this.getHiveMembers(hivePos, debugValues)), hivePos, row++, -3355444);
149
		if (hive.occupantCount() == 0) {
150
			renderTextOverHive("In: -", hivePos, row++, -256);
151
		} else if (hive.occupantCount() == 1) {
152
			renderTextOverHive("In: 1 bee", hivePos, row++, -256);
153
		} else {
154
			renderTextOverHive("In: " + hive.occupantCount() + " bees", hivePos, row++, -256);
155
		}
156
157
		renderTextOverHive("Honey: " + hive.honeyLevel(), hivePos, row++, -23296);
158
		renderTextOverHive(hive.type().getName().getString() + (hive.sedated() ? " (sedated)" : ""), hivePos, row++, -1);
159
	}
160
161
	private void renderBeeInfo(final Entity entity, final DebugBeeInfo beeInfo, final @Nullable DebugGoalInfo goalInfo) {
162
		boolean selected = this.isBeeSelected(entity);
163
		int row = 0;
164
		Gizmos.billboardTextOverMob(entity, row++, beeInfo.toString(), -1, 0.48F);
165
		if (beeInfo.hivePos().isEmpty()) {
166
			Gizmos.billboardTextOverMob(entity, row++, "No hive", -98404, 0.32F);
167
		} else {
168
			Gizmos.billboardTextOverMob(entity, row++, "Hive: " + this.getPosDescription(entity, beeInfo.hivePos().get()), -256, 0.32F);
169
		}
170
171
		if (beeInfo.flowerPos().isEmpty()) {
172
			Gizmos.billboardTextOverMob(entity, row++, "No flower", -98404, 0.32F);
173
		} else {
174
			Gizmos.billboardTextOverMob(entity, row++, "Flower: " + this.getPosDescription(entity, beeInfo.flowerPos().get()), -256, 0.32F);
175
		}
176
177
		if (goalInfo != null) {
178
			for (DebugGoal goal : goalInfo.goals()) {
179
				if (goal.isRunning()) {
180
					Gizmos.billboardTextOverMob(entity, row++, goal.name(), -16711936, 0.32F);
181
				}
182
			}
183
		}
184
185
		if (beeInfo.travelTicks() > 0) {
186
			int color = beeInfo.travelTicks() < 2400 ? -3355444 : -23296;
187
			Gizmos.billboardTextOverMob(entity, row++, "Travelling: " + beeInfo.travelTicks() + " ticks", color, 0.32F);
188
		}
189
	}
190
191
	private static void renderTextOverHive(final String text, final BlockPos hivePos, final int row, final int color) {
192
		Gizmos.billboardTextOverBlock(text, hivePos, row, color, 0.32F);
193
	}
194
195
	private Camera getCamera() {
196
		return this.minecraft.gameRenderer.mainCamera();
197
	}
198
199
	private String getPosDescription(final Entity entity, final BlockPos pos) {
200
		double dist = pos.distToCenterSqr(entity.position());
201
		double distRounded = Math.round(dist * 10.0) / 10.0;
202
		return pos.toShortString() + " (dist " + distRounded + ")";
203
	}
204
205
	private boolean isBeeSelected(final Entity entity) {
206
		return Objects.equals(this.lastLookedAtUuid, entity.getUUID());
207
	}
208
209
	private Collection<UUID> getHiveMembers(final BlockPos hivePos, final DebugValueAccess debugValues) {
210
		Set<UUID> hiveMembers = new HashSet<>();
211
		debugValues.forEachEntity(DebugSubscriptions.BEES, (entity, beeInfo) -> {
212
			if (beeInfo.hasHive(hivePos)) {
213
				hiveMembers.add(entity.getUUID());
214
			}
215
		});
216
		return hiveMembers;
217
	}
218
219
	private Map<BlockPos, List<String>> getGhostHives(final DebugValueAccess debugValues) {
220
		Map<BlockPos, List<String>> ghostHives = new HashMap<>();
221
		debugValues.forEachEntity(DebugSubscriptions.BEES, (entity, beeInfo) -> {
222
			if (beeInfo.hivePos().isPresent() && debugValues.getBlockValue(DebugSubscriptions.BEE_HIVES, beeInfo.hivePos().get()) == null) {
223
				ghostHives.computeIfAbsent(beeInfo.hivePos().get(), k -> Lists.newArrayList()).add(DebugEntityNameGenerator.getEntityName(entity));
224
			}
225
		});
226
		return ghostHives;
227
	}
228
229
	private void updateLastLookedAtUuid() {
230
		DebugRenderer.getTargetedEntity(this.minecraft.getCameraEntity(), 8).ifPresent(entity -> this.lastLookedAtUuid = entity.getUUID());
231
	}
232
}
233

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