PocketMine-MP 5.42.2 git-88c18cd9cf7fc37bd5261e6f29ed6041bfe776f1
Loading...
Searching...
No Matches
ClientboundAttributeLayerSyncPacket.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;
25
27 public const NETWORK_ID = ProtocolInfo::CLIENTBOUND_ATTRIBUTE_LAYER_SYNC_PACKET;
28
29 private AttributeLayerSyncPayload $payload;
30
34 public static function create(AttributeLayerSyncPayload $payload) : self{
35 $result = new self;
36 $result->payload = $payload;
37 return $result;
38 }
39
40 public function getPayload() : AttributeLayerSyncPayload{ return $this->payload; }
41
42 protected function decodePayload(ByteBufferReader $in) : void{
43 $this->payload = match(VarInt::readUnsignedInt($in)){
44 AttributeUpdateLayers::ID => AttributeUpdateLayers::read($in),
45 AttributeUpdateLayerSettings::ID => AttributeUpdateLayerSettings::read($in),
46 AttributesUpdateEnvironment::ID => AttributesUpdateEnvironment::read($in),
47 AttributesRemoveEnvironment::ID => AttributesRemoveEnvironment::read($in),
48 default => throw new PacketDecodeException("Unknown ClientboundAttributeLayerSync type"),
49 };
50 }
51
52 protected function encodePayload(ByteBufferWriter $out) : void{
53 VarInt::writeUnsignedInt($out, $this->payload->getTypeId());
54 $this->payload->write($out);
55 }
56
57 public function handle(PacketHandlerInterface $handler) : bool{
58 return $handler->handleClientboundAttributeLayerSync($this);
59 }
60}