Idea: I have PRE-Placed Chest all around the map.(around 20-30) Im wondering if there's a way where I can get ALL the chest in a "world", so I can then just add randomized items into a chest. Basically, I just need to find a way to GET all chest in a "world", so I can place items in to them. All of the chest will have the same exact randomized items. Thanks
The only Chest in the map are the chests I have in my "arena" the world is custom and only has those chests that I placed was thinking get all tiles and place items
PHP: @param World $world@param Chests $tile@param ChestInventory $invforeach($world->getTiles() as $tile){if($tile instanceof Chest){$inv = $tile->getInventory();}}
@Muqsit can you help me get a way to fully load in a world when the plugin on enebales? That way if all chunks are loaded I can go ahead and send this function right after. Hopefully that would work if not could you help me out? Thanks
That sounds like a terrible idea. My intent in saying that wasn't so you could come up with a method of loading all chunks, it isn't as simple as that sounds. You'll end up exhausting all your RAM and have to wait countless minutes or hours to start the server. Why not do what @wolfdale mentioned? That's memory (and possibly CPU) efficient and you won't need to store a list of chest positions the way other plugins do.
You can fillchests on ChunkLoadEvent. PHP: /** * @param \pocketmine\event\level\ChunkLoadEvent $event */ public function onChunkLoad(ChunkLoadEvent $event) { $chunk = $event->getChunk(); /** @var \pocketmine\tile\Tile $tile */ foreach ($chunk->getTiles() as $tile) { /** @var \pocketmine\tile\Chest $tile */ if($tile instanceof Chest) { $tile->getInventory()->setItem(0, Item::get(Item::IRON_SWORD)); } } }