TransWikia.com

Minecraft Inventory Saving

Arqade Asked by thezi3 on March 24, 2021

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.

4 Answers

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.

Correct answer by pppery on March 24, 2021

You must use /gamerule keepInventory true

Answered by math.random on March 24, 2021

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.

Answered by Dorian Dore on March 24, 2021

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 keepInventory off.

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.

Answered by SirBenet on March 24, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP