aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/BoundingBox.cpp
diff options
context:
space:
mode:
authorLoki Rautio <lokirautio@gmail.com>2026-03-04 03:56:03 -0600
committerLoki Rautio <lokirautio@gmail.com>2026-03-04 03:56:03 -0600
commit42aec6dac53dffa6afe072560a7e1d4986112538 (patch)
tree0836426857391df1b6a83f6368a183f83ec9b104 /Minecraft.World/BoundingBox.cpp
parentc9d58eeac7c72f0b3038e084667b4d89a6249fce (diff)
parentef9b6fd500dfabd9463267b0dd9e29577eea8a2b (diff)
Merge branch 'main' into pr/win64-world-saves
# Conflicts: # Minecraft.Client/MinecraftServer.cpp # README.md
Diffstat (limited to 'Minecraft.World/BoundingBox.cpp')
-rw-r--r--Minecraft.World/BoundingBox.cpp129
1 files changed, 76 insertions, 53 deletions
diff --git a/Minecraft.World/BoundingBox.cpp b/Minecraft.World/BoundingBox.cpp
index eb828ed0..24972bf9 100644
--- a/Minecraft.World/BoundingBox.cpp
+++ b/Minecraft.World/BoundingBox.cpp
@@ -14,6 +14,19 @@ BoundingBox::BoundingBox()
z1 = 0;
}
+BoundingBox::BoundingBox(intArray sourceData)
+{
+ if (sourceData.length == 6)
+ {
+ x0 = sourceData[0];
+ y0 = sourceData[1];
+ z0 = sourceData[2];
+ x1 = sourceData[3];
+ y1 = sourceData[4];
+ z1 = sourceData[5];
+ }
+}
+
BoundingBox *BoundingBox::getUnknownBox()
{
return new BoundingBox(INT_MAX, INT_MAX, INT_MAX, INT_MIN, INT_MIN, INT_MIN );
@@ -21,56 +34,56 @@ BoundingBox *BoundingBox::getUnknownBox()
BoundingBox *BoundingBox::orientBox(int footX, int footY, int footZ, int offX, int offY, int offZ, int width, int height, int depth, int orientation)
{
- switch (orientation)
+ switch (orientation)
{
- default:
- return new BoundingBox(footX + offX, footY + offY, footZ + offZ, footX + width - 1 + offX, footY + height - 1 + offY, footZ + depth - 1 + offZ);
+ default:
+ return new BoundingBox(footX + offX, footY + offY, footZ + offZ, footX + width - 1 + offX, footY + height - 1 + offY, footZ + depth - 1 + offZ);
case Direction::NORTH:
- // foot is at x0, y0, z1
- return new BoundingBox(footX + offX, footY + offY, footZ - depth + 1 + offZ, footX + width - 1 + offX, footY + height - 1 + offY, footZ + offZ);
+ // foot is at x0, y0, z1
+ return new BoundingBox(footX + offX, footY + offY, footZ - depth + 1 + offZ, footX + width - 1 + offX, footY + height - 1 + offY, footZ + offZ);
case Direction::SOUTH:
- // foot is at x0, y0, z0
- return new BoundingBox(footX + offX, footY + offY, footZ + offZ, footX + width - 1 + offX, footY + height - 1 + offY, footZ + depth - 1 + offZ);
+ // foot is at x0, y0, z0
+ return new BoundingBox(footX + offX, footY + offY, footZ + offZ, footX + width - 1 + offX, footY + height - 1 + offY, footZ + depth - 1 + offZ);
case Direction::WEST:
- // foot is at x1, y0, z0, but width and depth are flipped
- return new BoundingBox(footX - depth + 1 + offZ, footY + offY, footZ + offX, footX + offZ, footY + height - 1 + offY, footZ + width - 1 + offX);
+ // foot is at x1, y0, z0, but width and depth are flipped
+ return new BoundingBox(footX - depth + 1 + offZ, footY + offY, footZ + offX, footX + offZ, footY + height - 1 + offY, footZ + width - 1 + offX);
case Direction::EAST:
- // foot is at x0, y0, z0, but width and depth are flipped
- return new BoundingBox(footX + offZ, footY + offY, footZ + offX, footX + depth - 1 + offZ, footY + height - 1 + offY, footZ + width - 1 + offX);
- }
+ // foot is at x0, y0, z0, but width and depth are flipped
+ return new BoundingBox(footX + offZ, footY + offY, footZ + offX, footX + depth - 1 + offZ, footY + height - 1 + offY, footZ + width - 1 + offX);
+ }
}
BoundingBox::BoundingBox(BoundingBox *other)
{
- this->x0 = other->x0;
- this->y0 = other->y0;
- this->z0 = other->z0;
- this->x1 = other->x1;
- this->y1 = other->y1;
- this->z1 = other->z1;
+ x0 = other->x0;
+ y0 = other->y0;
+ z0 = other->z0;
+ x1 = other->x1;
+ y1 = other->y1;
+ z1 = other->z1;
}
BoundingBox::BoundingBox(int x0, int y0, int z0, int x1, int y1, int z1)
{
- this->x0 = x0;
- this->y0 = y0;
- this->z0 = z0;
- this->x1 = x1;
- this->y1 = y1;
- this->z1 = z1;
+ this->x0 = x0;
+ this->y0 = y0;
+ this->z0 = z0;
+ this->x1 = x1;
+ this->y1 = y1;
+ this->z1 = z1;
}
BoundingBox::BoundingBox(int x0, int z0, int x1, int z1)
{
- this->x0 = x0;
- this->z0 = z0;
- this->x1 = x1;
- this->z1 = z1;
+ this->x0 = x0;
+ this->z0 = z0;
+ this->x1 = x1;
+ this->z1 = z1;
// the bounding box for this constructor is limited to world size,
// excluding bedrock level
- this->y0 = 1;
- this->y1 = 512;
+ y0 = 1;
+ y1 = 512;
}
bool BoundingBox::intersects(BoundingBox *other)
@@ -90,39 +103,39 @@ bool BoundingBox::intersects(int x0, int z0, int x1, int z1)
void BoundingBox::expand(BoundingBox *other)
{
- this->x0 = Math::_min(this->x0, other->x0);
- this->y0 = Math::_min(this->y0, other->y0);
- this->z0 = Math::_min(this->z0, other->z0);
- this->x1 = Math::_max(this->x1, other->x1);
- this->y1 = Math::_max(this->y1, other->y1);
- this->z1 = Math::_max(this->z1, other->z1);
+ x0 = Math::_min(x0, other->x0);
+ y0 = Math::_min(y0, other->y0);
+ z0 = Math::_min(z0, other->z0);
+ x1 = Math::_max(x1, other->x1);
+ y1 = Math::_max(y1, other->y1);
+ z1 = Math::_max(z1, other->z1);
}
BoundingBox *BoundingBox::getIntersection(BoundingBox *other)
{
- if (!intersects(other))
+ if (!intersects(other))
{
- return NULL;
- }
- BoundingBox *result = new BoundingBox();
- result->x0 = Math::_max(this->x0, other->x0);
- result->y0 = Math::_max(this->y0, other->y0);
- result->z0 = Math::_max(this->z0, other->z0);
- result->x1 = Math::_min(this->x1, other->x1);
- result->y1 = Math::_min(this->y1, other->y1);
- result->z1 = Math::_min(this->z1, other->z1);
+ return NULL;
+ }
+ BoundingBox *result = new BoundingBox();
+ result->x0 = Math::_max(x0, other->x0);
+ result->y0 = Math::_max(y0, other->y0);
+ result->z0 = Math::_max(z0, other->z0);
+ result->x1 = Math::_min(x1, other->x1);
+ result->y1 = Math::_min(y1, other->y1);
+ result->z1 = Math::_min(z1, other->z1);
- return result;
+ return result;
}
void BoundingBox::move(int dx, int dy, int dz)
{
- x0 += dx;
- y0 += dy;
- z0 += dz;
- x1 += dx;
- y1 += dy;
- z1 += dz;
+ x0 += dx;
+ y0 += dy;
+ z0 += dz;
+ x1 += dx;
+ y1 += dy;
+ z1 += dz;
}
bool BoundingBox::isInside(int x, int y, int z)
@@ -163,4 +176,14 @@ int BoundingBox::getZCenter()
wstring BoundingBox::toString()
{
return L"(" + _toString<int>(x0) + L", " + _toString<int>(y0) + L", " + _toString<int>(z0) + L"; " + _toString<int>(x1) + L", " + _toString<int>(y1) + L", " + _toString<int>(z1) + L")";
+}
+
+IntArrayTag *BoundingBox::createTag(const wstring &name)
+{
+ // 4J-JEV: If somebody knows a better way to do this, please tell me.
+ int *data = new int[6]();
+ data[0] = x0; data[1] = y0; data[2] = z0;
+ data[3] = x1; data[4] = y1; data[5] = z1;
+
+ return new IntArrayTag( name, intArray(data,6) );
} \ No newline at end of file