| 1 | package net.minecraft.client.gui.components.debug;
|
| 2 |
|
| 3 | import it.unimi.dsi.fastutil.longs.LongSet;
|
| 4 | import it.unimi.dsi.fastutil.longs.LongSets;
|
| 5 | import java.util.List;
|
| 6 | import java.util.Locale;
|
| 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.core.Direction;
|
| 12 | import net.minecraft.core.SectionPos;
|
| 13 | import net.minecraft.resources.Identifier;
|
| 14 | import net.minecraft.server.level.ServerLevel;
|
| 15 | import net.minecraft.util.Mth;
|
| 16 | import net.minecraft.world.entity.Entity;
|
| 17 | import net.minecraft.world.level.ChunkPos;
|
| 18 | import net.minecraft.world.level.Level;
|
| 19 | import net.minecraft.world.level.chunk.LevelChunk;
|
| 20 | import org.jspecify.annotations.Nullable;
|
| 21 |
|
| 22 | @Environment(EnvType.CLIENT)
|
| 23 | public class DebugEntryPosition implements DebugScreenEntry {
|
| 24 | public static final Identifier GROUP = Identifier.withDefaultNamespace("position");
|
| 25 |
|
| 26 | @Override
|
| 27 | public void display(
|
| 28 | final DebugScreenDisplayer displayer,
|
| 29 | final @Nullable Level serverOrClientLevel,
|
| 30 | final @Nullable LevelChunk clientChunk,
|
| 31 | final @Nullable LevelChunk serverChunk
|
| 32 | ) {
|
| 33 | Minecraft minecraft = Minecraft.getInstance();
|
| 34 | Entity entity = minecraft.getCameraEntity();
|
| 35 | if (entity != null) {
|
| 36 | BlockPos feetPos = minecraft.getCameraEntity().blockPosition();
|
| 37 | ChunkPos chunkPos = ChunkPos.containing(feetPos);
|
| 38 | Direction direction = entity.getDirection();
|
| 39 |
|
| 40 | String faceString = switch (direction) {
|
| 41 | case NORTH -> "Towards negative Z";
|
| 42 | case SOUTH -> "Towards positive Z";
|
| 43 | case WEST -> "Towards negative X";
|
| 44 | case EAST -> "Towards positive X";
|
| 45 | default -> "Invalid";
|
| 46 | };
|
| 47 | LongSet chunks = serverOrClientLevel instanceof ServerLevel serverLevel ? serverLevel.getForceLoadedChunks() : LongSets.EMPTY_SET;
|
| 48 | displayer.addToGroup(
|
| 49 | GROUP,
|
| 50 | List.of(
|
| 51 | String.format(
|
| 52 | Locale.ROOT, "XYZ: %.3f / %.5f / %.3f", minecraft.getCameraEntity().getX(), minecraft.getCameraEntity().getY(), minecraft.getCameraEntity().getZ()
|
| 53 | ),
|
| 54 | String.format(Locale.ROOT, "Block: %d %d %d", feetPos.getX(), feetPos.getY(), feetPos.getZ()),
|
| 55 | String.format(
|
| 56 | Locale.ROOT,
|
| 57 | "Chunk: %d %d %d [%d %d in r.%d.%d.mca]",
|
| 58 | chunkPos.x(),
|
| 59 | SectionPos.blockToSectionCoord(feetPos.getY()),
|
| 60 | chunkPos.z(),
|
| 61 | chunkPos.getRegionLocalX(),
|
| 62 | chunkPos.getRegionLocalZ(),
|
| 63 | chunkPos.getRegionX(),
|
| 64 | chunkPos.getRegionZ()
|
| 65 | ),
|
| 66 | String.format(Locale.ROOT, "Facing: %s (%s) (%.1f / %.1f)", direction, faceString, Mth.wrapDegrees(entity.getYRot()), Mth.wrapDegrees(entity.getXRot())),
|
| 67 | minecraft.level.dimension().identifier() + " FC: " + chunks.size()
|
| 68 | )
|
| 69 | );
|
| 70 | }
|
| 71 | }
|
| 72 | }
|
| 73 |
|