Fixed chunk unload on level change

This commit is contained in:
Shoghi Cervantes 2014-06-15 00:07:21 +02:00
parent 6f36e9af24
commit cb1c4da4ea
2 changed files with 9 additions and 5 deletions

View File

@ -653,17 +653,15 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
foreach($lastChunk as $index => $Yndex){ foreach($lastChunk as $index => $Yndex){
if($Yndex === 0){
$X = null; $X = null;
$Z = null; $Z = null;
Level::getXZ($index, $X, $Z); Level::getXZ($index, $X, $Z);
if($Yndex === 0){
foreach($this->getLevel()->getChunkEntities($X, $Z) as $entity){ foreach($this->getLevel()->getChunkEntities($X, $Z) as $entity){
if($entity !== $this){ if($entity !== $this){
$entity->despawnFrom($this); $entity->despawnFrom($this);
} }
} }
}else{
$pk = new UnloadChunkPacket(); $pk = new UnloadChunkPacket();
$pk->chunkX = $X; $pk->chunkX = $X;
$pk->chunkZ = $Z; $pk->chunkZ = $Z;

View File

@ -49,6 +49,7 @@ use pocketmine\network\protocol\MovePlayerPacket;
use pocketmine\network\protocol\RemoveEntityPacket; use pocketmine\network\protocol\RemoveEntityPacket;
use pocketmine\network\protocol\SetEntityMotionPacket; use pocketmine\network\protocol\SetEntityMotionPacket;
use pocketmine\network\protocol\SetTimePacket; use pocketmine\network\protocol\SetTimePacket;
use pocketmine\network\protocol\UnloadChunkPacket;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\plugin\Plugin; use pocketmine\plugin\Plugin;
use pocketmine\Server; use pocketmine\Server;
@ -593,6 +594,11 @@ abstract class Entity extends Position implements Metadatable{
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);
} }
} }
$this->getLevel()->freeAllChunks($this); $this->getLevel()->freeAllChunks($this);