Hi! I'm not sure if this is correct but i'm having issues with cancelling Inv Transaction and setting items in a Chest... Please help and advise. Thanks PHP: public function sendChestInventory(Player $player, InventoryTransactionEvent $e){ $block = Block::get(54); $player->getLevel()->setBlock(new Vector3($player->x, $player->y - 2, $player->z), $block, true, true); $nbt = new CompoundTag("", [ new ListTag("Items", []), new StringTag("id", Tile::CHEST), new IntTag("x", floor($player->x)), new IntTag("y", floor($player->y) - 2), new IntTag("z", floor($player->z)) ]); $nbt->Items->setTagType(NBT::TAG_Compound); $tile = Tile::createTile("Chest", $player->getLevel()->getChunk($player->getX() >> 4, $player->getZ() >> 4), $nbt); /* Items */ $item = Item::get(310, 0, 1); $item2 = Item::get(276, 0, 1); $item2->setCustomName("Lmao"); $tile->getInventory()->getSlotIndex(1)->setItem($item); $tile->getInventory()->addItem(2, $item); $player->addWindow($tile->getInventory()); foreach($e->getTransaction()->getTransactions() as $t) { if($t->getInventory() instanceof ChestInventory) { $e->setCancelled(true); ] ] }
you should listen for the event after creating the chest. the event you passed doesn't know of your new chest yet