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

Get items in chest

Discussion in 'Development' started by Trxgically, Feb 15, 2019.

  1. Trxgically

    Trxgically Spider Jockey

    Messages:
    26
    GitHub:
    trxgically
    How would I get the items in a chest after tapping it? I’ve gotten this done so far :


    public function onInteract(PlayerInteractEvent $event)
    {
    if ($this->chestInteractions === true) {
    $player = $event->getPlayer();
    $block = $event->getBlock();
    $x = $block->getX();
    $y = $block->getY();
    $z = $block->getZ();
    $lv = $player->getLevel();
    $tile = $lv->getTile(new Vector3($x, $y, $z));
    if ($event->getBlock()->getId() === Item::CHEST) {
    if ($tile instanceof Chest) {


    $this->chestInteractions = false;
    }
    }
    }
     
  2. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Next time put your code in code tags, it will improve readability
    PHP:
    $contents $tile->getInventory()->getContents();
    if(
    $notAdded $player->getInventory()->addItem(...$contents))
        foreach(
    $notAdded as $item){
            
    //you can choose to drop the item or ignore
        
    }
    $tile->getInventory()->clearAll(); //optional
     
  3. Trxgically

    Trxgically Spider Jockey

    Messages:
    26
    GitHub:
    trxgically
    Thanks!
     
  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.