Using /data to copy items from a player to a chest [duplicate]
Emily Wong
Im trying to copy a players inventory to a chest upon death but noticed that it only copies the hotbar and the first two rows of the inventory.
Command:
/data modify block ~ ~ ~ Items set from entity @p Inventory
So now my plan is to copy certain parts of the inventory into two separate storage containers.
This has led to the problem where i am unable to select certain sections or specific items out if the player inventory and copy them into a chest.
I tried:
/data modify block ~ ~ ~ Items set from entity @p Inventory[{Slot:0b}]
/data modify block ~ ~ ~ Items set from entity @p Inventory.0
/data modify block ~ ~ ~ Items set from entity @p Inventory[0]
Let me know if there is something wrong with my code, or if I need to try a different approach.
41 Answer
What you can do, and what is working in minecraft 1.15.2 (should also work in 1.14.4 and 1.16.x), is to append the player-inventory-data to the Item-data in the chest/hopper/etc.
this can be done like this:/data modify block <posX> <posY> <posZ> <container> append from entity <entity_selector> <container>
an example:
if there's a chest at 8 56 10, and you want to copy the 3rd item(be aware of that the inv. id's start at 0) in the player's hotbar to the chest, the command would look like this:/data modify block 8 56 10 Items append from entity @s Inventory[3]
this will copy the contents of the players 3rd hotbar slot to the chest, also at the third position.
if you want to modify the positions(inventory id's), than you would need to do a lot more complex programming. In this case, usually the problem can be solved easier by trying to solve the problem in an completely different way.
i hope that i could help you at least a bit.