From fd4fc4ff9488c9458dde781f3a5ded63c459b14c Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 23 Jun 2014 11:57:47 +0200 Subject: [PATCH] Fixed Entity & Player loaded chunk indexes --- src/pocketmine/Player.php | 2 +- src/pocketmine/entity/Entity.php | 28 +++++++++++++--------------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 81cde18d4..8620c06c9 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -139,7 +139,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ protected $startAction = false; protected $sleeping = false; - protected $usedChunks = []; + public $usedChunks = []; protected $loadQueue = []; protected $chunkACK = []; /** @var \pocketmine\scheduler\TaskHandler */ diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 4ab604613..3bb024f7a 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -225,7 +225,7 @@ abstract class Entity extends Position implements Metadatable{ * @param Player $player */ public function spawnTo(Player $player){ - if(!isset($this->hasSpawned[$player->getID()]) and $player->chunksLoaded[Level::chunkHash($this->chunk->getX(), $this->chunk->getZ())] !== 0xff){ + if(!isset($this->hasSpawned[$player->getID()]) and isset($player->usedChunks[Level::chunkHash($this->chunk->getX(), $this->chunk->getZ())])){ $this->hasSpawned[$player->getID()] = $player; } } @@ -585,20 +585,18 @@ abstract class Entity extends Position implements Metadatable{ $this->chunk->removeEntity($this); $this->despawnFromAll(); if($this instanceof Player){ - foreach($this->chunksLoaded as $index => $Yndex){ - if($Yndex !== 0xff){ - $X = null; - $Z = null; - Level::getXZ($index, $X, $Z); - foreach($this->getLevel()->getChunkEntities($X, $Z) as $entity){ - $entity->despawnFrom($this); - } - - $pk = new UnloadChunkPacket(); - $pk->chunkX = $X; - $pk->chunkZ = $Z; - $this->dataPacket($pk); + foreach($this->usedChunks as $index => $d){ + $X = null; + $Z = null; + Level::getXZ($index, $X, $Z); + foreach($this->getLevel()->getChunkEntities($X, $Z) as $entity){ + $entity->despawnFrom($this); } + + $pk = new UnloadChunkPacket(); + $pk->chunkX = $X; + $pk->chunkZ = $Z; + $this->dataPacket($pk); } $this->getLevel()->freeAllChunks($this); } @@ -606,7 +604,7 @@ abstract class Entity extends Position implements Metadatable{ $this->setLevel($targetLevel, true); //Hard reference $this->getLevel()->addEntity($this); if($this instanceof Player){ - $this->chunksLoaded = []; + $this->usedChunks = []; $pk = new SetTimePacket(); $pk->time = $this->getLevel()->getTime(); $pk->started = $this->getLevel()->stopTime == false;