PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
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
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\VarInt;
22use function count;
23
25 public const NETWORK_ID = ProtocolInfo::TRIM_DATA_PACKET;
26
31 private array $trimPatterns;
36 private array $trimMaterials;
37
45 public static function create(array $trimPatterns, array $trimMaterials) : self{
46 $result = new self;
47 $result->trimPatterns = $trimPatterns;
48 $result->trimMaterials = $trimMaterials;
49 return $result;
50 }
51
56 public function getTrimPatterns() : array{ return $this->trimPatterns; }
57
62 public function getTrimMaterials() : array{ return $this->trimMaterials; }
63
64 protected function decodePayload(ByteBufferReader $in) : void{
65 $this->trimPatterns = [];
66 for($i = 0, $count = VarInt::readUnsignedInt($in); $i < $count; ++$i){
67 $this->trimPatterns[] = TrimPattern::read($in);
68 }
69 $this->trimMaterials = [];
70 for($i = 0, $count = VarInt::readUnsignedInt($in); $i < $count; ++$i){
71 $this->trimMaterials[] = TrimMaterial::read($in);
72 }
73 }
74
75 protected function encodePayload(ByteBufferWriter $out) : void{
76 VarInt::writeUnsignedInt($out, count($this->trimPatterns));
77 foreach($this->trimPatterns as $trimPattern){
78 $trimPattern->write($out);
79 }
80 VarInt::writeUnsignedInt($out, count($this->trimMaterials));
81 foreach($this->trimMaterials as $trimMaterial){
82 $trimMaterial->write($out);
83 }
84 }
85
86 public function handle(PacketHandlerInterface $handler) : bool{
87 return $handler->handleTrimData($this);
88 }
89}
static create(array $trimPatterns, array $trimMaterials)
handle(PacketHandlerInterface $handler)