From bbe9e0ee13866f0960451b6476ace4e7fd2011c6 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Wed, 16 Jul 2025 19:16:11 +0300 Subject: [PATCH] fixed enitites being able to clip through 0 barrier --- src/entity/Entity.php | 8 ++++---- src/math/AxisAlignedBB.php | 13 ++++++++++++- src/world/Level.php | 2 +- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 8ef686cd..0d3970c0 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -586,7 +586,7 @@ class Entity extends Position } } - + public function move($dx, $dy, $dz){ $movX = $this->x; $movY = $this->y; @@ -610,6 +610,7 @@ class Entity extends Position $aaBBs = $this->level->getCubes($this, $this->boundingBox->addCoord($dx, $dy, $dz)); + foreach($aaBBs as $bb){ $dy = $bb->calculateYOffset($this->boundingBox, $dy); } @@ -618,14 +619,13 @@ class Entity extends Position foreach($aaBBs as $bb){ $dx = $bb->calculateXOffset($this->boundingBox, $dx); } - $this->boundingBox->offset($dx, 0, 0); + $this->boundingBox->offset($dx, 0, 0); foreach($aaBBs as $bb){ $dz = $bb->calculateZOffset($this->boundingBox, $dz); } $this->boundingBox->offset(0, 0, $dz); - $fallingFlag = $this->onGround || $savedDY != $dy && $savedDY < 0; if($this->stepHeight > 0 && $fallingFlag && ($savedDX != $dx || $savedDZ != $dz)){ @@ -666,6 +666,7 @@ class Entity extends Position $this->modifySpeedY = true; $this->modifedSpeedY = 0.5; } + } $this->x = ($this->boundingBox->minX + $this->boundingBox->maxX) / 2; @@ -677,7 +678,6 @@ class Entity extends Position $this->isCollided = $this->isCollidedHorizontally || $this->isCollidedVertically; $this->updateFallState($this->speedY); - if($savedDX != $dx) $this->speedX = 0; if($savedDY != $dy) $this->speedY = 0; if($savedDZ != $dz) $this->speedZ = 0; diff --git a/src/math/AxisAlignedBB.php b/src/math/AxisAlignedBB.php index 187700ca..a186fa68 100644 --- a/src/math/AxisAlignedBB.php +++ b/src/math/AxisAlignedBB.php @@ -75,7 +75,14 @@ class AxisAlignedBB{ $this->maxX += $x; $this->maxY += $y; $this->maxZ += $z; - + + if($this->minX < 1e-6 && $this->minX > -1e-6)$this->minX = 0; + if($this->minY < 1e-6 && $this->minY > -1e-6)$this->minY = 0; + if($this->minZ < 1e-6 && $this->minZ > -1e-6)$this->minZ = 0; + if($this->maxX < 1e-6 && $this->maxX > -1e-6)$this->maxX = 0; + if($this->maxY < 1e-6 && $this->maxY > -1e-6)$this->maxY = 0; + if($this->maxZ < 1e-6 && $this->maxZ > -1e-6)$this->maxZ = 0; + return $this; } @@ -170,6 +177,10 @@ class AxisAlignedBB{ return $z; } + public function intersectsWith_(AxisAlignedBB $bb){ + return $bb->maxX > $this->minX && $bb->minX < $this->maxX && $bb->maxY > $this->minY && $bb->minY < $this->maxY && $bb->maxZ > $this->minZ && $bb->minZ < $this->maxZ; + } + public function intersectsWith(AxisAlignedBB $bb){ return $bb->maxX >= $this->minX && $bb->minX <= $this->maxX && $bb->maxZ >= $this->minZ && $bb->minZ <= $this->maxZ && $bb->maxY >= $this->minY && $bb->minY <= $this->maxY; } diff --git a/src/world/Level.php b/src/world/Level.php index 2f1cc931..bd18ffb7 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -277,7 +277,7 @@ class Level{ $blockBounds = StaticBlock::$prealloc[$bid]::getCollisionBoundingBoxes($this, $x, $y, $z, $e); //StaticBlock::getBoundingBoxForBlockCoords($b, $x, $y, $z); foreach($blockBounds as $blockBound){ - if($aABB->intersectsWith($blockBound)) $aABBs[] = $blockBound; + if($aABB->intersectsWith_($blockBound)) $aABBs[] = $blockBound; } } }