diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 301f0d04..67211d43 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -568,6 +568,10 @@ class Entity extends Position $y1 = ceil($aABB->maxY); $z0 = floor($aABB->minZ); $z1 = ceil($aABB->maxZ); + + $ywMin = floor($aABB->minY + 0.4); + $ywMax = ceil($aABB->maxY - 0.4); + $x0 = $x0 < 0 ? 0 : $x0; $y0 = $y0 < 0 ? 0 : $y0; $z0 = $z0 < 0 ? 0 : $z0; @@ -579,8 +583,9 @@ class Entity extends Position for($z = $z0; $z < $z1; ++$z){ $pos = new Vector3($x, $y, $z); $b = $this->level->getBlock($pos); - if($b->y == ($y1 - 1) && ($b->getID() === WATER || $b->getID() === STILL_WATER)){ - $water = true; + if(($b->getID() === WATER || $b->getID() === STILL_WATER)){ + $water = $b->y == ($y1 - 1); + $this->fallDistance = 0; } if($b != false && $b->isSolid){ $this->speedY = $b->boundingBox->calculateYOffset($this->boundingBox, $this->speedY); @@ -729,7 +734,6 @@ class Entity extends Position $this->needsUpdate = $hasUpdate; $this->lastUpdate = $now; } - public function fall(){} public function updateFallState($fallTick){ diff --git a/src/entity/Living.php b/src/entity/Living.php index 97bae63c..92d967c4 100644 --- a/src/entity/Living.php +++ b/src/entity/Living.php @@ -39,6 +39,7 @@ abstract class Living extends Entity implements Damageable, Pathfindable{ $this->ai->updateTasks(); } $this->ai->mobController->rotateTick(); + $this->ai->mobController->movementTick(); if($this->onGround){ //if(!$this->hasPath() && $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(-10, 10), $this->y + mt_rand(-1, 1), $this->z + mt_rand(-10, 10), $this->level), 10); diff --git a/src/entity/ai/MobController.php b/src/entity/ai/MobController.php index c5db87f5..c382ad74 100644 --- a/src/entity/ai/MobController.php +++ b/src/entity/ai/MobController.php @@ -9,11 +9,21 @@ class MobController public $finalYaw, $finalPitch, $finalHeadYaw; + protected $jumping; + protected $jumpTimeout; public function __construct($e){ $this->entity = $e; } + public function isJumping(){ + return $this->jumping; + } + + public function setJumping($b){ + $this->jumping = $b; + } + public function moveNonInstant($x, $y, $z){ if($x == 0 && $y == 0 && $z == 0){ return false; @@ -47,6 +57,15 @@ class MobController return true; } + public function movementTick(){ + if($this->isJumping() && $this->jumpTimeout <= 0){ + $this->jumpTimeout = 10; + $this->entity->speedY = 0.42; + } + + if($this->jumpTimeout > 0) --$this->jumpTimeout; + } + public function rotateTick(){ //TODO handle more rotation $w180 = Utils::wrapAngleTo180($this->finalHeadYaw - $this->entity->headYaw); $w180min = min(abs($w180), 20)*Utils::getSign($w180); diff --git a/src/entity/ai/tasks/TaskSwimming.php b/src/entity/ai/tasks/TaskSwimming.php index 2bf1b910..3ece25c4 100644 --- a/src/entity/ai/tasks/TaskSwimming.php +++ b/src/entity/ai/tasks/TaskSwimming.php @@ -16,10 +16,12 @@ class TaskSwimming extends TaskBase { if(!$ai->entity->inWater){ $this->reset(); + $ai->mobController->setJumping(false); + return; } if(Utils::randomFloat() < 0.8){ #1.5.2 method - $ai->entity->speedY = 0.42; + $ai->mobController->setJumping(true); } diff --git a/src/material/block/LiquidBlock.php b/src/material/block/LiquidBlock.php index 03b07ca2..c34ce5ad 100644 --- a/src/material/block/LiquidBlock.php +++ b/src/material/block/LiquidBlock.php @@ -18,4 +18,8 @@ class LiquidBlock extends TransparentBlock{ public function getDrops(Item $item, Player $player){ return array(); } + + public function getLiquidHeight(){ //TODO lava,water meta + return (($this->meta >= 8 ? 0 : $this->meta)+1) / 9; + } } \ No newline at end of file