6

I'm creating an adventure map with many levels. You can chose which level to do and can walk out of one anytime. When you walk out of the level your inventory will be cleared. Is there a way to make it so that when you walk back into the level you will get your old items back?

5

Make sure that you have

/gamerule keepInventory false

We have to assume that there are no other items in the world, if not we just kill them. The idea is to kill the Player and put his items into a hopper -> chest. Then you could clone the chest.

Put those commands into a command block chain

/kill @e[type=Item]

(Optional) kills every item in the map, if you want to get the items laying aroung into the chest too, remove this commmand

/kill @p

Kill the player

/entitydata @e[type=Item] {Motion:[0:0.0,1:0.0,2:0.0]}

Remove the Motion of all items so they stay still

/tp @e[type=Item] 5 10 5

Tp the items onto the hopper (replace 5 10 5 with one block the hopper)

Trigger the command blocks with redstone or other chain command blocks

enter image description here

This does not have to be a trpped chest

enter image description here

You then could tp the player to his old position, do research and then, if you can not find anything for that, ask a new question for that.

On level reenter:

A command chain:

/setblock -3 4 8 air 0 destroy

Do it for all chests and the hopper

/kill @e[type=Item]
/tp @e[type=Item] @p

Then two ways for removing the chest and the hopper out of the inventory of the player:

/gamerule doTileDrops false

Or add this to the chain (But with delay) repeater ... comparator setblock ... Bit advanced

/clear @p minecraft:chest 0 2
/clear @p minecraft:hopper 0 1

enter image description here

| improve this answer | |
  • but how will i get my items back when i reenter the level? – Haroun Mohamed-Fakier May 21 '16 at 15:40
  • @HarounMohamed-Fakier they'll be in the chest – RudolfJelin May 21 '16 at 16:43
  • edited it to your request – Simon Meusel May 21 '16 at 17:51

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