From ab03a1883f9d3858aed4c68434c0919bcd526bb7 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Mon, 23 Jan 2023 19:54:35 +0300 Subject: [PATCH] collision tweaks, autojump tweaks --- src/entity/Entity.php | 6 ++--- src/entity/ai/MobController.php | 29 +++++++++++++---------- src/material/block/TransparentBlock.php | 1 + src/material/block/nonfull/FenceBlock.php | 2 ++ 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 53fefbb8..295119c8 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -566,11 +566,11 @@ class Entity extends Position $this->inWater = false; if($this->class === ENTITY_MOB || $this->class === ENTITY_ITEM || ($this->class === ENTITY_OBJECT && $this->type === OBJECT_PRIMEDTNT)){ $aABB = $this->boundingBox->getOffsetBoundingBox($this->speedX, $this->speedY, $this->speedZ); - $x0 = floor($aABB->minX); + $x0 = floor($aABB->minX - 1); $x1 = ceil($aABB->maxX); $y0 = floor($aABB->minY); $y1 = ceil($aABB->maxY); - $z0 = floor($aABB->minZ); + $z0 = floor($aABB->minZ - 1); $z1 = ceil($aABB->maxZ); $x0 = $x0 < 0 ? 0 : $x0; $y0 = $y0 < 0 ? 0 : $y0; @@ -1352,7 +1352,7 @@ class Entity extends Position public function moveEntityWithOffset($oX, $oY, $oZ) { $oX = $oX === 0 ? $this->speedX : ($this->getSpeedModifer() * $oX * $this->getSpeed()); - $oY = $oY <= 0 ? $this->speedY : (0.5); + $oY = $oY <= 0 ? $this->speedY : (0.45); $oZ = $oZ === 0 ? $this->speedZ : ($this->getSpeedModifer() * $oZ * $this->getSpeed()); $this->setVelocity($oX, $oY, $oZ); } diff --git a/src/entity/ai/MobController.php b/src/entity/ai/MobController.php index ce5ce453..bf31572c 100644 --- a/src/entity/ai/MobController.php +++ b/src/entity/ai/MobController.php @@ -20,20 +20,23 @@ class MobController $oz = ($z > 0 ? 1 : ($z < 0 ? -1 : 0)); $xf = $this->entity->x + ($this->entity->getSpeedModifer() * $ox * $this->entity->getSpeed()); $zf = $this->entity->z + ($this->entity->getSpeedModifer() * $oz * $this->entity->getSpeed()); - $bs = [ //TODO simplify(somehow) - $this->entity->level->getBlockWithoutVector(ceil($xf), floor($this->entity->y), ceil($zf)), - $this->entity->level->getBlockWithoutVector(ceil($xf), floor($this->entity->y), $zf - ($oz < 0 ? 1 : 0)), - $this->entity->level->getBlockWithoutVector($xf - ($ox < 0 ? 1 : 0), floor($this->entity->y), $zf - ($oz < 0 ? 1 : 0)), - $this->entity->level->getBlockWithoutVector($xf - ($ox < 0 ? 1 : 0), floor($this->entity->y), ceil($zf)), - ]; - foreach($bs as $b){ - if($b->isSolid){ - if(!$b->getSide(1)->isSolid){ - $oy = 1; - break; - } - } + if($this->entity->onGround){ + $bs = [ //TODO simplify(somehow) + $this->entity->level->getBlockWithoutVector(ceil($xf), floor($this->entity->y), ceil($zf)), + $this->entity->level->getBlockWithoutVector(ceil($xf), floor($this->entity->y), $zf - ($oz < 0 ? 1 : 0)), + $this->entity->level->getBlockWithoutVector($xf - ($ox < 0 ? 1 : 0), floor($this->entity->y), $zf - ($oz < 0 ? 1 : 0)), + $this->entity->level->getBlockWithoutVector($xf - ($ox < 0 ? 1 : 0), floor($this->entity->y), ceil($zf)), + ]; + foreach($bs as $b){ + if($b->isSolid){ + if(!$b->getSide(1)->isSolid){ + $oy = 1; + break; + } + } + } } + if($this->entity->knockbackTime <= 0){ $this->entity->moveEntityWithOffset($ox, $oy, $oz); } diff --git a/src/material/block/TransparentBlock.php b/src/material/block/TransparentBlock.php index 3c98046b..07181e2b 100644 --- a/src/material/block/TransparentBlock.php +++ b/src/material/block/TransparentBlock.php @@ -15,5 +15,6 @@ class TransparentBlock extends GenericBlock{ $this->isReplaceable = false; $this->isPlaceable = true; $this->isSolid = true; + $this->boundingBox->setBounds($this->x, $this->y, $this->z, $this->x + 1, $this->y + 1.2, $this->z + 1); } } \ No newline at end of file diff --git a/src/material/block/nonfull/FenceBlock.php b/src/material/block/nonfull/FenceBlock.php index b9cd6337..9b4b0e91 100644 --- a/src/material/block/nonfull/FenceBlock.php +++ b/src/material/block/nonfull/FenceBlock.php @@ -7,4 +7,6 @@ class FenceBlock extends TransparentBlock{ $this->hardness = 15; } + + } \ No newline at end of file