aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/BoundingBox.cpp
diff options
context:
space:
mode:
authordaoge <3523206925@qq.com>2026-03-03 03:04:10 +0800
committerGitHub <noreply@github.com>2026-03-03 03:04:10 +0800
commitb3feddfef372618c8a9d7a0abcaf18cfad866c18 (patch)
tree267761c3bb39241ba5c347bfbe2254d06686e287 /Minecraft.World/BoundingBox.cpp
parent84c31a2331f7a0ec85b9d438992e244f60e5020f (diff)
feat: TU19 (Dec 2014) Features & Content (#155)
* try to resolve merge conflict * feat: TU19 (Dec 2014) Features & Content (#32) * December 2014 files * Working release build * Fix compilation issues * Add sound to Windows64Media * Add DLC content and force Tutorial DLC * Revert "Add DLC content and force Tutorial DLC" This reverts commit 97a43994725008e35fceb984d5549df9c8cea470. * Disable broken light packing * Disable breakpoint during DLC texture map load Allows DLC loading but the DLC textures are still broken * Fix post build not working * ... * fix vs2022 build * fix cmake build --------- Co-authored-by: Loki <lokirautio@gmail.com>
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