From d01de52d036d3429eac340b6dda5a189d5b23cb4 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Sun, 2 Jul 2023 05:16:58 +0300 Subject: [PATCH] better player fall damage, TODO anti fly & other stuff --- src/entity/Entity.php | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/entity/Entity.php b/src/entity/Entity.php index bb4d7d25..f91e3340 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -557,6 +557,7 @@ class Entity extends Position break; } } + $this->onGround = $support; } if(!$this->isPlayer()){ $update = false; @@ -686,7 +687,25 @@ class Entity extends Position } $this->updateFallState($this->speedY); } elseif($this->player instanceof Player){ - if($isFlying === true and ($this->player->gamemode & 0x01) === 0x00){ + + $this->speedX = -($this->lastX - $this->x); + $this->speedY = -($this->lastY - $this->y); + $this->speedZ = -($this->lastZ - $this->z); + $this->printSpeed(); + for($x = floor($this->boundingBox->minX); $x <= ceil($this->boundingBox->maxX); ++$x){ + for($z = floor($this->boundingBox->minZ); $z <= ceil($this->boundingBox->maxZ); ++$z){ + for($y = floor($this->boundingBox->minY); $y <= ceil($this->boundingBox->maxY); ++$y){ + $id = $this->level->level->getBlockID($x, $y, $z); + if($id === WATER || $id === STILL_WATER || $id === COBWEB){ + $this->fallDistance = 0; + } + } + } + } + $this->updateFallState($this->speedY); + + $hasUpdate = true; + /*if($isFlying === true and ($this->player->gamemode & 0x01) === 0x00){ if($this->fallY === false or $this->fallStart === false){ $this->fallY = $y; $this->fallStart = microtime(true); @@ -718,7 +737,7 @@ class Entity extends Position $this->calculateVelocity(); if($this->speed <= 9 or ($this->speed <= 20 and ($this->player->gamemode & 0x01) === 0x01)){ $this->player->lastCorrect = new Vector3($this->last[0], $this->last[1], $this->last[2]); - } + }*/ //TODO anticheat stuff } } if($this->knockbackTime > 0){ @@ -744,7 +763,14 @@ class Entity extends Position $this->needsUpdate = $hasUpdate; $this->lastUpdate = $now; } - public function fall(){} + public function fall(){ + if($this->isPlayer()){ + $dmg = floor($this->fallDistance - 3); + if($dmg > 0){ + $this->harm($dmg, "fall"); + } + } + } public function updateFallState($fallTick){ if($this->onGround && $this->fallDistance > 0){