summaryrefslogtreecommitdiffstats
path: root/src/BlockArea.cpp
diff options
context:
space:
mode:
authorpeterbell10 <peterbell10@live.co.uk>2017-06-24 20:25:23 +0200
committerLukas Pioch <lukas@zgow.de>2017-06-24 23:27:26 +0200
commitf0f001c10dd5ee3bb179866c16cf163b9b754fce (patch)
treef2a83986d0233b22d0ac8f0a58e61cadc3285060 /src/BlockArea.cpp
parentcBlockArea supports block entities. (#3795) (diff)
downloadcuberite-f0f001c10dd5ee3bb179866c16cf163b9b754fce.tar
cuberite-f0f001c10dd5ee3bb179866c16cf163b9b754fce.tar.gz
cuberite-f0f001c10dd5ee3bb179866c16cf163b9b754fce.tar.bz2
cuberite-f0f001c10dd5ee3bb179866c16cf163b9b754fce.tar.lz
cuberite-f0f001c10dd5ee3bb179866c16cf163b9b754fce.tar.xz
cuberite-f0f001c10dd5ee3bb179866c16cf163b9b754fce.tar.zst
cuberite-f0f001c10dd5ee3bb179866c16cf163b9b754fce.zip
Diffstat (limited to 'src/BlockArea.cpp')
-rw-r--r--src/BlockArea.cpp86
1 files changed, 45 insertions, 41 deletions
diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp
index a35c391fa..53d82a106 100644
--- a/src/BlockArea.cpp
+++ b/src/BlockArea.cpp
@@ -733,37 +733,39 @@ void cBlockArea::Crop(int a_AddMinX, int a_SubMaxX, int a_AddMinY, int a_SubMaxY
{
CropNibbles(m_BlockSkyLight, a_AddMinX, a_SubMaxX, a_AddMinY, a_SubMaxY, a_AddMinZ, a_SubMaxZ);
}
+ if (HasBlockEntities())
+ {
+ auto maxX = m_Size.x - a_SubMaxX;
+ auto maxY = m_Size.y - a_SubMaxY;
+ auto maxZ = m_Size.z - a_SubMaxZ;
- auto maxX = m_Size.x - a_SubMaxX;
- auto maxY = m_Size.y - a_SubMaxY;
- auto maxZ = m_Size.z - a_SubMaxZ;
-
- // Move and crop block Entities:
- cBlockEntities oldBE;
- std::swap(oldBE, *m_BlockEntities);
- for (const auto & keyPair: oldBE)
- {
- auto & be = keyPair.second;
- auto posX = be->GetPosX();
- auto posY = be->GetPosY();
- auto posZ = be->GetPosZ();
- if (
- (posX < a_AddMinX) || (posX >= maxX) ||
- (posY < a_AddMinY) || (posY >= maxY) ||
- (posZ < a_AddMinZ) || (posZ >= maxZ)
- )
- {
- // The block entity is out of new coord range, remove it:
- delete be;
- }
- else
+ // Move and crop block Entities:
+ cBlockEntities oldBE;
+ std::swap(oldBE, *m_BlockEntities);
+ for (const auto & keyPair: oldBE)
{
- // The block entity is within the new coords, recalculate its coords to match the new area:
- posX -= a_AddMinX;
- posY -= a_AddMinY;
- posZ -= a_AddMinZ;
- be->SetPos(posX, posY, posZ);
- m_BlockEntities->insert({MakeIndex(posX, posY, posZ), std::move(be)});
+ auto & be = keyPair.second;
+ auto posX = be->GetPosX();
+ auto posY = be->GetPosY();
+ auto posZ = be->GetPosZ();
+ if (
+ (posX < a_AddMinX) || (posX >= maxX) ||
+ (posY < a_AddMinY) || (posY >= maxY) ||
+ (posZ < a_AddMinZ) || (posZ >= maxZ)
+ )
+ {
+ // The block entity is out of new coord range, remove it:
+ delete be;
+ }
+ else
+ {
+ // The block entity is within the new coords, recalculate its coords to match the new area:
+ posX -= a_AddMinX;
+ posY -= a_AddMinY;
+ posZ -= a_AddMinZ;
+ be->SetPos(posX, posY, posZ);
+ m_BlockEntities->insert({MakeIndex(posX, posY, posZ), std::move(be)});
+ }
}
}
@@ -795,18 +797,20 @@ void cBlockArea::Expand(int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMa
{
ExpandNibbles(m_BlockSkyLight, a_SubMinX, a_AddMaxX, a_SubMinY, a_AddMaxY, a_SubMinZ, a_AddMaxZ);
}
-
- // Move block entities:
- cBlockEntities oldBE;
- std::swap(oldBE, *m_BlockEntities);
- for (const auto & keyPair: oldBE)
- {
- auto & be = keyPair.second;
- auto posX = be->GetPosX() + a_SubMinX;
- auto posY = be->GetPosY() + a_SubMinY;
- auto posZ = be->GetPosZ() + a_SubMinZ;
- be->SetPos(posX, posY, posZ);
- m_BlockEntities->insert({MakeIndex(posX, posY, posZ), std::move(be)});
+ if (HasBlockEntities())
+ {
+ // Move block entities:
+ cBlockEntities oldBE;
+ std::swap(oldBE, *m_BlockEntities);
+ for (const auto & keyPair: oldBE)
+ {
+ auto & be = keyPair.second;
+ auto posX = be->GetPosX() + a_SubMinX;
+ auto posY = be->GetPosY() + a_SubMinY;
+ auto posZ = be->GetPosZ() + a_SubMinZ;
+ be->SetPos(posX, posY, posZ);
+ m_BlockEntities->insert({MakeIndex(posX, posY, posZ), std::move(be)});
+ }
}
m_Origin.Move(-a_SubMinX, -a_SubMinY, -a_SubMinZ);