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

Solved how to add Items to Chest

Discussion in 'Development' started by iCirgio, Dec 17, 2017.

  1. iCirgio

    iCirgio Slime

    Messages:
    92
    GitHub:
    lolnova
    When the player place the chest i want it to have items in it. How will I go about doing that?
     
  2. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    PHP:
    public function onPlace(\pocketmine\event\block\BlockPlaceEvent $e){
         
    $b $e->getBlock();
         
    $tile $b->getLevel()->getTile(new \pocketmine\math\Vector3($b->x$b->y$b->z));
         if(
    $tile instanceof \pocketmine\tile\Chest){
              
    $id 1;
              
    $damage 0;
              
    $count 64;
              
    $tile->getInventory()->addItem(\pocketmine\item\Item::get($id$damage$count);
         }
    }
     
  3. iCirgio

    iCirgio Slime

    Messages:
    92
    GitHub:
    lolnova
    thanks I'll test
     
  4. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    try the give command
    Code:
    /give jasonwynn10 chest 1 {display:{Name:"§rSuspicious Chest"},BlockEntityTag:{Items:[{id:7,Count:64,Slot:0,display:{Name:"FEEL THE POWER!"}}]}}
     
  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.