PocketMine-MP 5.21.2 git-09bf203267aca9b83a09640e17bfac0fc7b58ff8
Loading...
Searching...
No Matches
TrimDataPacket.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::TRIM_DATA_PACKET;
24
29 private array $trimPatterns;
34 private array $trimMaterials;
35
43 public static function create(array $trimPatterns, array $trimMaterials) : self{
44 $result = new self;
45 $result->trimPatterns = $trimPatterns;
46 $result->trimMaterials = $trimMaterials;
47 return $result;
48 }
49
54 public function getTrimPatterns() : array{ return $this->trimPatterns; }
55
60 public function getTrimMaterials() : array{ return $this->trimMaterials; }
61
62 protected function decodePayload(PacketSerializer $in) : void{
63 $this->trimPatterns = [];
64 for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; ++$i){
65 $this->trimPatterns[] = TrimPattern::read($in);
66 }
67 $this->trimMaterials = [];
68 for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; ++$i){
69 $this->trimMaterials[] = TrimMaterial::read($in);
70 }
71 }
72
73 protected function encodePayload(PacketSerializer $out) : void{
74 $out->putUnsignedVarInt(count($this->trimPatterns));
75 foreach($this->trimPatterns as $trimPattern){
76 $trimPattern->write($out);
77 }
78 $out->putUnsignedVarInt(count($this->trimMaterials));
79 foreach($this->trimMaterials as $trimMaterial){
80 $trimMaterial->write($out);
81 }
82 }
83
84 public function handle(PacketHandlerInterface $handler) : bool{
85 return $handler->handleTrimData($this);
86 }
87}
static create(array $trimPatterns, array $trimMaterials)
handle(PacketHandlerInterface $handler)