diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 4f7df34d5..25abc7afc 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -237,14 +237,10 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ /** @var Vector3|null */ protected $newPosition; - /** @var Vector3|null */ - public $speed = null; /** @var bool */ protected $isTeleporting = false; /** @var int */ protected $inAirTicks = 0; - /** @var int */ - protected $startAirTicks = 5; /** @var float */ protected $stepHeight = 0.6; /** @var bool */ @@ -499,9 +495,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ public function resetFallDistance() : void{ parent::resetFallDistance(); - if($this->inAirTicks !== 0){ - $this->startAirTicks = 5; - } $this->inAirTicks = 0; } @@ -1551,10 +1544,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } } } - - $this->speed = $to->subtract($from)->divide($tickDiff); - }elseif($distanceSquared == 0){ - $this->speed = new Vector3(0, 0, 0); } if($revert){ @@ -1580,10 +1569,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ if(parent::setMotion($motion)){ $this->broadcastMotion(); - if($this->motion->y > 0){ - $this->startAirTicks = (-log($this->gravity / ($this->gravity + $this->drag * $this->motion->y)) / $this->drag) * 2 + 5; - } - return true; } return false; @@ -1637,6 +1622,11 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ if($this->spawned){ $this->processMovement($tickDiff); $this->motion->x = $this->motion->y = $this->motion->z = 0; //TODO: HACK! (Fixes player knockback being messed up) + if($this->onGround){ + $this->inAirTicks = 0; + }else{ + $this->inAirTicks += $tickDiff; + } Timings::$timerEntityBaseTick->startTiming(); $this->entityBaseTick($tickDiff); @@ -1646,32 +1636,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ Timings::$playerCheckNearEntitiesTimer->startTiming(); $this->checkNearEntities(); Timings::$playerCheckNearEntitiesTimer->stopTiming(); - - if($this->speed !== null){ - if($this->onGround){ - if($this->inAirTicks !== 0){ - $this->startAirTicks = 5; - } - $this->inAirTicks = 0; - }else{ - if(!$this->allowFlight and $this->inAirTicks > 10 and !$this->isSleeping() and !$this->isImmobile()){ - $expectedVelocity = (-$this->gravity) / $this->drag - ((-$this->gravity) / $this->drag) * exp(-$this->drag * ($this->inAirTicks - $this->startAirTicks)); - $diff = ($this->speed->y - $expectedVelocity) ** 2; - - if(!$this->hasEffect(Effect::JUMP) and !$this->hasEffect(Effect::LEVITATION) and $diff > 0.6 and $expectedVelocity < $this->speed->y and !$this->server->getAllowFlight()){ - if($this->inAirTicks < 100){ - $this->setMotion(new Vector3(0, $expectedVelocity, 0)); - }elseif($this->kick($this->server->getLanguage()->translateString("kick.reason.cheat", ["%ability.flight"]))){ - $this->timings->stopTiming(); - - return false; - } - } - } - - $this->inAirTicks += $tickDiff; - } - } } } @@ -2436,7 +2400,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $handled = false; $isFlying = $packet->getFlag(AdventureSettingsPacket::FLYING); - if($isFlying and !$this->allowFlight and !$this->server->getAllowFlight()){ + if($isFlying and !$this->allowFlight){ $this->kick($this->server->getLanguage()->translateString("kick.reason.cheat", ["%ability.flight"])); return true; }elseif($isFlying !== $this->isFlying()){ diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index 1af22c6a1..1b9736764 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -559,10 +559,11 @@ class Server{ } /** + * @deprecated * @return bool */ public function getAllowFlight() : bool{ - return $this->getConfigBool("allow-flight", false); + return true; } /** @@ -1493,7 +1494,6 @@ class Server{ "announce-player-achievements" => true, "spawn-protection" => 16, "max-players" => 20, - "allow-flight" => false, "spawn-animals" => true, "spawn-mobs" => true, "gamemode" => 0, diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 533febadf..4871adf69 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -247,6 +247,11 @@ class Level implements ChunkManager, Metadatable{ /** @var bool */ private $closed = false; + /** @var BlockLightUpdate|null */ + private $blockLightUpdate = null; + /** @var SkyLightUpdate|null */ + private $skyLightUpdate = null; + public static function chunkHash(int $x, int $z) : int{ return (($x & 0xFFFFFFFF) << 32) | ($z & 0xFFFFFFFF); } @@ -758,6 +763,8 @@ class Level implements ChunkManager, Metadatable{ $this->tickChunks(); $this->timings->doTickTiles->stopTiming(); + $this->executeQueuedLightUpdates(); + if(count($this->changedBlocks) > 0){ if(count($this->players) > 0){ foreach($this->changedBlocks as $index => $blocks){ @@ -1414,22 +1421,21 @@ class Level implements ChunkManager, Metadatable{ $newHeightMap = $oldHeightMap; } - $update = new SkyLightUpdate($this); - + if($this->skyLightUpdate === null){ + $this->skyLightUpdate = new SkyLightUpdate($this); + } if($newHeightMap > $oldHeightMap){ //Heightmap increase, block placed, remove sky light for($i = $y; $i >= $oldHeightMap; --$i){ - $update->setAndUpdateLight($x, $i, $z, 0); //Remove all light beneath, adjacent recalculation will handle the rest. + $this->skyLightUpdate->setAndUpdateLight($x, $i, $z, 0); //Remove all light beneath, adjacent recalculation will handle the rest. } }elseif($newHeightMap < $oldHeightMap){ //Heightmap decrease, block changed or removed, add sky light for($i = $y; $i >= $newHeightMap; --$i){ - $update->setAndUpdateLight($x, $i, $z, 15); + $this->skyLightUpdate->setAndUpdateLight($x, $i, $z, 15); } }else{ //No heightmap change, block changed "underground" - $update->setAndUpdateLight($x, $y, $z, max(0, $this->getHighestAdjacentBlockSkyLight($x, $y, $z) - BlockFactory::$lightFilter[$sourceId])); + $this->skyLightUpdate->setAndUpdateLight($x, $y, $z, max(0, $this->getHighestAdjacentBlockSkyLight($x, $y, $z) - BlockFactory::$lightFilter[$sourceId])); } - $update->execute(); - $this->timings->doBlockSkyLightUpdates->stopTiming(); } @@ -1459,13 +1465,30 @@ class Level implements ChunkManager, Metadatable{ $id = $this->getBlockIdAt($x, $y, $z); $newLevel = max(BlockFactory::$light[$id], $this->getHighestAdjacentBlockLight($x, $y, $z) - BlockFactory::$lightFilter[$id]); - $update = new BlockLightUpdate($this); - $update->setAndUpdateLight($x, $y, $z, $newLevel); - $update->execute(); + if($this->blockLightUpdate === null){ + $this->blockLightUpdate = new BlockLightUpdate($this); + } + $this->blockLightUpdate->setAndUpdateLight($x, $y, $z, $newLevel); $this->timings->doBlockLightUpdates->stopTiming(); } + public function executeQueuedLightUpdates() : void{ + if($this->blockLightUpdate !== null){ + $this->timings->doBlockLightUpdates->startTiming(); + $this->blockLightUpdate->execute(); + $this->blockLightUpdate = null; + $this->timings->doBlockLightUpdates->stopTiming(); + } + + if($this->skyLightUpdate !== null){ + $this->timings->doBlockSkyLightUpdates->startTiming(); + $this->skyLightUpdate->execute(); + $this->skyLightUpdate = null; + $this->timings->doBlockSkyLightUpdates->stopTiming(); + } + } + /** * Sets on Vector3 the data from a Block object, * does block updates and puts the changes to the send queue.