With the help of some github codes I made a mini api of the villager's trade, it works well but I realized that the window that opens is an old trade window, by chance the game limits us to that old window or has some way to use the new? PHP: <?phpnamespace trade;use pocketmine\Player;use pocketmine\entity\Villager;use pocketmine\entity\Entity;use pocketmine\math\Vector3;use pocketmine\network\mcpe\protocol\UpdateTradePacket;use pocketmine\network\mcpe\protocol\AddActorPacket;use pocketmine\network\mcpe\protocol\types\WindowTypes;use pocketmine\nbt\NetworkLittleEndianNBTStream;use pocketmine\item\Item;use pocketmine\nbt\tag\{ CompoundTag, ListTag, ByteTag, IntTag};class Trade{protected $eid = 0;protected $title = "";protected $willing = false;protected $tradeTier = 1;protected $recipes = [];public function __construct(string $title){$this->title = $title;}public function getEid() : int{ return $this->eid;}public function getTitle() : string{ return $this->title;}public function setTitle(string $title){ $this->title = $title;}public function isWilling() : bool{ return $this->willing;}public function setWilling(bool $v){ $this->willing = $v;}public function getTradeTier() : int{ return $this->tradeTier;}public function setTradeTier(int $v){ $this->tradeTier = $v;}/*@Param Item $buy - First Item to trade@Param Item $buyB - Second Item To Trade (is opcional)@Param Item $sell - Result Item of Trade@Param bool $rewardXp - xp trade@Param int $maxUse - Trade limit@Param int $defaultUses - Default trade use*/public function addRecipe(Item $buy, ?Item $buyB = null, Item $sell, bool $rewardXp = true, int $maxUse = 12, int $defaultUses = 0){$arr = [ new ByteTag("rewardExp", $rewardXp), new IntTag("maxUses", $maxUse), new IntTag("uses", $defaultUses), $buy->nbtSerialize(-1, "buyA"), $sell->nbtSerialize(-1, "sell")];if(!is_null($buyB)){ $arr[] = $buyB->nbtSerialize(-1, "buyB");}$this->recipes[] = new CompoundTag("", $arr);}public function send(Player $p, ?Villager $v = null){ $eid = is_null($v) ? $this->getFakeVillagerId($p) : $v->getId(); $this->eid = $eid; $pk = new UpdateTradePacket(); $pk->windowId = WindowTypes::TRADING; $pk->tradeTier = $this->getTradeTier(); $pk->isWilling = $this->isWilling(); $pk->traderEid = $eid; $pk->playerEid = $p->getId(); $pk->displayName = $this->getTitle(); $writer = new NetworkLittleEndianNBTStream(); $tags = new CompoundTag("Offers", [ new ListTag("Recipes", $this->recipes) ]); $pk->offers = $writer->write($tags); $p->dataPacket($pk); Main::saveTrade($p, $this);}public function getFakeVillagerId(Player $p) : int{ $eid = Entity::$entityCount++; $pk = new AddActorPacket(); $pk->entityRuntimeId = $eid; $pk->type = Villager::NETWORK_ID; $pk->position = $p->asVector3(); $pk->motion = new Vector3(); $pk->yaw = $pk->pitch = 0; $pk->metadata = [ Entity::DATA_FLAGS => [Entity::DATA_TYPE_LONG, 1 << Entity::DATA_FLAG_IMMOBILE], Entity::DATA_SCALE => [Entity::DATA_TYPE_FLOAT, 0] ]; $p->dataPacket($pk); return $eid;}}
Hi @HeyDeniis_ The new villager trading screen can be used by enabling the isV2Trading value in the UpdateTradePacket, https://github.com/pmmp/PocketMine-...twork/mcpe/protocol/UpdateTradePacket.php#L51
I set it to true but it's still in the old one :/ PHP: $pk = new UpdateTradePacket(); $pk->windowId = WindowTypes::TRADING; $pk->tradeTier = $this->getTradeTier(); $pk->isWilling = $this->isWilling(); $pk->traderEid = $eid; $pk->playerEid = $p->getId(); $pk->isV2Trading = (bool) true; $pk->displayName = $this->getTitle(); $writer = new NetworkLittleEndianNBTStream(); $tags = new CompoundTag("Offers", [ new ListTag("Recipes", $this->recipes) ]); $pk->offers = $writer->write($tags); $p->dataPacket($pk);
I used your class with & without that exact line(Minus the type casting) Using Two items of Apple to trade for One item of bed but I doubt the data used is a problem.
I understand, I wanted your code because it could be something that I put wrong, you already deleted it?
Yes it was only a quick piggyback on a plugin, the last thing I can suggest is making sure your server is updated to 3.12.0 previous versions miss-matched encoding that specific variable.