From 5696074313ff98e634f307bdac2e391adeab3d84 Mon Sep 17 00:00:00 2001 From: GabsPuNs Date: Sun, 17 May 2026 14:48:58 -0400 Subject: [PATCH] Improvements * Use new ZYX Loops order in LevelRenderer::allChanged * Revert xt, yt, zt change in PathFinder * Fix return in PathFinder --- Minecraft.Client/LevelRenderer.cpp | 47 ++++++++++++++---------------- Minecraft.World/PathFinder.cpp | 12 ++++---- 2 files changed, 28 insertions(+), 31 deletions(-) diff --git a/Minecraft.Client/LevelRenderer.cpp b/Minecraft.Client/LevelRenderer.cpp index aa47dfa8..51019d05 100644 --- a/Minecraft.Client/LevelRenderer.cpp +++ b/Minecraft.Client/LevelRenderer.cpp @@ -424,9 +424,7 @@ void LevelRenderer::allChanged(int playerIndex) // deadlock when starting a game in splitscreen. //EnterCriticalSection(&m_csDirtyChunks); if( level == nullptr ) - { return; - } Minecraft::GetInstance()->gameRenderer->DisableUpdateThread(); @@ -458,12 +456,11 @@ void LevelRenderer::allChanged(int playerIndex) delete chunks[playerIndex][i].chunk; } delete[] chunks[playerIndex].data; - // delete sortedChunks[playerIndex]; // 4J - removed - not sorting our chunks anymore + //delete sortedChunks[playerIndex]; // 4J - removed - not sorting our chunks anymore } chunks[playerIndex] = ClipChunkArray(xChunks * yChunks * zChunks); - // sortedChunks[playerIndex] = new vector(xChunks * yChunks * zChunks); // 4J - removed - not sorting our chunks anymore - int id = 0; + //sortedChunks[playerIndex] = new vector(xChunks * yChunks * zChunks); // 4J - removed - not sorting our chunks anymore int count = 0; xMinChunk = 0; @@ -476,31 +473,31 @@ void LevelRenderer::allChanged(int playerIndex) // 4J removed - we now only fully clear this on exiting the game (setting level to nullptr). Apart from that, the chunk rebuilding is responsible for maintaining this // renderableTileEntities.clear(); - for (int x = 0; x < xChunks; x++) + // Use new ZYX Loops order instead of Mojang XYZ Loops orders + for (int z = 0; z < zChunks; z++) { - for (int y = 0; y < yChunks; y++) - { - for (int z = 0; z < zChunks; z++) - { - chunks[playerIndex][(z * yChunks + y) * xChunks + x].chunk = new Chunk(level[playerIndex], renderableTileEntities, m_csRenderableTileEntities, x * CHUNK_XZSIZE, y * CHUNK_SIZE, z * CHUNK_XZSIZE, &chunks[playerIndex][(z * yChunks + y) * xChunks + x]); - chunks[playerIndex][(z * yChunks + y) * xChunks + x].visible = true; - chunks[playerIndex][(z * yChunks + y) * xChunks + x].chunk->id = count++; - // sortedChunks[playerIndex]->at((z * yChunks + y) * xChunks + x) = chunks[playerIndex]->at((z * yChunks + y) * xChunks + x); // 4J - removed - not sorting our chunks anymore - - id += 3; - } - } + for (int y = 0; y < yChunks; y++) + { + for (int x = 0; x < xChunks; x++) + { + int idx = (z * yChunks + y) * xChunks + x; + + chunks[playerIndex][idx].chunk = new Chunk(level[playerIndex], renderableTileEntities, m_csRenderableTileEntities, x * CHUNK_XZSIZE, y * CHUNK_SIZE, z * CHUNK_XZSIZE, &chunks[playerIndex][idx]); + chunks[playerIndex][idx].visible = true; + chunks[playerIndex][idx].chunk->id = count++; + //sortedChunks[playerIndex]->at((z * yChunks + y) * xChunks + x) = chunks[playerIndex]->at((z * yChunks + y) * xChunks + x); // 4J - removed - not sorting our chunks anymore + } + } } + nonStackDirtyChunksAdded(); - if (level != nullptr) + + shared_ptr player = mc->cameraTargetPlayer; + if (player != nullptr) { - shared_ptr player = mc->cameraTargetPlayer; - if (player != nullptr) - { - this->resortChunks(Mth::floor(player->x), Mth::floor(player->y), Mth::floor(player->z)); - // sort(sortedChunks[playerIndex]->begin(),sortedChunks[playerIndex]->end(), DistanceChunkSorter(player)); // 4J - removed - not sorting our chunks anymore - } + this->resortChunks(Mth::floor(player->x), Mth::floor(player->y), Mth::floor(player->z)); + //sort(sortedChunks[playerIndex]->begin(),sortedChunks[playerIndex]->end(), DistanceChunkSorter(player)); // 4J - removed - not sorting our chunks anymore } noEntityRenderFrames = 2; diff --git a/Minecraft.World/PathFinder.cpp b/Minecraft.World/PathFinder.cpp index cf42029f..1c34b85d 100644 --- a/Minecraft.World/PathFinder.cpp +++ b/Minecraft.World/PathFinder.cpp @@ -211,10 +211,6 @@ int PathFinder::isFree(Entity *entity, int x, int y, int z, Node *size, bool avo { bool walkable = false; - int xt = Mth::floor(entity->x); - int yt = Mth::floor(entity->y); - int zt = Mth::floor(entity->z); - //Use 4J XZY Loops order instead of Mojang XYZ Loops orders for (int xx = x; xx < x + size->x; xx++) { @@ -246,6 +242,10 @@ int PathFinder::isFree(Entity *entity, int x, int y, int z, Node *size, bool avo // 4J Stu - Use new getTileRenderShape passing in the tileId we have already got if (entity->level->getTileRenderShape(tileId) == Tile::SHAPE_RAIL) { + int xt = Mth::floor(entity->x); + int yt = Mth::floor(entity->y); + int zt = Mth::floor(entity->z); + if (entity->level->getTileRenderShape(xt, yt, zt) == Tile::SHAPE_RAIL || entity->level->getTileRenderShape(xt, yt - 1, zt) == Tile::SHAPE_RAIL) { @@ -279,9 +279,9 @@ int PathFinder::isFree(Entity *entity, int x, int y, int z, Node *size, bool avo return TYPE_BLOCKED; } } - - return walkable ? TYPE_WALKABLE : TYPE_OPEN; } + + return walkable ? TYPE_WALKABLE : TYPE_OPEN; } // function reconstruct_path(came_from,current_node)