public function refillChests($tile, $int){ for($i = 0;$i <= 20;$i++){ $tile->getInventory()->setItem($i, ItemFactory::get(1)); } } If i want refill chests with this function nothing happens, what's the matter?
Maybe try something like this PHP: public function refillChests(){ $fillInv = function (ChestInventory $inv) { $fillSlot = function (ChestInventory $inv) { $inv->setItem(slot, Item::get(id, 0, count)); }; $inv->clearAll(); for ($x = 0; $x <= 26; $x++) { if (rand(1, 3) == 1) { $fillSlot($inv); } }}; $level = $player->getLevel(); foreach ($level->getTiles() as $tile) { if ($tile instanceof Chest) { $fillInv($tile->getInventory()); } }} PHP: use pocketmine\inventory\ChestInventory;