PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
UpdateTradePacket.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;
16
17use pmmp\encoding\Byte;
18use pmmp\encoding\ByteBufferReader;
19use pmmp\encoding\ByteBufferWriter;
20use pmmp\encoding\VarInt;
24
26 public const NETWORK_ID = ProtocolInfo::UPDATE_TRADE_PACKET;
27
28 public int $windowId;
29 public int $windowType = WindowTypes::TRADING; //Mojang hardcoded this -_-
30 public int $windowSlotCount = 0; //useless, seems to be part of a standard container header
31 public int $tradeTier;
32 public int $traderActorUniqueId;
33 public int $playerActorUniqueId;
34 public string $displayName;
35 public bool $isV2Trading;
36 public bool $isEconomyTrading;
39
44 public static function create(
45 int $windowId,
46 int $windowType,
47 int $windowSlotCount,
48 int $tradeTier,
49 int $traderActorUniqueId,
50 int $playerActorUniqueId,
51 string $displayName,
52 bool $isV2Trading,
53 bool $isEconomyTrading,
55 ) : self{
56 $result = new self;
57 $result->windowId = $windowId;
58 $result->windowType = $windowType;
59 $result->windowSlotCount = $windowSlotCount;
60 $result->tradeTier = $tradeTier;
61 $result->traderActorUniqueId = $traderActorUniqueId;
62 $result->playerActorUniqueId = $playerActorUniqueId;
63 $result->displayName = $displayName;
64 $result->isV2Trading = $isV2Trading;
65 $result->isEconomyTrading = $isEconomyTrading;
66 $result->offers = $offers;
67 return $result;
68 }
69
70 protected function decodePayload(ByteBufferReader $in) : void{
71 $this->windowId = Byte::readUnsigned($in);
72 $this->windowType = Byte::readUnsigned($in);
73 $this->windowSlotCount = VarInt::readSignedInt($in);
74 $this->tradeTier = VarInt::readSignedInt($in);
75 $this->traderActorUniqueId = CommonTypes::getActorUniqueId($in);
76 $this->playerActorUniqueId = CommonTypes::getActorUniqueId($in);
77 $this->displayName = CommonTypes::getString($in);
78 $this->isV2Trading = CommonTypes::getBool($in);
79 $this->isEconomyTrading = CommonTypes::getBool($in);
80 $this->offers = new CacheableNbt(CommonTypes::getNbtCompoundRoot($in));
81 }
82
83 protected function encodePayload(ByteBufferWriter $out) : void{
84 Byte::writeUnsigned($out, $this->windowId);
85 Byte::writeUnsigned($out, $this->windowType);
86 VarInt::writeSignedInt($out, $this->windowSlotCount);
87 VarInt::writeSignedInt($out, $this->tradeTier);
88 CommonTypes::putActorUniqueId($out, $this->traderActorUniqueId);
89 CommonTypes::putActorUniqueId($out, $this->playerActorUniqueId);
90 CommonTypes::putString($out, $this->displayName);
91 CommonTypes::putBool($out, $this->isV2Trading);
92 CommonTypes::putBool($out, $this->isEconomyTrading);
93 $out->writeByteArray($this->offers->getEncodedNbt());
94 }
95
96 public function handle(PacketHandlerInterface $handler) : bool{
97 return $handler->handleUpdateTrade($this);
98 }
99}
static create(int $windowId, int $windowType, int $windowSlotCount, int $tradeTier, int $traderActorUniqueId, int $playerActorUniqueId, string $displayName, bool $isV2Trading, bool $isEconomyTrading, CacheableNbt $offers,)