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.
In Minecraft 1.14, 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
I've got a solution, but it's a bit ugly; it involves killing the player and having them reorganize their inventory at each save. You'll also need
Whenever you want to save, teleport the player to an enclosed cell with a hopper on the floor and chest below, then kill them; all of their items should go into the chest. If there were already items in the chest from a previous save, you'll need to
/setblock the chest to clear it first.
/clone this chest with their items to another enclosed cell.
When the player dies, teleport them to the cloned chest and break the chest. All of their items in the cloned chest (that they had when they saved) will fall into their inventory.
/clone the chest again form the original one in case they die again. Then you'll just need to teleport the player out of the cell back to where they were when they saved.
This video here might be able to help you. The only way I can think of is to have 36 command blocks to test for what item is in your inventory, and have the command blocks run simultaneously once the save command is executed. Then, when the player dies, it gives back all items that the 36 command blocks checked for.
You must use
/gamerule keepInventory true