Basically, I want to be able to get ALL the chests that are ALREADY placed on the map and give items to them. I honestly don't know how to go about doing that. They are going to be specific items but randomly. Thanks
PHP: /** @var Level $level *//** @var Item $item */foreach($level->getTiles() as $tile) { if($tile instanceof Chest) { $tile->getInventory()->addItem($item); }}
That would work if all chunks of the world are loaded. It would be better (in terms of memory and CPU) if this was solved by a script (outside pocketmine) which does that, but that might require a few reflection hacks if you're going to use pocketmine's level provider.
[QUOTE = "DiamondGamer30, postagem: 60917, membro: 1548"] PHP: / ** @var Level $ level * // ** @var Item $ item * /foreach ($ level-> getTiles () as $ tile) { if ($ tile instanceof Chest) { $ tile-> getInventory () -> addItem ($ item); }} [/QUOTE] The ChunkLoadEvent event Maybe it is more efficient because it will apply the items in all the chests that are loaded, just a suggestion[/PHP]
If its just for a game where block cannot be broken it would be better to add item on inventory open? Then save the coords of the holder and clear at end of game. Dont add item if coords already exist Make use of rand or array_rand for choosing items in an array