Fixed Entity & Player loaded chunk indexes

This commit is contained in:
Shoghi Cervantes 2014-06-23 11:57:47 +02:00
parent 496c004efc
commit fd4fc4ff94
2 changed files with 14 additions and 16 deletions

View File

@ -139,7 +139,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
protected $startAction = false; protected $startAction = false;
protected $sleeping = false; protected $sleeping = false;
protected $usedChunks = []; public $usedChunks = [];
protected $loadQueue = []; protected $loadQueue = [];
protected $chunkACK = []; protected $chunkACK = [];
/** @var \pocketmine\scheduler\TaskHandler */ /** @var \pocketmine\scheduler\TaskHandler */

View File

@ -225,7 +225,7 @@ abstract class Entity extends Position implements Metadatable{
* @param Player $player * @param Player $player
*/ */
public function spawnTo(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; $this->hasSpawned[$player->getID()] = $player;
} }
} }
@ -585,20 +585,18 @@ abstract class Entity extends Position implements Metadatable{
$this->chunk->removeEntity($this); $this->chunk->removeEntity($this);
$this->despawnFromAll(); $this->despawnFromAll();
if($this instanceof Player){ if($this instanceof Player){
foreach($this->chunksLoaded as $index => $Yndex){ foreach($this->usedChunks as $index => $d){
if($Yndex !== 0xff){ $X = null;
$X = null; $Z = null;
$Z = null; Level::getXZ($index, $X, $Z);
Level::getXZ($index, $X, $Z); foreach($this->getLevel()->getChunkEntities($X, $Z) as $entity){
foreach($this->getLevel()->getChunkEntities($X, $Z) as $entity){ $entity->despawnFrom($this);
$entity->despawnFrom($this);
}
$pk = new UnloadChunkPacket();
$pk->chunkX = $X;
$pk->chunkZ = $Z;
$this->dataPacket($pk);
} }
$pk = new UnloadChunkPacket();
$pk->chunkX = $X;
$pk->chunkZ = $Z;
$this->dataPacket($pk);
} }
$this->getLevel()->freeAllChunks($this); $this->getLevel()->freeAllChunks($this);
} }
@ -606,7 +604,7 @@ abstract class Entity extends Position implements Metadatable{
$this->setLevel($targetLevel, true); //Hard reference $this->setLevel($targetLevel, true); //Hard reference
$this->getLevel()->addEntity($this); $this->getLevel()->addEntity($this);
if($this instanceof Player){ if($this instanceof Player){
$this->chunksLoaded = []; $this->usedChunks = [];
$pk = new SetTimePacket(); $pk = new SetTimePacket();
$pk->time = $this->getLevel()->getTime(); $pk->time = $this->getLevel()->getTime();
$pk->started = $this->getLevel()->stopTime == false; $pk->started = $this->getLevel()->stopTime == false;