If I placed a chest with this code PHP: $level->setBlock(new Vector3($x, $y, $z), 54); How can I put items in that chest by code?
You need to initialize a chest tile entity for that block first. https://github.com/PocketMine/PocketMine-MP/blob/master/src/pocketmine/block/Chest.php#L94
Chest inventory is like player inventory. But at first, you need get the chest as a tile: PHP: $tile = $lv->getTile(new Vector3($x,$y,$z)); Then check if this tile is really chest(not sign...): PHP: if ($tile instanceof Chest){ Then, just get inventory with $tile->getInventory() and you can use addItem(Item::get($id, $meta, $cnt)), removeItem....
Thanks! Now, with this code I can randomly spawn chests in the whole SkyWars world. You'll no longer know where chest can appear :3
To put items in the chest, you need to acquire the inventory of the chest first. PHP: $chestInventory = $tileChest->getInventory(); Then set the items: Code: $chestInventory->setItem($itemIndex, Item::get($itemId, $itemMeta, $itemCount));
I did this PHP: $chest = $level->createTile("chest", new Vector3($randX+4, $randY+1, $Z+4));$chestInv = $chest->getInventory();$config = $this->getConfig()->get("Items");foreach($config as $i){ $chestInv->addItem($i);} Would that work? (i haven't tested it yet)