6

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.

  • Have you found an answer for your problem? – Dorian Dore Mar 6 '15 at 15:39
  • 1
    Yeah, I guess I'll probably just go with teleporting the player, unless I decide to set up 2,000 command blocks. Thanks for all of the help. – thezi3 Mar 6 '15 at 18:50
  • I think @colorfusion 's answer was the best. Go for his. – Dorian Dore Mar 6 '15 at 19:06
  • 1
    I think the new NBT management features added in the recent snapshots will finally allow for this in a fairly simple and straight forward manner. It should only need maybe a dozen commands in order to implement a save and restore mechanic. – MBraedley Nov 10 '18 at 15:12
2

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
  • Thanks! I personally don't need it anymore, but I'm sure someone else will find this helpful. – thezi3 Jul 25 at 5:57
5

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.

  • That might work. I'll get back to you on that... Thanks – thezi3 Mar 3 '15 at 19:48
  • Combine this with the blindness + night vision trick to give a black screen and it might not look so ugly. – SevenSidedDie Mar 3 '15 at 22:02
  • 1
    @SevenSidedDie: They'll still get the respawn screen, though. In any case, this is similar to one of the methods I was going to suggest. One possible issue I see in it is that it takes time for items to flow through a hopper. It can be sped up, but not fast enough if there's a lot of items on the player. – MBraedley Mar 3 '15 at 22:07
1

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.

  • 1
    Except it's not 36 command blocks, it's effectively 36 x 64 x the number items that stack to 64, plus the same math for items that don't stack as high, plus the armour slots. And that completely ignores enchantments and durability. There might be some tricks to get it down to something reasonable (where "reasonable" is less than 2000 command blocks), and you don't have to test every slot (so divide by 36), but it's still a massive number of command blocks that I don't think will properly handle specific edge cases. – MBraedley Mar 3 '15 at 22:21
  • 1
    It would be a whole lot easier if I could test for x slot, find an item, and have the command block remember that item lol But yeah, as much as I want to have it "save" where the player is, I think I am going to have to go with teleporting the player to a saving chamber of sorts. – thezi3 Mar 4 '15 at 14:37
-7

You must use /gamerule keepInventory true

  • 8
    He specifically pointed out that this won't work. – Frank Mar 2 '15 at 19:44
  • @Frank He writed /gamerule keepInventory not /gamerule keepInventory true. Big difference. – math.random Mar 2 '15 at 19:55
  • What I mean by /gamerule keepInventory was pretty clear... – thezi3 Mar 3 '15 at 19:48
  • 1
    this wont work as since the OP is trying to create a check point " to have it so that you will have all the items you had then, and none of the items you got after you saved", this rule will not work as it keeps the current inventory so any items obtained after the "checkpoint" will still be present while any items used wont come back – Memor-X Mar 3 '15 at 21:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.