PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
UpdateSubChunkBlocksPacket.php
1<?php
2
3/*
4 * This file is part of BedrockProtocol.
5 * Copyright (C) 2014-2022 PocketMine Team <https://github.com/pmmp/BedrockProtocol>
6 *
7 * BedrockProtocol is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 */
12
13declare(strict_types=1);
14
15namespace pocketmine\network\mcpe\protocol;
16
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\VarInt;
23use function count;
24
26 public const NETWORK_ID = ProtocolInfo::UPDATE_SUB_CHUNK_BLOCKS_PACKET;
27
28 private BlockPosition $baseBlockPosition;
29
31 private array $layer0Updates;
33 private array $layer1Updates;
34
40 public static function create(BlockPosition $baseBlockPosition, array $layer0Updates, array $layer1Updates) : self{
41 $result = new self;
42 $result->baseBlockPosition = $baseBlockPosition;
43 $result->layer0Updates = $layer0Updates;
44 $result->layer1Updates = $layer1Updates;
45 return $result;
46 }
47
48 public function getBaseBlockPosition() : BlockPosition{ return $this->baseBlockPosition; }
49
51 public function getLayer0Updates() : array{ return $this->layer0Updates; }
52
54 public function getLayer1Updates() : array{ return $this->layer1Updates; }
55
56 protected function decodePayload(ByteBufferReader $in) : void{
57 $this->baseBlockPosition = CommonTypes::getBlockPosition($in);
58 $this->layer0Updates = [];
59 for($i = 0, $count = VarInt::readUnsignedInt($in); $i < $count; ++$i){
60 $this->layer0Updates[] = UpdateSubChunkBlocksPacketEntry::read($in);
61 }
62 $this->layer1Updates = [];
63 for($i = 0, $count = VarInt::readUnsignedInt($in); $i < $count; ++$i){
64 $this->layer1Updates[] = UpdateSubChunkBlocksPacketEntry::read($in);
65 }
66 }
67
68 protected function encodePayload(ByteBufferWriter $out) : void{
69 CommonTypes::putBlockPosition($out, $this->baseBlockPosition);
70 VarInt::writeUnsignedInt($out, count($this->layer0Updates));
71 foreach($this->layer0Updates as $update){
72 $update->write($out);
73 }
74 VarInt::writeUnsignedInt($out, count($this->layer1Updates));
75 foreach($this->layer1Updates as $update){
76 $update->write($out);
77 }
78 }
79
80 public function handle(PacketHandlerInterface $handler) : bool{
81 return $handler->handleUpdateSubChunkBlocks($this);
82 }
83}
static create(BlockPosition $baseBlockPosition, array $layer0Updates, array $layer1Updates)