From f7cccfb2c3c893a9a8221ef7f3d2cb08caff613d Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Wed, 30 Aug 2023 08:16:52 +0300 Subject: [PATCH] fixed lava and fire mob collision(ignore mobcontroller) --- src/entity/Entity.php | 4 +- src/entity/ai/MobController.php | 67 +++++++++++++++++++++++++-------- src/pmf/PMFLevel.php | 2 +- 3 files changed, 54 insertions(+), 19 deletions(-) diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 9732d61c..8b73974a 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -446,7 +446,7 @@ class Entity extends Position break; case LAVA: // Lava damage case STILL_LAVA: - if ($this->inBlockNonVector($x, $y, $z)) { + if ((!$this->isPlayer() && StaticBlock::getBoundingBoxForBlockCoords($id, $x, $y, $z)->intersectsWith($this->boundingBox)) || ($this->isPlayer() && $this->inBlockNonVector($x, $y, $z))) { $this->harm(5, "lava"); $this->fire = 300; $this->updateMetadata(); @@ -454,7 +454,7 @@ class Entity extends Position } break; case FIRE: // Fire block damage - if ($this->inBlockNonVector($x, $y, $z)) { + if ((!$this->isPlayer() && StaticBlock::getBoundingBoxForBlockCoords($id, $x, $y, $z)->intersectsWith($this->boundingBox)) || ($this->isPlayer() && $this->inBlockNonVector($x, $y, $z))) { $this->harm(1, "fire"); $this->fire = 300; $this->updateMetadata(); diff --git a/src/entity/ai/MobController.php b/src/entity/ai/MobController.php index d1b3f0d5..0614c518 100644 --- a/src/entity/ai/MobController.php +++ b/src/entity/ai/MobController.php @@ -2,6 +2,12 @@ class MobController { + public static $ADVANCED = false; + public static $DANGEROUS_BLOCKS = [ + LAVA => true, + STILL_LAVA => true, + FIRE => true, + ]; /** * @var Entity */ @@ -15,7 +21,9 @@ class MobController public function __construct($e){ $this->entity = $e; } - + public function isDangerous($id){ + return isset(self::$DANGEROUS_BLOCKS[$id]); + } public function isJumping(){ return $this->jumping; } @@ -34,21 +42,48 @@ 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()); - if($this->entity->onGround){ - $oy = - StaticBlock::getIsSolid($this->entity->level->level->getBlockID(ceil($xf), floor($this->entity->y), ceil($zf))) && - !StaticBlock::getIsSolid($this->entity->level->level->getBlockID(ceil($xf), floor($this->entity->y) + 1, ceil($zf))) - || - StaticBlock::getIsSolid($this->entity->level->level->getBlockID(ceil($xf), floor($this->entity->y), $zf - ($oz < 0))) && - !StaticBlock::getIsSolid($this->entity->level->level->getBlockID(ceil($xf), floor($this->entity->y) + 1, $zf - ($oz < 0))) - || - StaticBlock::getIsSolid($this->entity->level->level->getBlockID($xf - ($ox < 0), floor($this->entity->y), $zf - ($oz < 0))) && - !StaticBlock::getIsSolid($this->entity->level->level->getBlockID($xf - ($ox < 0), floor($this->entity->y) + 1, $zf - ($oz < 0))) - || - StaticBlock::getIsSolid($this->entity->level->level->getBlockID($xf - ($ox < 0), floor($this->entity->y), ceil($zf))) && - !StaticBlock::getIsSolid($this->entity->level->level->getBlockID($xf - ($ox < 0), floor($this->entity->y) + 1, ceil($zf))) - ; - + $a = $b = $c = $d = 0; + $oy = $this->entity->onGround && ( + StaticBlock::getIsSolid(($a = $this->entity->level->level->getBlockID(ceil($xf), (int)($this->entity->y), ceil($zf)))) && + !StaticBlock::getIsSolid($this->entity->level->level->getBlockID(ceil($xf), (int)($this->entity->y) + 1, ceil($zf))) + || + StaticBlock::getIsSolid(($b = $this->entity->level->level->getBlockID(ceil($xf), (int)($this->entity->y), $zf - ($oz < 0)))) && + !StaticBlock::getIsSolid($this->entity->level->level->getBlockID(ceil($xf), (int)($this->entity->y) + 1, $zf - ($oz < 0))) + || + StaticBlock::getIsSolid(($c = $this->entity->level->level->getBlockID($xf - ($ox < 0), (int)($this->entity->y), $zf - ($oz < 0)))) && + !StaticBlock::getIsSolid($this->entity->level->level->getBlockID($xf - ($ox < 0), (int)($this->entity->y) + 1, $zf - ($oz < 0))) + || + StaticBlock::getIsSolid(($d = $this->entity->level->level->getBlockID($xf - ($ox < 0), (int)($this->entity->y), ceil($zf)))) && + !StaticBlock::getIsSolid($this->entity->level->level->getBlockID($xf - ($ox < 0), (int)($this->entity->y) + 1, ceil($zf))) + ); + + while(self::$ADVANCED){ + if($this->isDangerous($a) || $this->isDangerous($b) || $this->isDangerous($c) || $this->isDangerous($d)){ + return false; + } + $id1 = $this->entity->level->level->getBlockID($xf, $this->entity->y + $oy - 1, $zf); + if($this->isDangerous($id1)) return false; + if(!StaticBlock::getIsSolid($id1)){ + $id2 = $this->entity->level->level->getBlockID($xf, $this->entity->y - 2, $zf); + $id3 = $this->entity->level->level->getBlockID($xf, $this->entity->y - 3, $zf); + $id4 = $this->entity->level->level->getBlockID($xf, $this->entity->y - 4, $zf); + $s2 = StaticBlock::getIsSolid($id2); + $s3 = StaticBlock::getIsSolid($id3); + $s4 = StaticBlock::getIsSolid($id4); + if($this->isDangerous($id2)) return false; + if($s2) break; //i cant goto label which wasnt declared before + + if($this->isDangerous($id3)) return false; + if($s3) break; + + if($this->isDangerous($id4)) return false; + if($s4) break; + + if(!($this->entity instanceof Chicken)){ + return false; + } + } + break; } $this->faceEntity($ox, $oy, $oz); if($this->entity->knockbackTime <= 0){ diff --git a/src/pmf/PMFLevel.php b/src/pmf/PMFLevel.php index ccf2e299..a642aea4 100644 --- a/src/pmf/PMFLevel.php +++ b/src/pmf/PMFLevel.php @@ -193,7 +193,7 @@ class PMFLevel extends PMF{ unset($this->chunks[$index], $this->chunkChange[$index]); return true; } - + public function isChunkLoaded($X, $Z){ $index = $this->getIndex($X, $Z); if(!isset($this->chunks[$index]) or $this->chunks[$index] === false){