PocketMine-MP 5.42.1 git-443151900a14fe9dc682cbf786fa441be1294fab
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 protected function decodePayload(ByteBufferReader $in) : void{
41 $this->payload = match(VarInt::readUnsignedInt($in)){
42 AttributeUpdateLayers::ID => AttributeUpdateLayers::read($in),
43 AttributeUpdateLayerSettings::ID => AttributeUpdateLayerSettings::read($in),
44 AttributesUpdateEnvironment::ID => AttributesUpdateEnvironment::read($in),
45 AttributesRemoveEnvironment::ID => AttributesRemoveEnvironment::read($in),
46 default => throw new PacketDecodeException("Unknown ClientboundAttributeLayerSync type"),
47 };
48 }
49
50 protected function encodePayload(ByteBufferWriter $out) : void{
51 VarInt::writeUnsignedInt($out, $this->payload->getTypeId());
52 $this->payload->write($out);
53 }
54
55 public function handle(PacketHandlerInterface $handler) : bool{
56 return $handler->handleClientboundAttributeLayerSync($this);
57 }
58}