Minecraft Java Edition – How to Save Minecraft Inventory Using Commands in Minecraft Java Edition

minecraft-commandsminecraft-java-edition

I am making an RPG map, and was wondering how to "save" the game. If you die, you would revert back to a save that happens automatically or manually, and I was wondering how to have it so that you will have all the items you had then, and none of the items you got after you saved (so /gamerule keepInventory won't work). The only way I can think of doing this is having this long, long, annoying set of command blocks to test for all the items in the game, and then have another 64 command blocks for each of those items, testing for the amount of the item.

Best Answer

In Minecraft 1.14 and later versions, it is possible to copy the player's inventory to a chest without killing the player.

/data modify block <coordinates of chest> Items set from entity <player> Inventory

Note that this only copies the hotbar and the bottom two rows of the player's inventory, since players can carry slightly more stuff than can fit in a chest. If you want to copy the player's entire inventory to a double chest, you need a much more complicated trick.