61 $this->requestId =
CommonTypes::readLegacyItemStackRequestId($in);
63 $this->requestChangedSlots = CommonTypes::readOptional($in,
static function(ByteBufferReader $in) : array{
65 for($i = 0, $len = VarInt::readUnsignedInt($in); $i < $len; ++$i){
66 $result[] = InventoryTransactionChangedSlotsHack::read($in);
71 if(Byte::readUnsigned($in) !== 1){
74 $transactionType = VarInt::readUnsignedInt($in);
75 if(Byte::readUnsigned($in) !== 1){
78 $this->trData = match($transactionType) {
79 NormalTransactionData::ID =>
new NormalTransactionData(),
80 MismatchTransactionData::ID =>
new MismatchTransactionData(),
81 UseItemTransactionData::ID =>
new UseItemTransactionData(),
82 UseItemOnEntityTransactionData::ID =>
new UseItemOnEntityTransactionData(),
83 ReleaseItemTransactionData::ID =>
new ReleaseItemTransactionData(),
84 default =>
throw new PacketDecodeException(
"Unknown transaction type $transactionType"),
86 $this->trData->decodeTransaction($in);
90 CommonTypes::writeLegacyItemStackRequestId($out, $this->requestId);
92 CommonTypes::writeOptional($out, $this->requestChangedSlots,
static function(ByteBufferWriter $out, array $value) :
void{
93 VarInt::writeUnsignedInt($out, count($value));
94 foreach($value as $changedSlots){
95 $changedSlots->write($out);
99 Byte::writeUnsigned($out, 1);
100 VarInt::writeUnsignedInt($out, $this->trData->getTypeId());
101 Byte::writeUnsigned($out, 1);
102 $this->trData->encodeTransaction($out);