PocketMine-MP 5.15.1 git-08c6e63aac45a450fe3b437616ee8aa2500e04e2
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
20use function count;
21
23 public const NETWORK_ID = ProtocolInfo::UPDATE_SUB_CHUNK_BLOCKS_PACKET;
24
25 private BlockPosition $baseBlockPosition;
26
28 private array $layer0Updates;
30 private array $layer1Updates;
31
37 public static function create(BlockPosition $baseBlockPosition, array $layer0Updates, array $layer1Updates) : self{
38 $result = new self;
39 $result->baseBlockPosition = $baseBlockPosition;
40 $result->layer0Updates = $layer0Updates;
41 $result->layer1Updates = $layer1Updates;
42 return $result;
43 }
44
45 public function getBaseBlockPosition() : BlockPosition{ return $this->baseBlockPosition; }
46
48 public function getLayer0Updates() : array{ return $this->layer0Updates; }
49
51 public function getLayer1Updates() : array{ return $this->layer1Updates; }
52
53 protected function decodePayload(PacketSerializer $in) : void{
54 $this->baseBlockPosition = $in->getBlockPosition();
55 $this->layer0Updates = [];
56 for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; ++$i){
57 $this->layer0Updates[] = UpdateSubChunkBlocksPacketEntry::read($in);
58 }
59 $this->layer1Updates = [];
60 for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; ++$i){
61 $this->layer1Updates[] = UpdateSubChunkBlocksPacketEntry::read($in);
62 }
63 }
64
65 protected function encodePayload(PacketSerializer $out) : void{
66 $out->putBlockPosition($this->baseBlockPosition);
67 $out->putUnsignedVarInt(count($this->layer0Updates));
68 foreach($this->layer0Updates as $update){
69 $update->write($out);
70 }
71 $out->putUnsignedVarInt(count($this->layer1Updates));
72 foreach($this->layer1Updates as $update){
73 $update->write($out);
74 }
75 }
76
77 public function handle(PacketHandlerInterface $handler) : bool{
78 return $handler->handleUpdateSubChunkBlocks($this);
79 }
80}
static create(BlockPosition $baseBlockPosition, array $layer0Updates, array $layer1Updates)