diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 480057a3de..bbb1a2d0a0 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1483,14 +1483,9 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->server->getLogger()->warning($this->getName() . " moved too fast, reverting movement"); $this->server->getLogger()->debug("Old position: " . $this->asVector3() . ", new position: " . $this->newPosition); $revert = true; - }else{ - $chunkX = $newPos->getFloorX() >> 4; - $chunkZ = $newPos->getFloorZ() >> 4; - - if(!$this->level->isChunkLoaded($chunkX, $chunkZ) or !$this->level->isChunkGenerated($chunkX, $chunkZ)){ - $revert = true; - $this->nextChunkOrderRun = 0; - } + }elseif(!$this->level->isInLoadedTerrain($newPos) or !$this->level->isChunkGenerated($newPos->getFloorX() >> 4, $newPos->getFloorZ() >> 4)){ + $revert = true; + $this->nextChunkOrderRun = 0; } if(!$revert and $distanceSquared != 0){ diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 14a777381f..0816d08513 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -2406,6 +2406,17 @@ class Level implements ChunkManager, Metadatable{ return $this->getChunk($x >> 4, $z >> 4, true)->getHighestBlockAt($x & 0x0f, $z & 0x0f); } + /** + * Returns whether the given position is in a loaded area of terrain. + * + * @param Vector3 $pos + * + * @return bool + */ + public function isInLoadedTerrain(Vector3 $pos) : bool{ + return $this->isChunkLoaded($pos->getFloorX() >> 4, $pos->getFloorZ() >> 4); + } + /** * @param int $x * @param int $z diff --git a/src/pocketmine/tile/Chest.php b/src/pocketmine/tile/Chest.php index beb6d1214a..6c0dd4f192 100644 --- a/src/pocketmine/tile/Chest.php +++ b/src/pocketmine/tile/Chest.php @@ -26,6 +26,7 @@ namespace pocketmine\tile; use pocketmine\inventory\ChestInventory; use pocketmine\inventory\DoubleChestInventory; use pocketmine\inventory\InventoryHolder; +use pocketmine\math\Vector3; use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\IntTag; @@ -103,7 +104,7 @@ class Chest extends Spawnable implements InventoryHolder, Container, Nameable{ } protected function checkPairing(){ - if($this->isPaired() and !$this->getLevel()->isChunkLoaded($this->pairX >> 4, $this->pairZ >> 4)){ + if($this->isPaired() and !$this->getLevel()->isInLoadedTerrain(new Vector3($this->pairX, $this->y, $this->pairZ))){ //paired to a tile in an unloaded chunk $this->doubleInventory = null;