Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved Adding items to chest (stacking)

Comments in 'Plugin Development' started by AppPhil, Oct 9, 2015.

  1. AppPhil
    Offline

    AppPhil Active Member

    Joined:
    Oct 3, 2015
    Posts:
    54
    Hey there,

    how can I add items to a chest every second?
    I got this code:
    PHP:
    $chest $this->getMatch()->getMap()->getLevel()->getTile($team->getSpawnChestPos());
    $inv $chest->getInventory();
    if(
    $inv->canAddItem($this->item)) {
        
    $inv->setItem($inv->firstEmpty(), $this->item);
    }
    And this all gets called every second. But firstEmpty() returns the $index where no item is, but I want that the item stacks. How can I do that?
  2. CavinMiana
    Offline

    CavinMiana Active Member

    Joined:
    Aug 26, 2015
    Posts:
    101
    Minecraft User:
    CavinMiana
    Make a repeatingTask
  3. AppPhil
    Offline

    AppPhil Active Member

    Joined:
    Oct 3, 2015
    Posts:
    54
    Thats not the problem. I got that what I wrote in the first post and that gets called every second. But how can I do it, that the Inventory gets the first place, to add the item? With the first place I mean, the first where the same item is and where it's not full stacked.
  4. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    PHP:
    $chest $lv->getTile(new Vector3($x,$y,$z));
    if (
    $chest instanceof Chest){
     
    $chest->getInventory()->addItem(Item::get(1,0,64));
    }
    TheKofola12 and AppPhil like this.

Share This Page

Advertisement