How to spawn items in a chest after a player dies in Minecraft?
Solution 1:
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:
- Put a hopper down
- Place a hopper facing the other one (Sneak + Click)
- Break hopper facing ground
- Place a hopper facing the other hopper, so the two chutes are connected
- Put a comparator next to it
- Put a repeater with a 1 tick delay at the end of the comparator
- Toss an item into one of the hoppers, you will notice it begins to work
And how to fix comparators giving out a weak signal with /testfor
:
- Make sure it isn't in "Subtraction Mode" (Not sure what it does exactly...) (Torch should be off when not powered)
- Place a 1 tick repeater next to it
How to look at the coordinates of a block:
- Press F3 (Some computers have a binding like mine, Fn + F3)
- Look for:
- x:129.28349208(129)
- y:56(57.28382 eyes)
- z:293.138842(293)
- In this case, x:129, y:56, and z:293