1

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.

4
  • What happened when you ran those commands?
    – pppery
    Aug 3, 2020 at 0:57
  • By "section", do you mean a group of item slots or a single item slot?
    – One 2 Many
    Aug 3, 2020 at 18:58
  • may you please tell us, which version of minecraft you are using, might be helpful. Aug 3, 2020 at 21:35
  • 4
    Possible duplicate of How would you copy a player's inventory into a double chest? (cutting out the XY problem and addressing the original issue)
    – pppery
    Apr 30, 2021 at 23:07

1 Answer 1

0

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.

Not the answer you're looking for? Browse other questions tagged .