PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
DeprecatedCraftingResultsStackRequestAction.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\types\inventory\stackrequest;
16
17use pmmp\encoding\Byte;
18use pmmp\encoding\ByteBufferReader;
19use pmmp\encoding\ByteBufferWriter;
20use pmmp\encoding\VarInt;
22use pocketmine\network\mcpe\protocol\types\GetTypeIdFromConstTrait;
24use function count;
25
31 use GetTypeIdFromConstTrait;
32
33 public const ID = ItemStackRequestActionType::CRAFTING_RESULTS_DEPRECATED_ASK_TY_LAING;
34
38 public function __construct(
39 private array $results,
40 private int $iterations
41 ){}
42
44 public function getResults() : array{ return $this->results; }
45
46 public function getIterations() : int{ return $this->iterations; }
47
48 public static function read(ByteBufferReader $in) : self{
49 $results = [];
50 for($i = 0, $len = VarInt::readUnsignedInt($in); $i < $len; ++$i){
51 $results[] = CommonTypes::getItemStackWithoutStackId($in);
52 }
53 $iterations = Byte::readUnsigned($in);
54 return new self($results, $iterations);
55 }
56
57 public function write(ByteBufferWriter $out) : void{
58 VarInt::writeUnsignedInt($out, count($this->results));
59 foreach($this->results as $result){
60 CommonTypes::putItemStackWithoutStackId($out, $result);
61 }
62 Byte::writeUnsigned($out, $this->iterations);
63 }
64}