From 2cdf3ca8da6d5c74546e15e799dc0f56d25c78cb Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Mon, 26 Dec 2022 02:47:08 +0300 Subject: [PATCH] readded useless loop, fixed falling --- src/entity/Creature.php | 30 ++++++++++++------------------ src/entity/Entity.php | 39 +++++++++++++++++++++++++++++++++++---- src/entity/Living.php | 4 ++-- 3 files changed, 49 insertions(+), 24 deletions(-) diff --git a/src/entity/Creature.php b/src/entity/Creature.php index 7949610c..ab11857c 100644 --- a/src/entity/Creature.php +++ b/src/entity/Creature.php @@ -25,26 +25,20 @@ abstract class Creature extends Living{ } public function update(){ - /*if($this->path === null && $this->pathFinder instanceof ITileNavigator){ - $this->path = $this->pathFinder->navigate(new PathTileXYZ($this->x, $this->y, $this->z, $this->level), new PathTileXYZ($this->x + mt_rand(-7, 7), $this->y, $this->z + mt_rand(-7, 7), $this->level)); + if($this->onGround){ + /*if($this->path === null && $this->pathFinder instanceof ITileNavigator && mt_rand(0, 120) === 0){ + $this->path = $this->pathFinder->navigate(new PathTileXYZ($this->x, $this->y, $this->z, $this->level), new PathTileXYZ($this->x + mt_rand(-10, 10), $this->y, $this->z + mt_rand(-10, 10), $this->level)); + } + if($this->path != null && (is_array($this->path) && count($this->path) <= 0 || $this->currentIndex >= count($this->path))){ + $this->path = null; + $this->currentIndex = 0; + $this->currentNode = false; + }elseif($this->path != null && ($this->currentNode == false || $this->ai->mobController->moveTo($this->currentNode->x, $this->currentNode->y, $this->currentNode->z) === false)){ + $this->currentNode = $this->path[$this->currentIndex++]; + }*/ } - if(is_array($this->path) && count($this->path) <= 0 || $this->currentIndex >= count($this->path)){ - $this->path = null; - $this->currentIndex = 0; - $this->currentNode = false; - }elseif($this->currentNode == false || $this->ai->mobController->moveTo($this->currentNode->x, $this->currentNode->y, $this->currentNode->z) === false){ - console("this"); - $this->currentNode = $this->path[$this->currentIndex++]; - }*/ - - - /*if($this->path === false || count($this->path) <= 0){ - } - $state = $this->pathNavigator->followPath($this->path); - if($state === PathNavigator::PATH_COMPLETED){ - $this->path = false; - }*/ parent::update(); + } public function createSaveData(){ diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 6efe939f..85a24316 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -69,7 +69,9 @@ class Entity extends Position public $radius; public $inAction = false; public $hasKnockback; - + + public $onGround; + function __construct(Level $level, $eid, $class, $type = 0, $data = array()) { $this->random = new Random(); @@ -635,6 +637,36 @@ class Entity extends Position } } + if(!$support){ + for($z = $startZ; $z <= $endZ; ++ $z){ + for($x = $startX; $x <= $endX; ++ $x){ + $v = new Vector3($x, $y, $z); + $v1 = new Vector3($x, $yC, $z); + if($this->isSupport($v, $this->width)){ + $b = $this->level->getBlock($v); + if($b->isSolid === true){ + $support = true; + $isFlying = false; + break; + } elseif(($b instanceof LiquidBlock) or $b->getID() === COBWEB or $b->getID() === LADDER or $b->getID() === FENCE or $b->getID() === STONE_WALL or $b->getID() === IRON_BARS){ + $isFlying = false; + } + } elseif($this->isSupport($v1, $this->width)){ + $b = $this->level->getBlock($v1); + if($b->isSolid === true){ + $support = true; + $isFlying = false; + break; + } elseif(($b instanceof LiquidBlock) or $b->getID() === COBWEB or $b->getID() === LADDER or $b->getID() === FENCE or $b->getID() === STONE_WALL or $b->getID() === IRON_BARS){ + $isFlying = false; + } + } + } + if($support === true){ + break; + } + } + } if($this->speedX != 0){ $this->x += $this->speedX; $this->speedX -= $this->speedX * $drag; @@ -677,10 +709,9 @@ class Entity extends Position $this->speedY -= $this->speedY * $drag; $update = true; } - if($this->speedY == 0){ - $support = true; - } + $this->onGround = $support; + if($this->hasGravity && $support === false){ $this->speedY -= ($this->class === ENTITY_FALLING) ? 0.04 : ($this->class === ENTITY_ITEM ? 0.06 : 0.08); // TODO: replace with $gravity $update = true; diff --git a/src/entity/Living.php b/src/entity/Living.php index 3a841167..bb76611e 100644 --- a/src/entity/Living.php +++ b/src/entity/Living.php @@ -7,8 +7,8 @@ abstract class Living extends Entity implements Damageable{ $this->ai = new EntityAI($this); parent::__construct($level, $eid, $class, $type, $data); $this->canBeAttacked = true; - $this->hasGravity = true; - $this->hasKnockback = true; + $this->hasGravity = true; + $this->hasKnockback = true; } public function update(){