Skip to content

Commit

Permalink
updating packet and buffer code to match PM's changes in 6a64486f55e3…
Browse files Browse the repository at this point in the history
…7cbd7a0ce092335441d111fa77e4 and 2a3288c4f98aae9a685cd43226c42c18bb5c4e3f
  • Loading branch information
ColinHDev committed Mar 31, 2023
1 parent 004183f commit 5823a2e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\convert\RuntimeBlockMapping;
use pocketmine\network\mcpe\NetworkSession;
use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
use pocketmine\network\mcpe\protocol\UpdateBlockPacket;
use pocketmine\world\World;
use function array_filter;
Expand Down Expand Up @@ -71,6 +72,7 @@ public function onDataPacketSend(DataPacketSendEvent $event) : void {
return;
}
foreach($positionsToUpdatePerWorld as $worldName => $positionsToUpdate) {
/** @var NetworkSession[] $worldTargets */
$worldTargets = array_filter(
$applyableTargets,
static function(NetworkSession $target) use($worldName) : bool {
Expand All @@ -86,7 +88,7 @@ static function(Vector3|null $value) : bool {
$world = $applyableWorlds[$worldName];
foreach ($world->createBlockUpdatePackets($positionsToUpdate) as $packet) {
foreach($worldTargets as $target) {
$target->addToSendBuffer($packet);
$target->addToSendBuffer(NetworkSession::encodePacketTimed(PacketSerializer::encoder($target->getPacketSerializerContext()), $packet));
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/ColinHDev/ActualAntiXRay/tasks/ChunkRequestTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use pocketmine\network\mcpe\protocol\types\ChunkPosition;
use pocketmine\network\mcpe\serializer\ChunkSerializer;
use pocketmine\utils\AssumptionFailedError;
use pocketmine\utils\BinaryStream;
use pocketmine\world\ChunkLoader;
use pocketmine\world\format\Chunk;
use pocketmine\world\format\io\FastChunkSerializer;
Expand Down Expand Up @@ -170,7 +171,10 @@ public function onRun() : void {
$subCount = ChunkSerializer::getSubChunkCount($chunk) + ChunkSerializer::LOWER_PADDING_SIZE;
$encoderContext = new PacketSerializerContext(GlobalItemTypeDictionary::getInstance()->getDictionary());
$payload = ChunkSerializer::serializeFullChunk($chunk, RuntimeBlockMapping::getInstance(), $encoderContext, $this->tiles);
$this->setResult($this->compressor->compress(PacketBatch::fromPackets($encoderContext, LevelChunkPacket::create(new ChunkPosition($this->chunkX, $this->chunkZ), $subCount, false, null, $payload))->getBuffer()));

$stream = new BinaryStream();
PacketBatch::encodePackets($stream, $encoderContext, [LevelChunkPacket::create(new ChunkPosition($this->chunkX, $this->chunkZ), $subCount, false, null, $payload)]);
$this->setResult($this->compressor->compress($stream->getBuffer()));
}

private function isBlockReplaceable(SubChunkExplorer $explorer, Vector3 $vector, int $subChunkY) : bool {
Expand Down

0 comments on commit 5823a2e

Please sign in to comment.