From 6bba1bd5f6fb1f134f94413c3e99e4719940f5ea Mon Sep 17 00:00:00 2001 From: rtm516 Date: Sat, 7 Mar 2026 15:22:24 +0000 Subject: [PATCH] Change position, block, chunk and facing --- Minecraft.Client/Gui.cpp | 68 +++++++++++++++++++++++++++------- Minecraft.Client/Minecraft.cpp | 4 +- 2 files changed, 56 insertions(+), 16 deletions(-) diff --git a/Minecraft.Client/Gui.cpp b/Minecraft.Client/Gui.cpp index 851a18b68..67dca52ae 100644 --- a/Minecraft.Client/Gui.cpp +++ b/Minecraft.Client/Gui.cpp @@ -913,22 +913,62 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) #endif // 4J Stu - Moved these so that they don't overlap - double xBlockPos = floor(minecraft->player->x); - double yBlockPos = floor(minecraft->player->y); - double zBlockPos = floor(minecraft->player->z); - lines.push_back(L"x: " + std::to_wstring(minecraft->player->x) + L"/ Head: " + std::to_wstring(static_cast(xBlockPos)) + L"/ Chunk: " + std::to_wstring(minecraft->player->xChunk)); - lines.push_back(L"y: " + std::to_wstring(minecraft->player->y) + L"/ Head: " + std::to_wstring(static_cast(yBlockPos))); - lines.push_back(L"z: " + std::to_wstring(minecraft->player->z) + L"/ Head: " + std::to_wstring(static_cast(zBlockPos)) + L"/ Chunk: " + std::to_wstring(minecraft->player->zChunk)); - lines.push_back(L"f: " + std::to_wstring(Mth::floor(minecraft->player->yRot * 4.0f / 360.0f + 0.5) & 0x3) + L"/ yRot: " + std::to_wstring(minecraft->player->yRot)); + int xBlockPos = Mth::floor(minecraft->player->x); + int yBlockPos = Mth::floor(minecraft->player->y); + int zBlockPos = Mth::floor(minecraft->player->z); - int px = Mth::floor(minecraft->player->x); - int py = Mth::floor(minecraft->player->y); - int pz = Mth::floor(minecraft->player->z); - if (minecraft->level != NULL && minecraft->level->hasChunkAt(px, py, pz)) + int xChunkPos = minecraft->player->xChunk; + int yChunkPos = minecraft->player->yChunk; + int zChunkPos = minecraft->player->zChunk; + + int xChunkOffset = xBlockPos - xChunkPos * 16; + int yChunkOffset = yBlockPos - yChunkPos * 16; + int zChunkOffset = zBlockPos - zChunkPos * 16; + + lines.push_back(L"XYZ: " + std::to_wstring(minecraft->player->x) + L" / " + std::to_wstring(minecraft->player->y) + L" / " + std::to_wstring(minecraft->player->z)); + lines.push_back(L"Block: " + std::to_wstring(static_cast(xBlockPos)) + L" " + std::to_wstring(static_cast(yBlockPos)) + L" " + std::to_wstring(static_cast(zBlockPos))); + lines.push_back(L"Chunk: " + std::to_wstring(xChunkOffset) + L" " + std::to_wstring(yChunkOffset) + L" " + std::to_wstring(zChunkOffset) + L" in " + std::to_wstring(xChunkPos) + L" " + std::to_wstring(yChunkPos) + L" " + std::to_wstring(zChunkPos)); + + // Wrap the yRot to 360 then adjust to (-180 to 180) range to match java + float yRotDisplay = fmod(minecraft->player->yRot, 360.0f); + if (yRotDisplay > 180.0f) + { + yRotDisplay -= 360.0f; + } + if (yRotDisplay < -180.0f) + { + yRotDisplay += 360.0f; + } + // Generate the angle string in the format "yRot / xRot" with one decimal place, similar to java edition + WCHAR angleString[16]; + swprintf(angleString, 16, L"%.1f / %.1f", yRotDisplay, minecraft->player->xRot); + + // Work out the named direction + int direction = Mth::floor(minecraft->player->yRot * 4.0f / 360.0f + 0.5) & 0x3; + wstring cardinalDirection; + switch (direction) + { + case 0: + cardinalDirection = L"south"; + break; + case 1: + cardinalDirection = L"west"; + break; + case 2: + cardinalDirection = L"north"; + break; + case 3: + cardinalDirection = L"east"; + break; + } + + lines.push_back(L"Facing: " + cardinalDirection + L" (" + angleString + L")"); + + if (minecraft->level != NULL && minecraft->level->hasChunkAt(xBlockPos, yBlockPos, zBlockPos)) { - LevelChunk *chunkAt = minecraft->level->getChunkAt(px, pz); - Biome *biome = chunkAt->getBiome(px & 15, pz & 15, minecraft->level->getBiomeSource()); - lines.push_back(L"b: " + biome->m_name + L" (" + std::to_wstring(biome->id) + L")"); + LevelChunk *chunkAt = minecraft->level->getChunkAt(xBlockPos, zBlockPos); + Biome *biome = chunkAt->getBiome(xChunkOffset, zChunkOffset, minecraft->level->getBiomeSource()); + lines.push_back(L"Biome: " + biome->m_name + L" (" + std::to_wstring(biome->id) + L")"); } // Loop through the lines and draw them all on screen diff --git a/Minecraft.Client/Minecraft.cpp b/Minecraft.Client/Minecraft.cpp index f268ec50c..46e8497a1 100644 --- a/Minecraft.Client/Minecraft.cpp +++ b/Minecraft.Client/Minecraft.cpp @@ -742,7 +742,7 @@ void Minecraft::run() while (System::currentTimeMillis() >= lastTime + 1000) { - fpsString = std::to_wstring(frames) + L" fps, " + std::to_wstring(Chunk::updates) + L" chunk updates"; + fpsString = std::to_wstring(frames) + L" fps (" + std::to_wstring(Chunk::updates) + L" chunk updates)"; Chunk::updates = 0; lastTime += 1000; frames = 0; @@ -2066,7 +2066,7 @@ void Minecraft::run_middle() while (System::nanoTime() >= lastTime + 1000000000) { MemSect(31); - fpsString = std::to_wstring(frames) + L" fps, " + std::to_wstring(Chunk::updates) + L" chunk updates"; + fpsString = std::to_wstring(frames) + L" fps (" + std::to_wstring(Chunk::updates) + L" chunk updates)"; MemSect(0); Chunk::updates = 0; lastTime += 1000000000;