From a980eda1bed0df904a148eb4f9ee93884b753df7 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Sat, 13 Jul 2024 00:49:21 +0300 Subject: [PATCH] readded fly kicking(toggleable), small tweaks to fall damage --- src/API/ServerAPI.php | 7 +++++-- src/Player.php | 1 + src/entity/Entity.php | 38 +++++++++++++++++++++++++++++++++++--- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/API/ServerAPI.php b/src/API/ServerAPI.php index 3df1cf5c..55a3af1e 100644 --- a/src/API/ServerAPI.php +++ b/src/API/ServerAPI.php @@ -119,7 +119,7 @@ class ServerAPI{ "spawn-protection" => 16, "view-distance" => 10, "max-players" => 20, - "allow-flight" => false, + "allow-flight" => true, "spawn-animals" => true, "spawn-mobs" => true, "mobs-amount" => 50, @@ -138,7 +138,10 @@ class ServerAPI{ "enable-mob-ai" => true, "abort-reading-after-N-packets" => PocketMinecraftServer::$PACKET_READING_LIMIT ]); - + Entity::$allowFly = $this->getProperty("allow-flight", true); + if(!Entity::$allowFly){ + ConsoleAPI::warn("Fly checking is enabled! Players may experience issues with kicking while not flying!"); + } $this->parseProperties(); MobSpawner::$MOB_LIMIT = $this->getProperty("mobs-amount", 50); Entity::$allowedAI = $this->getProperty("enable-mob-ai", true); diff --git a/src/Player.php b/src/Player.php index 106bfe10..4f2a9aaf 100755 --- a/src/Player.php +++ b/src/Player.php @@ -285,6 +285,7 @@ class Player{ $this->lastCorrect = $pos; $this->entity->fallY = false; $this->entity->fallStart = false; + $this->entity->notOnGroundTicks = 0; $this->entity->setPosition($pos, $yaw, $pitch); $this->entity->resetSpeed(); $this->entity->updateLast(); diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 27034bfb..36cbe001 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -13,6 +13,7 @@ class Entity extends Position public $counter = 0; public $fallDistance = 0; public static $updateOnTick, $allowedAI; + public static $allowFly = true; public $canBeAttacked; public $moveTime, $lookTime, $idleTime, $knockbackTime = 0; public $attackTimeout = 0; @@ -105,6 +106,7 @@ class Entity extends Position public $inWeb; public $inLava; + public $notOnGroundTicks = 0; public $moveStrafing, $moveForward; @@ -769,14 +771,29 @@ class Entity extends Position $fireMaxY = floor($contractedCollisionBB->maxY + 1); $fireMaxZ = floor($contractedCollisionBB->maxZ + 1); + $bbbottom = $this->boundingBox->addCoord(0, -0.05, 0); + $bbbottom->minX = round($this->x, 3) - $this->radius; + $bbbottom->maxX = round($this->x, 3) + $this->radius; + $bbbottom->minZ = round($this->z, 3) - $this->radius; + $bbbottom->maxZ = round($this->z, 3) + $this->radius; + $handleFire = false; $handleCactus = false; - 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 - 1); $y < ceil($this->boundingBox->maxY); ++$y){ + $intersects = 0; + $id = $this->level->level->getBlockID($x, $y, $z); + $bounds = StaticBlock::$prealloc[$id]::getCollisionBoundingBoxes($this->level, $x, $y, $z, $this); + foreach($bounds as $bb){ + if($bbbottom->intersectsWith($bb)){ + ++$intersects; + } + } + + intersects: if($y <= floor($this->boundingBox->minY) && !$this->onGround){ - $this->onGround = StaticBlock::getIsSolid($this->level->level->getBlockID($x, $y, $z)); + if($intersects > 0) $this->onGround = count($bounds) > 0; }else{ $block = $this->level->level->getBlock($x, $y, $z); $id = $block[0]; @@ -794,6 +811,21 @@ class Entity extends Position } } + if($prevGroundState == $this->onGround && !$this->onGround){ + ++$this->notOnGroundTicks; + }else if($this->onGround){ + $this->notOnGroundTicks = 0; + } + + if($this->notOnGroundTicks > 80){ //~70 ticks is needed to reach from 127 to 0 + if(($this->player->gamemode & 1) != CREATIVE && !$this->player->blocked && $this->player->spawned){ //survival(0), adventure(2) + if(!Entity::$allowFly){ + $this->player->close("flying"); + } + } + } + + if($this->isOnLadder()){ $this->fallDistance = 0; $this->fallStart = $this->y; @@ -835,7 +867,7 @@ class Entity extends Position $this->counterUpdate(); - if($this->isPlayer() || $update){ + if($this->isPlayer()){ $this->updateMovement(); }