diff options
author | Tiger Wang <ziwei.tiger@outlook.com> | 2017-08-18 12:33:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-18 12:33:46 +0200 |
commit | e7a5e2952219acbe42b43a0450b388169e2f760a (patch) | |
tree | 10f2f398303fb788c0e21e9765eb4cb4096cf13b /src | |
parent | Represent cItem::m_Lore as an AStringVector (#3882) (diff) | |
parent | cChunk: Don't assume GetBlockEntity coords are valid (diff) | |
download | cuberite-e7a5e2952219acbe42b43a0450b388169e2f760a.tar cuberite-e7a5e2952219acbe42b43a0450b388169e2f760a.tar.gz cuberite-e7a5e2952219acbe42b43a0450b388169e2f760a.tar.bz2 cuberite-e7a5e2952219acbe42b43a0450b388169e2f760a.tar.lz cuberite-e7a5e2952219acbe42b43a0450b388169e2f760a.tar.xz cuberite-e7a5e2952219acbe42b43a0450b388169e2f760a.tar.zst cuberite-e7a5e2952219acbe42b43a0450b388169e2f760a.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/Chunk.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/Chunk.cpp b/src/Chunk.cpp index f2b936a3f..4c85c9c80 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -1775,16 +1775,20 @@ void cChunk::AddBlockEntityClean(cBlockEntity * a_BlockEntity) cBlockEntity * cChunk::GetBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ) { - // Check that the query coords are within chunk bounds: - ASSERT(a_BlockX >= m_PosX * cChunkDef::Width); - ASSERT(a_BlockX < m_PosX * cChunkDef::Width + cChunkDef::Width); - ASSERT(a_BlockZ >= m_PosZ * cChunkDef::Width); - ASSERT(a_BlockZ < m_PosZ * cChunkDef::Width + cChunkDef::Width); - int RelX = a_BlockX - m_PosX * cChunkDef::Width; int RelZ = a_BlockZ - m_PosZ * cChunkDef::Width; - auto itr = m_BlockEntities.find(MakeIndex(RelX, a_BlockY, RelZ)); + if ( + !IsValidWidth (RelX) || + !IsValidHeight(a_BlockY) || + !IsValidWidth (RelZ) + ) + { + // Coordinates are outside outside the world, no block entities here + return nullptr; + } + + auto itr = m_BlockEntities.find(MakeIndexNoCheck(RelX, a_BlockY, RelZ)); return (itr == m_BlockEntities.end()) ? nullptr : itr->second; } |