aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/Gui.cpp
diff options
context:
space:
mode:
authorAyush Thoren <ayushthoren@gmail.com>2026-03-08 12:10:47 -0700
committerGitHub <noreply@github.com>2026-03-09 03:10:47 +0800
commit2f443fe333000595319e23c6e78b3d00d7f91f40 (patch)
tree475a4a9e90b3280e51948da25366edfc882012c9 /Minecraft.Client/Gui.cpp
parent4cec4f4500788f693566e443fdfa56337db05771 (diff)
Fix F3 debug crash when throwing ender pearl long distance (#934)
Signed-off-by: Ayush Thoren <ayushthoren@gmail.com>
Diffstat (limited to 'Minecraft.Client/Gui.cpp')
-rw-r--r--Minecraft.Client/Gui.cpp32
1 files changed, 17 insertions, 15 deletions
diff --git a/Minecraft.Client/Gui.cpp b/Minecraft.Client/Gui.cpp
index f9810a36..8a3e84db 100644
--- a/Minecraft.Client/Gui.cpp
+++ b/Minecraft.Client/Gui.cpp
@@ -895,14 +895,14 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse)
int zBlockPos = Mth::floor(minecraft->player->z);
// Chunk player is in
- int xChunkPos = minecraft->player->xChunk;
- int yChunkPos = minecraft->player->yChunk;
- int zChunkPos = minecraft->player->zChunk;
+ int xChunkPos = xBlockPos >> 4;
+ int yChunkPos = yBlockPos >> 4;
+ int zChunkPos = zBlockPos >> 4;
// Players offset within the chunk
- int xChunkOffset = xBlockPos - xChunkPos * 16;
- int yChunkOffset = yBlockPos - yChunkPos * 16;
- int zChunkOffset = zBlockPos - zChunkPos * 16;
+ int xChunkOffset = xBlockPos & 15;
+ int yChunkOffset = yBlockPos & 15;
+ int zChunkOffset = zBlockPos & 15;
// Format the position like java with limited decumal places
WCHAR posString[44]; // Allows upto 7 digit positions (+-9_999_999)
@@ -951,18 +951,20 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse)
if (minecraft->level != NULL && minecraft->level->hasChunkAt(xBlockPos, fmod(yBlockPos, 256), zBlockPos))
{
LevelChunk *chunkAt = minecraft->level->getChunkAt(xBlockPos, zBlockPos);
+ if (chunkAt != NULL)
+ {
+ int skyLight = chunkAt->getBrightness(LightLayer::Sky, xChunkOffset, yChunkOffset, zChunkOffset);
+ int blockLight = chunkAt->getBrightness(LightLayer::Block, xChunkOffset, yChunkOffset, zChunkOffset);
+ int maxLight = fmax(skyLight, blockLight);
+ lines.push_back(L"Light: " + std::to_wstring(maxLight) + L" (" + std::to_wstring(skyLight) + L" sky, " + std::to_wstring(blockLight) + L" block)");
- int skyLight = chunkAt->getBrightness(LightLayer::Sky, xChunkOffset, yChunkOffset, zChunkOffset);
- int blockLight = chunkAt->getBrightness(LightLayer::Block, xChunkOffset, yChunkOffset, zChunkOffset);
- int maxLight = fmax(skyLight, blockLight);
- lines.push_back(L"Light: " + std::to_wstring(maxLight) + L" (" + std::to_wstring(skyLight) + L" sky, " + std::to_wstring(blockLight) + L" block)");
-
- lines.push_back(L"CH S: " + std::to_wstring(chunkAt->getHeightmap(xChunkOffset, zChunkOffset)));
+ lines.push_back(L"CH S: " + std::to_wstring(chunkAt->getHeightmap(xChunkOffset, zChunkOffset)));
- Biome *biome = chunkAt->getBiome(xChunkOffset, zChunkOffset, minecraft->level->getBiomeSource());
- lines.push_back(L"Biome: " + biome->m_name + L" (" + std::to_wstring(biome->id) + L")");
+ Biome *biome = chunkAt->getBiome(xChunkOffset, zChunkOffset, minecraft->level->getBiomeSource());
+ lines.push_back(L"Biome: " + biome->m_name + L" (" + std::to_wstring(biome->id) + L")");
- lines.push_back(L"Difficulty: " + std::to_wstring(minecraft->level->difficulty) + L" (Day " + std::to_wstring(minecraft->level->getGameTime() / Level::TICKS_PER_DAY) + L")");
+ lines.push_back(L"Difficulty: " + std::to_wstring(minecraft->level->difficulty) + L" (Day " + std::to_wstring(minecraft->level->getGameTime() / Level::TICKS_PER_DAY) + L")");
+ }
}