PocketMine-MP 5.23.3 git-f7687af337d001ddbcc47b8e773f014a33faa662
Loading...
Searching...
No Matches
NetworkInventoryAction.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;
16
20
22 public const SOURCE_CONTAINER = 0;
23
24 public const SOURCE_WORLD = 2; //drop/pickup item entity
25 public const SOURCE_CREATIVE = 3;
26 public const SOURCE_TODO = 99999;
27
37 public const SOURCE_TYPE_CRAFTING_RESULT = -4;
38 public const SOURCE_TYPE_CRAFTING_USE_INGREDIENT = -5;
39
40 public const SOURCE_TYPE_ANVIL_RESULT = -12;
41 public const SOURCE_TYPE_ANVIL_OUTPUT = -13;
42
43 public const SOURCE_TYPE_ENCHANT_OUTPUT = -17;
44
45 public const SOURCE_TYPE_TRADING_INPUT_1 = -20;
46 public const SOURCE_TYPE_TRADING_INPUT_2 = -21;
47 public const SOURCE_TYPE_TRADING_USE_INPUTS = -22;
48 public const SOURCE_TYPE_TRADING_OUTPUT = -23;
49
50 public const SOURCE_TYPE_BEACON = -24;
51
52 public const ACTION_MAGIC_SLOT_CREATIVE_DELETE_ITEM = 0;
53 public const ACTION_MAGIC_SLOT_CREATIVE_CREATE_ITEM = 1;
54
55 public const ACTION_MAGIC_SLOT_DROP_ITEM = 0;
56 public const ACTION_MAGIC_SLOT_PICKUP_ITEM = 1;
57
58 public int $sourceType;
59 public int $windowId;
60 public int $sourceFlags = 0;
61 public int $inventorySlot;
62 public ItemStackWrapper $oldItem;
63 public ItemStackWrapper $newItem;
64
71 public function read(PacketSerializer $packet) : NetworkInventoryAction{
72 $this->sourceType = $packet->getUnsignedVarInt();
73
74 switch($this->sourceType){
75 case self::SOURCE_CONTAINER:
76 $this->windowId = $packet->getVarInt();
77 break;
78 case self::SOURCE_WORLD:
79 $this->sourceFlags = $packet->getUnsignedVarInt();
80 break;
81 case self::SOURCE_CREATIVE:
82 break;
83 case self::SOURCE_TODO:
84 $this->windowId = $packet->getVarInt();
85 break;
86 default:
87 throw new PacketDecodeException("Unknown inventory action source type $this->sourceType");
88 }
89
90 $this->inventorySlot = $packet->getUnsignedVarInt();
91 $this->oldItem = $packet->getItemStackWrapper();
92 $this->newItem = $packet->getItemStackWrapper();
93
94 return $this;
95 }
96
100 public function write(PacketSerializer $packet) : void{
101 $packet->putUnsignedVarInt($this->sourceType);
102
103 switch($this->sourceType){
104 case self::SOURCE_CONTAINER:
105 $packet->putVarInt($this->windowId);
106 break;
107 case self::SOURCE_WORLD:
108 $packet->putUnsignedVarInt($this->sourceFlags);
109 break;
110 case self::SOURCE_CREATIVE:
111 break;
112 case self::SOURCE_TODO:
113 $packet->putVarInt($this->windowId);
114 break;
115 default:
116 throw new \InvalidArgumentException("Unknown inventory action source type $this->sourceType");
117 }
118
119 $packet->putUnsignedVarInt($this->inventorySlot);
120 $packet->putItemStackWrapper($this->oldItem);
121 $packet->putItemStackWrapper($this->newItem);
122 }
123}