7

I'm making an adventure map where the player re-spawns inside a house when he dies. I'm relatively new to Minecraft, and I've just begun to fiddle with the command block.

What I would like to know: How can I spawn a specific list of items back into a chest after a player is killed?

I already know it can be done, I just haven't figured out how.

Also, is there a way to re-spawn a player's inventory back into a chest?

I used the anvil and renamed the objects I want to put back in the chest, and if the player dies it would be really awesome if the objects could just pop back into the chest inside the player's house.

  • I'm pretty sure there is an option to leave items in a player's inventory on death... – BlaXpirit Jan 26 '14 at 1:11
  • @BlaXpirit There is, but there may be extra items that the asker may not want the player to keep, for whatever reason. If that's not the case however, then /keepinventory true would at least be a temporary fix until the desired solution is found, or possibly a better fix as the user might not notice/look in the chest. – LLF Jan 26 '14 at 1:30
  • 1
    @LLF /gamerule keepInventory true – pppery Aug 17 at 20:34
9

MAKE SURE YOU ARE USING SNAPSHOT 14w04b!

This was solution was untested for any lesser versions!

There are several ways to do this. First, you can do /gamerule keepinventory true, OR, when the player dies, you can spawn specific items in a chest. But that requires much more work. First, make a team using /scoreboard teams add <teamname> and then have the map put the player into the team with /scoreboard teams join <@a,@p,@r,playername>. That creates a team. Now you need to create an objective to track the number of deaths. This can be done by the /scoreboard objectives add <name> <criteria> [internalname (optional)] in this case, you would do /scoreboard objectives add Deaths deathCount. But how will we know when to put items into the chest? Well, you would want a hopper clock (Search on google if you need more info on it) connected to a command block with a test-for to see whether a player has died: /testfor @p[score_Deaths=1,score_Deaths_min=1] The output of the comparator next to it would connect to two command blocks. One with the command /scoreboard players set @a Deaths 0 which has a four tick delay of a repeater. In the other, we will summon a chest with contents into it. This part is the most difficult, because you mustn't only summon the chest, but fill it with items/blocks. This will be the command you will (likely) use:

/setblock <x> <y> <z> minecraft:chest 1 replace {Items:[{id:<itemid>,Count:<amount>,Slot:<slotnumber>},{<repeatstepsforlastbracesformoreitems>}]}

For example:

/setblock ~0 ~1 ~0 minecraft:chest 1 replace {Items:[{id:diamond,Count:1,Slot:0},{id:iron_ingot,Count:16,Slot:1}]} would spawn a chest facing South above the command block with a diamond in the top-left-most slot, and would have 16 iron ingots right next to it. Learning how to use command blocks can be very frustrating, and can become time consuming, especially if you are making a CTF or Team Deathmatch map. Adventure maps are slightly more difficult, only because you will likely spawn a boss, with modified attributes. Also, you want to keep your redstone VERY organized, or it will be difficult to modify (Learned that the hard way...)

Note that chests will face SOUTH when it is spawned, and is recommended a chest is already in the coordinates so that it doesn't look like it magically appeared (Unless you want it to look like that). The command block with that MASSIVE command is activated with a one tick repeater. Please let me know if this was NOT what you were looking for, or if it didn't work! =)

More Questions From Rave

To answer a few more questions, Here is the best way for a hopper clock:

  1. Put a hopper down
  2. Place a hopper facing the other one (Sneak + Click)
  3. Break hopper facing ground
  4. Place a hopper facing the other hopper, so the two chutes are connected
  5. Put a comparator next to it
  6. Put a repeater with a 1 tick delay at the end of the comparator
  7. Toss an item into one of the hoppers, you will notice it begins to work

Hopper Clock on Make A Gif

And how to fix comparators giving out a weak signal with /testfor:

  1. Make sure it isn't in "Subtraction Mode" (Not sure what it does exactly...) (Torch should be off when not powered)
  2. Place a 1 tick repeater next to it

How to look at the coordinates of a block:

  1. Press F3 (Some computers have a binding like mine, Fn + F3)
  2. Look for:
    • x:129.28349208(129)
    • y:56(57.28382 eyes)
    • z:293.138842(293)
  3. In this case, x:129, y:56, and z:293
  • 5
    Nice answer, great detail. – shanodin Jan 26 '14 at 16:47
  • ok, so another question then. I have everything set up except the hooper clock. Can't really find anything good on those. How would you set one up? (to be connected to the command block?) – Rave185 Jan 27 '14 at 1:15
  • sorry, hopper clock. yeesh. ;) – Rave185 Jan 27 '14 at 1:15
  • Ok, one more question. So I have the testfor setup, but the redstone right in front of the comparator is always on, but none of the rest of the redstone is. Why is that? – Rave185 Jan 27 '14 at 14:29
  • & it keeps saying "Found Rave185" – Rave185 Jan 27 '14 at 14:30

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.