Get all chest in the world and add items into the chest

Discussion in 'Development' started by Vaxrp, Feb 14, 2019 at 3:47 AM.

  1. Vaxrp

    Vaxrp Witch

    Messages:
    70
    GitHub:
    Vaxrp
    Basically, I want to be able to get ALL the chests that are ALREADY placed on the map and give items to them. I honestly don't know how to go about doing that. They are going to be specific items but randomly. Thanks
     
  2. DiamondGamer30

    DiamondGamer30 Baby Zombie

    Messages:
    151
    GitHub:
    diamondgamermcpe
    PHP:
    /** @var Level $level */
    /** @var Item $item */
    foreach($level->getTiles() as $tile) {
        if(
    $tile instanceof Chest) {
            
    $tile->getInventory()->addItem($item);
        }
    }
     
  3. Muqsit

    Muqsit Wither Skeleton Verified

    Messages:
    1,458
    GitHub:
    muqsit
    That would work if all chunks of the world are loaded.

    It would be better (in terms of memory and CPU) if this was solved by a script (outside pocketmine) which does that, but that might require a few reflection hacks if you're going to use pocketmine's level provider.
     
  4. KielKing

    KielKing Baby Zombie

    Messages:
    108
    GitHub:
    kielking
    if you're working on a minigame, I recommend you just save the position of the chests
     
  5. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    678
    GitHub:
    xXNiceYT
    No if I would him I would get all tiles and set items in it when game start
     
  6. KielKing

    KielKing Baby Zombie

    Messages:
    108
    GitHub:
    kielking
     

Share This Page

  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.