PocketMine-MP 5.23.3 git-f7687af337d001ddbcc47b8e773f014a33faa662
Loading...
Searching...
No Matches
ItemStackRequest.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
20use function count;
21
22final class ItemStackRequest{
28 public function __construct(
29 private int $requestId,
30 private array $actions,
31 private array $filterStrings,
32 private int $filterStringCause
33 ){}
34
35 public function getRequestId() : int{ return $this->requestId; }
36
38 public function getActions() : array{ return $this->actions; }
39
44 public function getFilterStrings() : array{ return $this->filterStrings; }
45
46 public function getFilterStringCause() : int{ return $this->filterStringCause; }
47
52 private static function readAction(PacketSerializer $in, int $typeId) : ItemStackRequestAction{
53 return match($typeId){
54 TakeStackRequestAction::ID => TakeStackRequestAction::read($in),
55 PlaceStackRequestAction::ID => PlaceStackRequestAction::read($in),
56 SwapStackRequestAction::ID => SwapStackRequestAction::read($in),
57 DropStackRequestAction::ID => DropStackRequestAction::read($in),
58 DestroyStackRequestAction::ID => DestroyStackRequestAction::read($in),
59 CraftingConsumeInputStackRequestAction::ID => CraftingConsumeInputStackRequestAction::read($in),
60 CraftingCreateSpecificResultStackRequestAction::ID => CraftingCreateSpecificResultStackRequestAction::read($in),
61 LabTableCombineStackRequestAction::ID => LabTableCombineStackRequestAction::read($in),
62 BeaconPaymentStackRequestAction::ID => BeaconPaymentStackRequestAction::read($in),
63 MineBlockStackRequestAction::ID => MineBlockStackRequestAction::read($in),
64 CraftRecipeStackRequestAction::ID => CraftRecipeStackRequestAction::read($in),
65 CraftRecipeAutoStackRequestAction::ID => CraftRecipeAutoStackRequestAction::read($in),
66 CreativeCreateStackRequestAction::ID => CreativeCreateStackRequestAction::read($in),
67 CraftRecipeOptionalStackRequestAction::ID => CraftRecipeOptionalStackRequestAction::read($in),
68 GrindstoneStackRequestAction::ID => GrindstoneStackRequestAction::read($in),
69 LoomStackRequestAction::ID => LoomStackRequestAction::read($in),
70 DeprecatedCraftingNonImplementedStackRequestAction::ID => DeprecatedCraftingNonImplementedStackRequestAction::read($in),
71 DeprecatedCraftingResultsStackRequestAction::ID => DeprecatedCraftingResultsStackRequestAction::read($in),
72 default => throw new PacketDecodeException("Unhandled item stack request action type $typeId"),
73 };
74 }
75
76 public static function read(PacketSerializer $in) : self{
77 $requestId = $in->readItemStackRequestId();
78 $actions = [];
79 for($i = 0, $len = $in->getUnsignedVarInt(); $i < $len; ++$i){
80 $typeId = $in->getByte();
81 $actions[] = self::readAction($in, $typeId);
82 }
83 $filterStrings = [];
84 for($i = 0, $len = $in->getUnsignedVarInt(); $i < $len; ++$i){
85 $filterStrings[] = $in->getString();
86 }
87 $filterStringCause = $in->getLInt();
88 return new self($requestId, $actions, $filterStrings, $filterStringCause);
89 }
90
91 public function write(PacketSerializer $out) : void{
92 $out->writeItemStackRequestId($this->requestId);
93 $out->putUnsignedVarInt(count($this->actions));
94 foreach($this->actions as $action){
95 $out->putByte($action->getTypeId());
96 $action->write($out);
97 }
98 $out->putUnsignedVarInt(count($this->filterStrings));
99 foreach($this->filterStrings as $string){
100 $out->putString($string);
101 }
102 $out->putLInt($this->filterStringCause);
103 }
104}
__construct(private int $requestId, private array $actions, private array $filterStrings, private int $filterStringCause)