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!
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().
Yeah, I had that kind of idea but im pretty sure t has to do with chest tiles, which I have never worked with
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
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([]); }}
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.