DebugEntrySpawnCounts .java

net.minecraft.client.gui.components.debug.DebugEntrySpawnCounts (class): members: serverOrClientLevel, displayer, clientChunk, display. imports: Minecraft.

net.minecraft.client.gui.components.debugclass46 linesclient1.7 KB

Implements

API Surface (1)

void display(final DebugScreenDisplayer displayer, final @Nullable Level serverOrClientLevel, final @Nullable LevelChunk clientChunk, final @Nullable LevelChunk serverChunk)

Fields & Constants (3)

displayer
serverOrClientLevel
clientChunk

Full Source

DebugEntrySpawnCounts.java46 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.gui.components.debug;
2
3
import it.unimi.dsi.fastutil.objects.Object2IntMap;
4
import java.util.stream.Collectors;
5
import java.util.stream.Stream;
6
import net.fabricmc.api.EnvType;
7
import net.fabricmc.api.Environment;
8
import net.minecraft.client.Minecraft;
9
import net.minecraft.server.level.ServerChunkCache;
10
import net.minecraft.server.level.ServerLevel;
11
import net.minecraft.world.entity.Entity;
12
import net.minecraft.world.entity.MobCategory;
13
import net.minecraft.world.level.Level;
14
import net.minecraft.world.level.NaturalSpawner.SpawnState;
15
import net.minecraft.world.level.chunk.LevelChunk;
16
import org.jspecify.annotations.Nullable;
17
18
@Environment(EnvType.CLIENT)
19
public class DebugEntrySpawnCounts implements DebugScreenEntry {
20
	@Override
21
	public void display(
22
		final DebugScreenDisplayer displayer,
23
		final @Nullable Level serverOrClientLevel,
24
		final @Nullable LevelChunk clientChunk,
25
		final @Nullable LevelChunk serverChunk
26
	) {
27
		Minecraft minecraft = Minecraft.getInstance();
28
		Entity entity = minecraft.getCameraEntity();
29
		ServerLevel serverLevel = serverOrClientLevel instanceof ServerLevel level ? level : null;
30
		if (entity != null && serverLevel != null) {
31
			ServerChunkCache chunkSource = serverLevel.getChunkSource();
32
			SpawnState lastSpawnState = chunkSource.getLastSpawnState();
33
			if (lastSpawnState != null) {
34
				Object2IntMap<MobCategory> mobCategoryCounts = lastSpawnState.getMobCategoryCounts();
35
				int chunkCount = lastSpawnState.getSpawnableChunkCount();
36
				displayer.addLine(
37
					"SC: "
38
						+ chunkCount
39
						+ ", "
40
						+ Stream.of(MobCategory.values()).map(c -> c.getDebugAbbreviation() + ": " + mobCategoryCounts.getInt(c)).collect(Collectors.joining(", "))
41
				);
42
			}
43
		}
44
	}
45
}
46

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