26 public const SOURCE_CONTAINER = 0;
28 public const SOURCE_GLOBAL = 1;
29 public const SOURCE_WORLD = 2;
30 public const SOURCE_CREATIVE = 3;
31 public const SOURCE_TODO = 99999;
43 public const SOURCE_TYPE_CRAFTING_USE_INGREDIENT = -5;
45 public const SOURCE_TYPE_ANVIL_RESULT = -12;
46 public const SOURCE_TYPE_ANVIL_OUTPUT = -13;
48 public const SOURCE_TYPE_ENCHANT_OUTPUT = -17;
50 public const SOURCE_TYPE_TRADING_INPUT_1 = -20;
51 public const SOURCE_TYPE_TRADING_INPUT_2 = -21;
52 public const SOURCE_TYPE_TRADING_USE_INPUTS = -22;
53 public const SOURCE_TYPE_TRADING_OUTPUT = -23;
55 public const SOURCE_TYPE_BEACON = -24;
57 public const ACTION_MAGIC_SLOT_CREATIVE_DELETE_ITEM = 0;
58 public const ACTION_MAGIC_SLOT_CREATIVE_CREATE_ITEM = 1;
60 public const ACTION_MAGIC_SLOT_DROP_ITEM = 0;
61 public const ACTION_MAGIC_SLOT_PICKUP_ITEM = 1;
63 public int $sourceType;
64 public ?
int $windowId =
null;
65 public ?
int $sourceFlags =
null;
66 public int $inventorySlot;
77 $this->sourceType = VarInt::readUnsignedInt($in);
79 switch($this->sourceType){
80 case self::SOURCE_CONTAINER:
81 $this->windowId = VarInt::readSignedInt($in);
83 case self::SOURCE_WORLD:
84 $this->sourceFlags = VarInt::readUnsignedInt($in);
86 case self::SOURCE_CREATIVE:
88 case self::SOURCE_TODO:
89 $this->windowId = VarInt::readSignedInt($in);
95 $this->inventorySlot = VarInt::readUnsignedInt($in);
96 $this->oldItem = CommonTypes::getItemStackWrapper($in);
97 $this->newItem = CommonTypes::getItemStackWrapper($in);
102 public function writeAuthInput(ByteBufferWriter $out) : void{
103 VarInt::writeUnsignedInt($out, $this->sourceType);
105 switch($this->sourceType){
106 case self::SOURCE_CONTAINER:
107 if($this->windowId ===
null){
108 throw new \LogicException(
"WindowID must be set for SOURCE_CONTAINER");
110 VarInt::writeSignedInt($out, $this->windowId);
112 case self::SOURCE_WORLD:
113 if($this->sourceFlags ===
null){
114 throw new \LogicException(
"SourceFlags must be set for SOURCE_WORLD");
116 VarInt::writeUnsignedInt($out, $this->sourceFlags);
118 case self::SOURCE_CREATIVE:
120 case self::SOURCE_TODO:
121 if($this->windowId ===
null){
122 throw new \LogicException(
"WindowID must be set for SOURCE_TODO");
124 VarInt::writeSignedInt($out, $this->windowId);
127 throw new \InvalidArgumentException(
"Unknown inventory action source type $this->sourceType");
130 VarInt::writeUnsignedInt($out, $this->inventorySlot);
131 CommonTypes::putItemStackWrapper($out, $this->oldItem);
132 CommonTypes::putItemStackWrapper($out, $this->newItem);
142 $this->sourceType = VarInt::readUnsignedInt($in);
144 if(Byte::readUnsigned($in) !== 1){
147 $this->windowId = CommonTypes::readOptional($in, Byte::readSigned(...));
149 if(Byte::readUnsigned($in) !== 1){
152 $this->sourceFlags = CommonTypes::readOptional($in, VarInt::readUnsignedInt(...));
154 $this->inventorySlot = VarInt::readUnsignedInt($in);
155 $this->oldItem = CommonTypes::getNetworkItemStackDescriptor($in);
156 $this->newItem = CommonTypes::getNetworkItemStackDescriptor($in);
165 VarInt::writeUnsignedInt($out, $this->sourceType);
167 Byte::writeUnsigned($out, 1);
168 CommonTypes::writeOptional($out, $this->windowId, Byte::writeSigned(...));
170 Byte::writeUnsigned($out, 1);
171 CommonTypes::writeOptional($out, $this->sourceFlags, VarInt::writeUnsignedInt(...));
173 VarInt::writeUnsignedInt($out, $this->inventorySlot);
174 CommonTypes::putNetworkItemStackDescriptor($out, $this->oldItem);
175 CommonTypes::putNetworkItemStackDescriptor($out, $this->newItem);