From 6b68b88572170bb275b5980095f72035300dc845 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Thu, 23 Feb 2023 18:54:10 +0300 Subject: [PATCH] mob fall damage --- src/entity/Entity.php | 18 +++++++++++++++--- src/entity/Living.php | 7 ++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/entity/Entity.php b/src/entity/Entity.php index b4cf8486..301f0d04 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -7,7 +7,7 @@ class Entity extends Position const CLASS_TYPE = - 1; public $counter = 0; - + public $fallDistance = 0; public static $updateOnTick, $allowedAI; public $isCollidable; public $canBeAttacked; @@ -669,7 +669,7 @@ class Entity extends Position $this->server->api->handle("entity.motion", $this); } } - + $this->updateFallState($this->speedY); } elseif($this->player instanceof Player){ if($isFlying === true and ($this->player->gamemode & 0x01) === 0x00){ if($this->fallY === false or $this->fallStart === false){ @@ -729,7 +729,19 @@ class Entity extends Position $this->needsUpdate = $hasUpdate; $this->lastUpdate = $now; } - + + public function fall(){} + + public function updateFallState($fallTick){ + if($this->onGround && $this->fallDistance > 0){ + $this->fall(); + $this->fallDistance = 0; + }elseif($fallTick < 0){ + $this->fallDistance -= $fallTick; + } + + } + public function updateMovement() { if($this->closed === true){ diff --git a/src/entity/Living.php b/src/entity/Living.php index 2c103d93..97bae63c 100644 --- a/src/entity/Living.php +++ b/src/entity/Living.php @@ -17,7 +17,12 @@ abstract class Living extends Entity implements Damageable, Pathfindable{ $this->hasKnockback = true; if(self::$despawnMobs) $this->server->schedule(self::$despawnTimer, [$this, "close"]); //900*20 } - + public function fall(){ + $dmg = floor($this->fallDistance - 3); + if($dmg > 0){ + $this->harm($dmg, "fall"); + } + } public function hasPath(){ return $this->path != null; }