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

Spawn items in pre placed chest.

Discussion in 'Development' started by Vaxrp, Jul 29, 2019.

  1. Vaxrp

    Vaxrp Witch

    Messages:
    73
    GitHub:
    Vaxrp
    Idea:
    I have PRE-Placed Chest all around the map.(around 20-30)

    Im wondering if there's a way where I can get ALL the chest in a "world", so I can then just add randomized items into a chest.

    Basically, I just need to find a way to GET all chest in a "world", so I can place items in to them. All of the chest will have the same exact randomized items.

    Thanks
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Worlds are infinite. Do you have a specific region you want to check?
     
  3. Vaxrp

    Vaxrp Witch

    Messages:
    73
    GitHub:
    Vaxrp
    The only Chest in the map are the chests I have in my "arena"

    the world is custom and only has those chests that I placed

    was thinking get all tiles and place items
     
  4. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Why not add the items when the players open them?
     
    HimbeersaftLP and Muqsit like this.
  5. HeyDeniis_

    HeyDeniis_ Baby Zombie

    Messages:
    137
    PHP:
    @param World $world
    @param Chests $tile
    @param ChestInventory $inv

    foreach($world->getTiles() as $tile){
    if(
    $tile instanceof Chest){
    $inv $tile->getInventory();

    }
    }
     
  6. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    getTiles() only returns tiles from the loaded chunks. You'll miss out several chests.
     
  7. Vaxrp

    Vaxrp Witch

    Messages:
    73
    GitHub:
    Vaxrp
    @Muqsit can you help me get a way to fully load in a world when the plugin on enebales?

    That way if all chunks are loaded I can go ahead and send this function right after.

    Hopefully that would work if not could you help me out? Thanks
     
  8. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    That sounds like a terrible idea. My intent in saying that wasn't so you could come up with a method of loading all chunks, it isn't as simple as that sounds. You'll end up exhausting all your RAM and have to wait countless minutes or hours to start the server.

    Why not do what @wolfdale mentioned? That's memory (and possibly CPU) efficient and you won't need to store a list of chest positions the way other plugins do.
     
    HimbeersaftLP likes this.
  9. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    You can fillchests on ChunkLoadEvent.

    PHP:
        /**
         * @param \pocketmine\event\level\ChunkLoadEvent $event
         */
        
    public function onChunkLoad(ChunkLoadEvent $event) {
            
    $chunk $event->getChunk();
            
    /** @var \pocketmine\tile\Tile $tile */
            
    foreach ($chunk->getTiles() as $tile) {
                
    /** @var \pocketmine\tile\Chest $tile */
                
    if($tile instanceof Chest) {
                    
    $tile->getInventory()->setItem(0Item::get(Item::IRON_SWORD));
                }
            }
        }
     
  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.