From 44cb43f13cdd8f2b3efb9ae77daa3e994c62bc26 Mon Sep 17 00:00:00 2001 From: x12xx12x <44411062+12xx12@users.noreply.github.com> Date: Sun, 10 Nov 2024 00:07:11 +0100 Subject: Fix Block Entity Placement in Generation (#5060) * block area in chunk desc now handles block entities some minor changes block entities validate and correct their position when put into the world * fixed checkstyle * Fixed Build * Removed Empty File --------- Co-authored-by: 12xx12 <12xx12100@gmail.com> Co-authored-by: Alexander Harkness --- src/Generating/ChunkDesc.cpp | 14 +++++++------- src/Generating/ChunkDesc.h | 4 ++-- src/Generating/MineShafts.cpp | 2 +- src/Generating/MineShafts.h | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) (limited to 'src/Generating') diff --git a/src/Generating/ChunkDesc.cpp b/src/Generating/ChunkDesc.cpp index b2a332489..397220f4f 100644 --- a/src/Generating/ChunkDesc.cpp +++ b/src/Generating/ChunkDesc.cpp @@ -573,12 +573,12 @@ void cChunkDesc::RandomFillRelCuboid( cBlockEntity * cChunkDesc::GetBlockEntity(int a_RelX, int a_RelY, int a_RelZ) { const auto Idx = cChunkDef::MakeIndex(a_RelX, a_RelY, a_RelZ); - const auto itr = m_BlockEntities.find(Idx); + const auto Iterator = m_BlockArea.GetBlockEntities().find(Idx); - if (itr != m_BlockEntities.end()) + if (Iterator != m_BlockArea.GetBlockEntities().end()) { // Already in the list: - cBlockEntity * BlockEntity = itr->second.get(); + cBlockEntity * BlockEntity = Iterator->second.get(); if (BlockEntity->GetBlockType() == GetBlockType(a_RelX, a_RelY, a_RelZ)) { // Correct type, already present. Return it: @@ -587,7 +587,7 @@ cBlockEntity * cChunkDesc::GetBlockEntity(int a_RelX, int a_RelY, int a_RelZ) else { // Wrong type, the block type has been overwritten. Erase and create new: - m_BlockEntities.erase(itr); + m_BlockArea.GetBlockEntities().erase(Iterator); } } @@ -595,13 +595,13 @@ cBlockEntity * cChunkDesc::GetBlockEntity(int a_RelX, int a_RelY, int a_RelZ) int AbsZ = a_RelZ + m_Coords.m_ChunkZ * cChunkDef::Width; // The block entity is not created yet, try to create it and add to list: - auto be = cBlockEntity::CreateByBlockType(GetBlockType(a_RelX, a_RelY, a_RelZ), GetBlockMeta(a_RelX, a_RelY, a_RelZ), {AbsX, a_RelY, AbsZ}); - if (be == nullptr) + auto BlockEntity = cBlockEntity::CreateByBlockType(GetBlockType(a_RelX, a_RelY, a_RelZ), GetBlockMeta(a_RelX, a_RelY, a_RelZ), {AbsX, a_RelY, AbsZ}); + if (BlockEntity == nullptr) { // No block entity for this block type return nullptr; } - auto res = m_BlockEntities.emplace(Idx, std::move(be)); + auto res = m_BlockArea.GetBlockEntities().emplace(Idx, std::move(BlockEntity)); return res.first->second.get(); } diff --git a/src/Generating/ChunkDesc.h b/src/Generating/ChunkDesc.h index d066660f1..519dbe81c 100644 --- a/src/Generating/ChunkDesc.h +++ b/src/Generating/ChunkDesc.h @@ -238,7 +238,8 @@ public: inline BlockNibbleBytes & GetBlockMetasUncompressed(void) { return *(reinterpret_cast(m_BlockArea.GetBlockMetas())); } inline cChunkDef::HeightMap & GetHeightMap (void) { return m_HeightMap; } inline cEntityList & GetEntities (void) { return m_Entities; } - inline cBlockEntities & GetBlockEntities (void) { return m_BlockEntities; } + inline const cBlockEntities & GetBlockEntities (void) const { return m_BlockArea.GetBlockEntities(); } + inline cBlockEntities & GetBlockEntities (void) { return m_BlockArea.GetBlockEntities(); } inline const cChunkDef::BiomeMap & GetBiomeMap() const { return m_BiomeMap; } inline const cChunkDef::BlockTypes & GetBlockTypes() const { return *(reinterpret_cast(m_BlockArea.GetBlockTypes())); } @@ -259,7 +260,6 @@ private: cBlockArea m_BlockArea; cChunkDef::HeightMap m_HeightMap; cEntityList m_Entities; - cBlockEntities m_BlockEntities; // Individual block entities are NOT owned by this object! bool m_bUseDefaultBiomes; bool m_bUseDefaultHeight; diff --git a/src/Generating/MineShafts.cpp b/src/Generating/MineShafts.cpp index 189b28095..beb1e24a1 100644 --- a/src/Generating/MineShafts.cpp +++ b/src/Generating/MineShafts.cpp @@ -26,7 +26,7 @@ in a depth-first processing. Each of the descendants will branch randomly, if no -class cMineShaft abstract +class cMineShaft { public: enum eKind diff --git a/src/Generating/MineShafts.h b/src/Generating/MineShafts.h index 43eff2055..6c137fed8 100644 --- a/src/Generating/MineShafts.h +++ b/src/Generating/MineShafts.h @@ -35,7 +35,7 @@ protected: class cMineShaftSystem; // fwd: MineShafts.cpp int m_GridSize; ///< Average spacing of the systems - int m_MaxSystemSize; ///< Maximum blcok size of a mineshaft system + int m_MaxSystemSize; ///< Maximum block size of a mineshaft system int m_ProbLevelCorridor; ///< Probability level of a branch object being the corridor int m_ProbLevelCrossing; ///< Probability level of a branch object being the crossing, minus Corridor int m_ProbLevelStaircase; ///< Probability level of a branch object being the staircase, minus Crossing -- cgit v1.2.3