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

Deathdrops into chest

Discussion in 'Development' started by Remarkabless, Dec 5, 2017.

  1. Remarkabless

    Remarkabless Slime

    Messages:
    83
    GitHub:
    Remakem
    How can I open a chest and add the items in there when a player dies, I have never worked with tiles or spawning chests, any help thanks!
     
  2. Karanpatel567

    Karanpatel567 Baby Zombie

    Messages:
    115
    GitHub:
    Karanpatel567
    First you have to use the class PlayerDeathEvent, and on death get the cords where the player died. I don't know how to add the items into the chest but you can spawn the chest using setBlock().
     
    Levi likes this.
  3. Remarkabless

    Remarkabless Slime

    Messages:
    83
    GitHub:
    Remakem
    Yeah, I had that kind of idea but im pretty sure t has to do with chest tiles, which I have never worked with
     
  4. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Do you have any previsious attempt?
     
  5. Remarkabless

    Remarkabless Slime

    Messages:
    83
    GitHub:
    Remakem
    I just have it where it gets the coordinates and spawns (diamond block) but thats honestly irrelevant to the actual questions
    I just need to know the actual put stuff on in the chest when the player dies
     
  6. friscowz

    friscowz Baby Zombie Ban Evader Banned

    Messages:
    128
    GitHub:
    friscowzmcpe
    PHP:
    /**
    * @param PlayerDeathEvent $event
    */
    public function onDeath(PlayerDeathEvent $event)
    {
        
    $player $event->getPlayer();

        
    $player->getLevel()->setBlock($player->asVector3(), Block::get(BlockIds::CHEST));
        
    $player->getLevel()->setBlock($player->asVector3()->add(1), Block::get(BlockIds::CHEST));
        
        
    $items $event->getDrops();
        
        
    $block1 $player->getLevel()->getBlock($player->asVector3());
        
    $block2 $player->getLevel()->getBlock($player->asVector3()->add(1));
        
        if(
    $block1 instanceof Chest and $block2 instanceof Chest){
            
    $block1->pairWith($block2);
            
    $block2->pairWith($block1);
            foreach (
    $items as $item) {
                
    $block1->getInventory()->addItem($item);
            }
            
    $event->setDrops([]);
        }
    }
     
  7. friscowz

    friscowz Baby Zombie Ban Evader Banned

    Messages:
    128
    GitHub:
    friscowzmcpe
    Note that the Chest object is the tile :)
     
    Karanpatel567 likes this.
  8. Karanpatel567

    Karanpatel567 Baby Zombie

    Messages:
    115
    GitHub:
    Karanpatel567
    No point making it spawn two chests when they won't even pair with each other :p
     
  9. friscowz

    friscowz Baby Zombie Ban Evader Banned

    Messages:
    128
    GitHub:
    friscowzmcpe
    did you even read the whole code ??
     
  10. Karanpatel567

    Karanpatel567 Baby Zombie

    Messages:
    115
    GitHub:
    Karanpatel567
    Dude, I'm saying ingame! And I did read the whole code :/
     
  11. friscowz

    friscowz Baby Zombie Ban Evader Banned

    Messages:
    128
    GitHub:
    friscowzmcpe
    then why did you say that ?
    i did pair both of them.
     
  12. Karanpatel567

    Karanpatel567 Baby Zombie

    Messages:
    115
    GitHub:
    Karanpatel567
    It doesn't matter if you did or not, it wouldn't pair in-game okay? And a moment ago i just tested it and i was true so not expecting any more replies.
     
  13. Derpific

    Derpific Spider Jockey

    Messages:
    44
    GitHub:
    Derpific
    There's a way to pair chests with a task..
     
    Levi likes this.
  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.