From c4b03ce13c2e1820b41e05a38a80b812495cf702 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Sat, 9 Dec 2023 20:53:07 +0300 Subject: [PATCH] fixed freeAllChunks --- src/Player.php | 11 +---------- src/entity/Entity.php | 4 ++-- src/world/Level.php | 32 ++++++++++++++++---------------- 3 files changed, 19 insertions(+), 28 deletions(-) diff --git a/src/Player.php b/src/Player.php index 47a30c5e..97d45111 100755 --- a/src/Player.php +++ b/src/Player.php @@ -569,6 +569,7 @@ class Player{ $z = $Z << 4; $this->level->useChunk($X, $Z, $this); $this->chunksLoaded["$X:$Z"] = true; + $pk = new FullChunkDataPacket; $pk->chunkX = $X; $pk->chunkZ = $Z; @@ -1132,16 +1133,6 @@ class Player{ if(isset($this->received[$p->messageIndex])){ continue; } - switch($p->pid()){ - case 0x01: - case ProtocolInfo::PING_PACKET: - case ProtocolInfo::PONG_PACKET: - case ProtocolInfo::MOVE_PLAYER_PACKET: - case ProtocolInfo::REQUEST_CHUNK_PACKET: - case ProtocolInfo::ANIMATE_PACKET: - case ProtocolInfo::SET_HEALTH_PACKET: - break; - } } $this->received[$p->messageIndex] = true; } diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 4d26764c..9a2eb1e5 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -408,8 +408,8 @@ class Entity extends Position } else{ $hasUpdate = true; } - if(($this->player instanceof Player) and ($this->player->gamemode & 0x01) === CREATIVE){ // Remove fire effects in next tick - $this->fire = 1; + if(($this->player instanceof Player) and ($this->player->gamemode & 0x01) === CREATIVE){ + $this->fire = 0; } } diff --git a/src/world/Level.php b/src/world/Level.php index 27b2aa27..dc26073d 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -85,19 +85,22 @@ class Level{ } public function fastSetBlockUpdate($x, $y, $z, $id, $meta, $updateBlocksAround = false){ + $x = (int)$x; + $y = (int)$y; + $z = (int)$z; $this->level->setBlock($x, $y, $z, $id, $meta); - $pk = new UpdateBlockPacket; - $pk->x = $x; - $pk->y = $y; - $pk->z = $z; - $pk->block = $id; - $pk->meta = $meta; - $this->server->api->player->broadcastPacket($this->players, $pk); //TODO broadcast in another queue? + $this->sendBlockToAll($x, $y, $z); if($updateBlocksAround){ $this->server->api->block->blockUpdateAround(new Position($x, $y, $z, $this), BLOCK_UPDATE_NORMAL, 1); } } + public function sendBlockToAll($x, $y, $z){ + foreach($this->players as $p){ + $this->resendBlocksToPlayers[$p->CID]["$x.$y.$z"] = true; + } + } + public function __destruct(){ if(isset($this->level)){ $this->save(false, false); @@ -312,8 +315,11 @@ class Level{ } public function freeAllChunks(Player $player){ - foreach($this->usedChunks as $i => $c){ - unset($this->usedChunks[$i][$player->CID]); + foreach($player->chunksLoaded as $chunk => $c){ + $xz = explode(":", $chunk); + $x = $xz[0]; + $z = $xz[1]; + $player->stopUsingChunk($x, $z); } } @@ -517,13 +523,7 @@ class Level{ } $block->position($pos); if($direct === true){ - $pk = new UpdateBlockPacket; - $pk->x = $pos->x; - $pk->y = $pos->y; - $pk->z = $pos->z; - $pk->block = $block->getID(); - $pk->meta = $block->getMetadata(); - $this->server->api->player->broadcastPacket($this->players, $pk); + $this->sendBlockToAll($pos->x, $pos->y, $pos->z); }else{ $i = ($pos->x >> 4) . ":" . ($pos->y >> 4) . ":" . ($pos->z >> 4); if(!isset($this->changedBlocks[$i])){