diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index bb95afd2e..0f6448e5c 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -557,33 +557,38 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ return; } - $index = key($this->loadQueue); - $distance = @$this->loadQueue[$index]; - - if($index === null or $distance === null){ + if(count($this->loadQueue) === 0){ $this->chunkLoadTask->setNextRun($this->chunkLoadTask->getNextRun() + 30); - return; - } - $X = null; - $Z = null; - Level::getXZ($index, $X, $Z); - if(!$this->getLevel()->isChunkPopulated($X, $Z)){ - return; - } - unset($this->loadQueue[$index]); - $this->usedChunks[$index] = [false, 0]; + }else{ + $count = 0; + $limit = (int) $this->server->getProperty("chunk-sending.per-tick", 1); + foreach($this->loadQueue as $index => $distance){ + if($count >= $limit){ + break; + } + ++$count; + $X = null; + $Z = null; + Level::getXZ($index, $X, $Z); + if(!$this->getLevel()->isChunkPopulated($X, $Z)){ + $this->chunkLoadTask->setNextRun($this->chunkLoadTask->getNextRun() + 30); + return; + } + unset($this->loadQueue[$index]); + $this->usedChunks[$index] = [false, 0]; - $this->getLevel()->useChunk($X, $Z, $this); - $pk = new FullChunkDataPacket; - $pk->chunkX = $X; - $pk->chunkZ = $Z; - $pk->data = $this->getLevel()->getNetworkChunk($X, $Z, 0xff); - $cnt = $this->dataPacket($pk, true); - - if($cnt === false or $cnt === true){ - return; + $this->getLevel()->useChunk($X, $Z, $this); + $pk = new FullChunkDataPacket; + $pk->chunkX = $X; + $pk->chunkZ = $Z; + $pk->data = $this->getLevel()->getNetworkChunk($X, $Z, 0xff); + $cnt = $this->dataPacket($pk, true); + if($cnt === false or $cnt === true){ + return; + } + $this->chunkACK[$cnt] = $index; + } } - $this->chunkACK[$cnt] = $index; if(count($this->usedChunks) >= 56 and $this->spawned === false){ $spawned = 0; @@ -597,25 +602,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ return; } - foreach($this->usedChunks as $index => $d){ - if($d[0] === false){ - continue; - } - $X = null; - $Z = null; - Level::getXZ($index, $X, $Z); - foreach($this->getLevel()->getChunkEntities($X, $Z) as $entity){ - if($entity !== $this){ - $entity->spawnTo($this); - } - } - foreach($this->getLevel()->getChunkTiles($X, $Z) as $tile){ - if($tile instanceof Spawnable){ - $tile->spawnTo($this); - } - } - } - //TODO //$this->heal($this->data->get("health"), "spawn", true); $this->spawned = true; @@ -633,6 +619,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $pos = new Position($this->x, $this->y, $this->z, $this->getLevel()); $pos = $this->getLevel()->getSafeSpawn($pos); + $this->server->getPluginManager()->callEvent($ev = new PlayerRespawnEvent($this, $pos)); $this->teleport($ev->getRespawnPosition()); @@ -1235,7 +1222,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->orderChunks(); $this->tasks[] = $this->server->getScheduler()->scheduleDelayedRepeatingTask(new CallbackTask(array($this, "orderChunks")), 10, 40); $this->sendNextChunk(); - $this->tasks[] = $this->chunkLoadTask = $this->server->getScheduler()->scheduleRepeatingTask(new CallbackTask(array($this, "sendNextChunk")), MAX_CHUNK_RATE); + $this->tasks[] = $this->chunkLoadTask = $this->server->getScheduler()->scheduleRepeatingTask(new CallbackTask(array($this, "sendNextChunk")), 1); $pk = new ReadyPacket(); $pk->x = $this->x; diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index f127ce761..28c32fd5f 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -1388,7 +1388,6 @@ class Server{ $this->logger->setLogDebug(\pocketmine\DEBUG > 1); } define("ADVANCED_CACHE", $this->getProperty("settings.advanced-cache", false)); - define("MAX_CHUNK_RATE", ceil(20 / $this->getProperty("chunk-sending.per-second", 20))); if(ADVANCED_CACHE == true){ $this->logger->info("Advanced cache enabled"); } diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index d24fe1978..ef1be8c62 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -931,7 +931,7 @@ abstract class Entity extends Position implements Metadatable{ $this->airTicks = 300; $this->fallDistance = 0; $this->orderChunks(); - $this->sendNextChunk(); + $this->chunkLoadTask->setNextRun(0); $this->forceMovement = $pos; $pk = new MovePlayerPacket; diff --git a/src/pocketmine/level/format/anvil/ChunkSection.php b/src/pocketmine/level/format/anvil/ChunkSection.php index 94ec48d80..6ba904328 100644 --- a/src/pocketmine/level/format/anvil/ChunkSection.php +++ b/src/pocketmine/level/format/anvil/ChunkSection.php @@ -150,11 +150,11 @@ class ChunkSection implements \pocketmine\level\format\ChunkSection{ $column = ""; if(($x & 1) === 0){ for($y = 0; $y < 16; $y += 2){ - $column .= chr((ord($this->data{($y << 7) + $i}) & 0x0f) | ((ord($this->data{(($y + 1) << 7) + $i}) & 0x0f) << 4)); + $column .= ($this->data{($y << 7) + $i} & "\x0f") | chr((ord($this->data{(($y + 1) << 7) + $i}) & 0x0f) << 4); } }else{ for($y = 0; $y < 16; $y += 2){ - $column .= chr(((ord($this->data{($y << 7) + $i}) & 0xf0) >> 4) | (ord($this->data{(($y + 1) << 7) + $i}) & 0xf0)); + $column .= chr((ord($this->data{($y << 7) + $i}) & 0xf0) >> 4) | ($this->data{(($y + 1) << 7) + $i} & "\xf0"); } } @@ -164,8 +164,14 @@ class ChunkSection implements \pocketmine\level\format\ChunkSection{ public function getBlockSkyLightColumn($x, $z){ $i = ($z << 3) + ($x >> 1); $column = ""; - for($y = 0; $y < 16; $y += 2){ - $column .= chr((ord($this->skyLight{($y << 7) + $i}) & 0x0f) | ((ord($this->skyLight{(($y + 1) << 7) + $i}) & 0x0f) << 4)); + if(($x & 1) === 0){ + for($y = 0; $y < 16; $y += 2){ + $column .= ($this->skyLight{($y << 7) + $i} & "\x0f") | chr((ord($this->skyLight{(($y + 1) << 7) + $i}) & 0x0f) << 4); + } + }else{ + for($y = 0; $y < 16; $y += 2){ + $column .= chr((ord($this->skyLight{($y << 7) + $i}) & 0xf0) >> 4) | ($this->skyLight{(($y + 1) << 7) + $i} & "\xf0"); + } } return $column; @@ -174,8 +180,14 @@ class ChunkSection implements \pocketmine\level\format\ChunkSection{ public function getBlockLightColumn($x, $z){ $i = ($z << 3) + ($x >> 1); $column = ""; - for($y = 0; $y < 16; $y += 2){ - $column .= chr((ord($this->blockLight{($y << 7) + $i}) & 0x0f) | ((ord($this->blockLight{(($y + 1) << 7) + $i}) & 0x0f) << 4)); + if(($x & 1) === 0){ + for($y = 0; $y < 16; $y += 2){ + $column .= ($this->blockLight{($y << 7) + $i} & "\x0f") | chr((ord($this->blockLight{(($y + 1) << 7) + $i}) & 0x0f) << 4); + } + }else{ + for($y = 0; $y < 16; $y += 2){ + $column .= chr((ord($this->blockLight{($y << 7) + $i}) & 0xf0) >> 4) | ($this->blockLight{(($y + 1) << 7) + $i} & "\xf0"); + } } return $column; diff --git a/src/pocketmine/resources/pocketmine.yml b/src/pocketmine/resources/pocketmine.yml index c42d196ed..5566ad3bd 100644 --- a/src/pocketmine/resources/pocketmine.yml +++ b/src/pocketmine/resources/pocketmine.yml @@ -16,7 +16,7 @@ debug: commands: false chunk-sending: - per-second: 20 + per-tick: 1 compression-level: 7 chunk-gc: