I'd like to create a Minecraft data pack to let a player see what he dropped/lost upon death (whatever he had in inventory+hotbar+offhand+armor+etc). I got the GUI part but i'm missing how to read a user inventory with a command so i can fill the new GUI with those items. I don't think /testfor
is viable since i'd have to test for every single block present in the game and also i'd lose all the tags attached to an item (Edit: i've read that command is available only on BE, this is for JE). I tried to look at the documentation of /replaceitem
but it doesn't seem useful either. Thanks in advance.
2 Answers
It seems that this is not possible. Maybe you could do something that detects if the player dies and teleports all the items on the ground or something along those lines. Perhaps using hoppers. You could also make sure that it doesn't teleport other items in the world by doing a radius. Although to my knowledge doing it any other way is impossible. You can use a scoreboard objective to test if the player has died.
You need a place to store the player data before the player dies. You can copy the player's inventory to another entity, perhaps an invisible armor stand at 0,0.
/execute as <player selector> run data modify entity <global armorstand selector> Items set from @s Items
Then, once the player is dead and whatnot, you need to copy the inventory from the armor stand to a chest/minecart chest for the player to be able to retrieve the items.
/execute as <chest selector> run data modify entity @s Items set from <global armorstand selector> Items
whatever your previous number was
to the power of 27).