From ca5fde56fed613a8f45767868636e2321b03d3f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Davi=20Eler=20Magalh=C3=A3es?= Date: Wed, 4 Mar 2026 12:07:37 -0300 Subject: [PATCH 1/2] Fix: Sorted the item list in the debug overlay (#340) * Fix: Sorted the item list in the debug overlay * revert show all files to false * Revert ShowAllFiles by removing it * removed extra line * Adressed PR review changes * Replaced push_back with emplace_back * Removed redundant emplace_back --- .../Common/UI/UIScene_DebugOverlay.cpp | 38 ++++++++++++++----- .../Minecraft.Client.vcxproj.user | 2 +- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/Minecraft.Client/Common/UI/UIScene_DebugOverlay.cpp b/Minecraft.Client/Common/UI/UIScene_DebugOverlay.cpp index 8e45c3246..6514e6ece 100644 --- a/Minecraft.Client/Common/UI/UIScene_DebugOverlay.cpp +++ b/Minecraft.Client/Common/UI/UIScene_DebugOverlay.cpp @@ -39,17 +39,37 @@ UIScene_DebugOverlay::UIScene_DebugOverlay(int iPad, void *initData, UILayer *pa m_buttonSetNight.init(L"Set Night", eControl_SetNight); m_buttonListItems.init(eControl_Items); + + // Sort items alphabetically + std::vector> sortedItems; + for (size_t i = 0; i < Item::items.length; ++i) + { + if (Item::items[i] != NULL) + { + sortedItems.emplace_back(std::wstring(app.GetString(Item::items[i]->getDescriptionId())), i); + } + } + for (size_t i = 1; i < sortedItems.size(); ++i) + { + auto key = sortedItems[i]; + int j = i - 1; + while (j >= 0 && sortedItems[j].first > key.first) + { + sortedItems[j + 1] = sortedItems[j]; + --j; + } + sortedItems[j + 1] = key; + } + + // Populate the list in sorted order int listId = 0; - for(unsigned int i = 0; i < Item::items.length; ++i) - { - if(Item::items[i] != NULL) - { - m_itemIds.push_back(i); - m_buttonListItems.addItem(app.GetString(Item::items[i]->getDescriptionId()), listId); - ++listId; - } - } + for (const auto& entry : sortedItems) + { + m_itemIds.push_back(entry.second); + m_buttonListItems.addItem(entry.first.c_str(), listId); + ++listId; + } m_buttonListEnchantments.init(eControl_Enchantments); diff --git a/Minecraft.Client/Minecraft.Client.vcxproj.user b/Minecraft.Client/Minecraft.Client.vcxproj.user index 09a7ebc4a..24ca62f80 100644 --- a/Minecraft.Client/Minecraft.Client.vcxproj.user +++ b/Minecraft.Client/Minecraft.Client.vcxproj.user @@ -19,4 +19,4 @@ $(SolutionDir)$(Platform)\$(Configuration)\ WindowsLocalDebugger - \ No newline at end of file + From 2be856a2d447ab758e02bfeaaa9cac5e1114dbfc Mon Sep 17 00:00:00 2001 From: ModMaker101 <119018978+ModMaker101@users.noreply.github.com> Date: Wed, 4 Mar 2026 10:43:29 -0500 Subject: [PATCH 2/2] Fix Chunk destructor segfault using smart pointers #112 (#414) --- Minecraft.Client/Chunk.cpp | 20 +++++++++----------- Minecraft.Client/Chunk.h | 6 +++--- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/Minecraft.Client/Chunk.cpp b/Minecraft.Client/Chunk.cpp index d039227bf..63cd05017 100644 --- a/Minecraft.Client/Chunk.cpp +++ b/Minecraft.Client/Chunk.cpp @@ -52,7 +52,7 @@ Chunk::Chunk(Level *level, LevelRenderer::rteMap &globalRenderableTileEntities, : globalRenderableTileEntities( &globalRenderableTileEntities ), globalRenderableTileEntities_cs(&globalRenderableTileEntities_cs) { clipChunk->visible = false; - bb = NULL; + bb = nullptr; id = 0; this->level = level; @@ -101,15 +101,15 @@ void Chunk::setPos(int x, int y, int z) float g = 6.0f; // 4J - changed to just set the value rather than make a new one, if we've already created storage - if( bb == NULL ) + if( !bb ) { - bb = AABB::newPermanent(-g, -g, -g, XZSIZE+g, SIZE+g, XZSIZE+g); + bb = shared_ptr(AABB::newPermanent(-g, -g, -g, XZSIZE+g, SIZE+g, XZSIZE+g)); } - else - { + else + { // 4J MGH - bounds are relative to the position now, so the AABB will be setup already, either above, or from the tesselator bounds. // bb->set(-g, -g, -g, SIZE+g, SIZE+g, SIZE+g); - } + } clipChunk->aabb[0] = bb->x0 + x; clipChunk->aabb[1] = bb->y0 + y; clipChunk->aabb[2] = bb->z0 + z; @@ -154,6 +154,7 @@ void Chunk::translateToPos() Chunk::Chunk() { + bb = nullptr; } void Chunk::makeCopyForRebuild(Chunk *source) @@ -998,7 +999,7 @@ int Chunk::getList(int layer) void Chunk::cull(Culler *culler) { - clipChunk->visible = culler->isVisible(bb); + clipChunk->visible = culler->isVisible(bb.get()); } void Chunk::renderBB() @@ -1027,10 +1028,7 @@ void Chunk::clearDirty() #endif } -Chunk::~Chunk() -{ - delete bb; -} +Chunk::~Chunk() = default; bool Chunk::emptyFlagSet(int layer) { diff --git a/Minecraft.Client/Chunk.h b/Minecraft.Client/Chunk.h index f7947156f..e0ae016ef 100644 --- a/Minecraft.Client/Chunk.h +++ b/Minecraft.Client/Chunk.h @@ -46,11 +46,11 @@ public: int xRender, yRender, zRender; int xRenderOffs, yRenderOffs, zRenderOffs; - int xm, ym, zm; - AABB *bb; + int xm, ym, zm; + shared_ptr bb; ClipChunk *clipChunk; - int id; + int id; //public: // vector > renderableTileEntities; // 4J - removed