| 1 | package net.minecraft.client.gui.components.debug;
|
| 2 |
|
| 3 | import com.google.common.collect.Maps;
|
| 4 | import java.util.ArrayList;
|
| 5 | import java.util.List;
|
| 6 | import java.util.Map;
|
| 7 | import net.fabricmc.api.EnvType;
|
| 8 | import net.fabricmc.api.Environment;
|
| 9 | import net.minecraft.client.Minecraft;
|
| 10 | import net.minecraft.core.BlockPos;
|
| 11 | import net.minecraft.resources.Identifier;
|
| 12 | import net.minecraft.world.entity.Entity;
|
| 13 | import net.minecraft.world.level.Level;
|
| 14 | import net.minecraft.world.level.chunk.LevelChunk;
|
| 15 | import net.minecraft.world.level.levelgen.Heightmap.Types;
|
| 16 | import org.jspecify.annotations.Nullable;
|
| 17 |
|
| 18 | @Environment(EnvType.CLIENT)
|
| 19 | public class DebugEntryHeightmap implements DebugScreenEntry {
|
| 20 | private static final Map<Types, String> HEIGHTMAP_NAMES = Maps.newEnumMap(
|
| 21 | Map.of(
|
| 22 | Types.WORLD_SURFACE_WG,
|
| 23 | "SW",
|
| 24 | Types.WORLD_SURFACE,
|
| 25 | "S",
|
| 26 | Types.OCEAN_FLOOR_WG,
|
| 27 | "OW",
|
| 28 | Types.OCEAN_FLOOR,
|
| 29 | "O",
|
| 30 | Types.MOTION_BLOCKING,
|
| 31 | "M",
|
| 32 | Types.MOTION_BLOCKING_NO_LEAVES,
|
| 33 | "ML"
|
| 34 | )
|
| 35 | );
|
| 36 | private static final Identifier GROUP = Identifier.withDefaultNamespace("heightmaps");
|
| 37 |
|
| 38 | @Override
|
| 39 | public void display(
|
| 40 | final DebugScreenDisplayer displayer,
|
| 41 | final @Nullable Level serverOrClientLevel,
|
| 42 | final @Nullable LevelChunk clientChunk,
|
| 43 | final @Nullable LevelChunk serverChunk
|
| 44 | ) {
|
| 45 | Minecraft minecraft = Minecraft.getInstance();
|
| 46 | Entity entity = minecraft.getCameraEntity();
|
| 47 | if (entity != null && minecraft.level != null && clientChunk != null) {
|
| 48 | BlockPos feetPos = entity.blockPosition();
|
| 49 | List<String> result = new ArrayList<>();
|
| 50 | StringBuilder heightmaps = new StringBuilder("CH");
|
| 51 |
|
| 52 | for (Types type : Types.values()) {
|
| 53 | if (type.sendToClient()) {
|
| 54 | heightmaps.append(" ").append(HEIGHTMAP_NAMES.get(type)).append(": ").append(clientChunk.getHeight(type, feetPos.getX(), feetPos.getZ()));
|
| 55 | }
|
| 56 | }
|
| 57 |
|
| 58 | result.add(heightmaps.toString());
|
| 59 | heightmaps.setLength(0);
|
| 60 | heightmaps.append("SH");
|
| 61 |
|
| 62 | for (Types type : Types.values()) {
|
| 63 | if (type.keepAfterWorldgen()) {
|
| 64 | heightmaps.append(" ").append(HEIGHTMAP_NAMES.get(type)).append(": ");
|
| 65 | if (serverChunk != null) {
|
| 66 | heightmaps.append(serverChunk.getHeight(type, feetPos.getX(), feetPos.getZ()));
|
| 67 | } else {
|
| 68 | heightmaps.append("??");
|
| 69 | }
|
| 70 | }
|
| 71 | }
|
| 72 |
|
| 73 | result.add(heightmaps.toString());
|
| 74 | displayer.addToGroup(GROUP, result);
|
| 75 | }
|
| 76 | }
|
| 77 | }
|
| 78 |
|