PocketMine-MP 5.23.3 git-f7687af337d001ddbcc47b8e773f014a33faa662
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
20
22 public const NETWORK_ID = ProtocolInfo::UPDATE_TRADE_PACKET;
23
24 public int $windowId;
25 public int $windowType = WindowTypes::TRADING; //Mojang hardcoded this -_-
26 public int $windowSlotCount = 0; //useless, seems to be part of a standard container header
27 public int $tradeTier;
28 public int $traderActorUniqueId;
29 public int $playerActorUniqueId;
30 public string $displayName;
31 public bool $isV2Trading;
32 public bool $isEconomyTrading;
35
40 public static function create(
41 int $windowId,
42 int $windowType,
43 int $windowSlotCount,
44 int $tradeTier,
45 int $traderActorUniqueId,
46 int $playerActorUniqueId,
47 string $displayName,
48 bool $isV2Trading,
49 bool $isEconomyTrading,
51 ) : self{
52 $result = new self;
53 $result->windowId = $windowId;
54 $result->windowType = $windowType;
55 $result->windowSlotCount = $windowSlotCount;
56 $result->tradeTier = $tradeTier;
57 $result->traderActorUniqueId = $traderActorUniqueId;
58 $result->playerActorUniqueId = $playerActorUniqueId;
59 $result->displayName = $displayName;
60 $result->isV2Trading = $isV2Trading;
61 $result->isEconomyTrading = $isEconomyTrading;
62 $result->offers = $offers;
63 return $result;
64 }
65
66 protected function decodePayload(PacketSerializer $in) : void{
67 $this->windowId = $in->getByte();
68 $this->windowType = $in->getByte();
69 $this->windowSlotCount = $in->getVarInt();
70 $this->tradeTier = $in->getVarInt();
71 $this->traderActorUniqueId = $in->getActorUniqueId();
72 $this->playerActorUniqueId = $in->getActorUniqueId();
73 $this->displayName = $in->getString();
74 $this->isV2Trading = $in->getBool();
75 $this->isEconomyTrading = $in->getBool();
76 $this->offers = new CacheableNbt($in->getNbtCompoundRoot());
77 }
78
79 protected function encodePayload(PacketSerializer $out) : void{
80 $out->putByte($this->windowId);
81 $out->putByte($this->windowType);
82 $out->putVarInt($this->windowSlotCount);
83 $out->putVarInt($this->tradeTier);
84 $out->putActorUniqueId($this->traderActorUniqueId);
85 $out->putActorUniqueId($this->playerActorUniqueId);
86 $out->putString($this->displayName);
87 $out->putBool($this->isV2Trading);
88 $out->putBool($this->isEconomyTrading);
89 $out->put($this->offers->getEncodedNbt());
90 }
91
92 public function handle(PacketHandlerInterface $handler) : bool{
93 return $handler->handleUpdateTrade($this);
94 }
95}
static create(int $windowId, int $windowType, int $windowSlotCount, int $tradeTier, int $traderActorUniqueId, int $playerActorUniqueId, string $displayName, bool $isV2Trading, bool $isEconomyTrading, CacheableNbt $offers,)