1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

How i do refill chest?

Discussion in 'Requests' started by kelauzer, Aug 17, 2021.

  1. kelauzer

    kelauzer Creeper

    Messages:
    5
    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?
     
  2. Superomarking

    Superomarking Spider Jockey

    Messages:
    34
    GitHub:
    Superomarking
    Maybe try something like this
    PHP:
    public function refillChests(){
     
      
    $fillInv = function (ChestInventory $inv) {
        
    $fillSlot = function (ChestInventory $inv) {
          
    $inv->setItem(slotItem::get(id0count));
       };
       
    $inv->clearAll();
       for (
    $x 0$x <= 26$x++) {
            if (
    rand(13) == 1) {
                 
    $fillSlot($inv);
             }
        }
    };
      
    $level $player->getLevel();
     
      foreach (
    $level->getTiles() as $tile) {
        if (
    $tile instanceof Chest) {
           
    $fillInv($tile->getInventory());
        }
      }
    }
    PHP:
    use pocketmine\inventory\ChestInventory;
     
    Last edited: Aug 17, 2021
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.