I'm currently making a custom map in Minecraft, and I'm a bit new to command blocks. I'm trying to have the player put on a player head named "Training Helmet" and then as soon as they put it on they are teleported to a certain coordinate. This is what I have been tying, but it's not working for me (obviously).

In the first command block (repeating, unconditional, activated with a lever):

/testfor @p {Inventory:[Slot:103b,id:"minecraft:skull"{SkullOwner: dannymastr9000},tag:{display:{Name:"Training Helmet"}}}]}

In the second command block (repeating, conditional, always active):

/tp @p -160 102 60

Any Idea on how to fix it? Thanks!

  • @pppery While these questions look very similar, this one appears to be a "this is my setup, what is wrong?" question rather than a question about how to mark or modify a player based on an item in their inventory. I'm sure that the question you chose is helpful for this topic, it maybe even would solve the problem for the person asking this question, but it isn't really a duplicate. – user232393 Aug 28 '19 at 6:30
  • @bearb001 But both questions ultimately seek the same solution. This question can be answered by checking what went wrong compared to the workable solution given as an answer in the suggested duplicate. – Joachim Aug 28 '19 at 12:33
  • @Joachim I'm not nessessarily against closing this question as a duplicate (I skiped this question in the queue if I remember correctly), this question is not fully answered with the answers from the other question, but this question is outdated anyway and relatively localized, the user asking this question hasn't been online for 2 years and someone who finds this question is likely more helped by the other question. All I'm saying is that this technically isn't a duplicate. – user232393 Aug 28 '19 at 16:00
  • @bearb001 I agree, and it happens frequently that they are closed as duplicate. At times, it is a thin line. Then again, in some situations it's preferable to have canonic questions and get additional specific answers or even comments there. – Joachim Aug 28 '19 at 16:16

So I see a few issue with what you're doing. First, make the second command block a chain command block. What you're doing right now is pretty close to undefined behaviour (I think it is defined, but it's definitely not what you're intending).

Secondly, your /tp command is not going to play nicely with multiple players. This is why I strongly encourage people learning commands for the first time to stay away from /testfor, and learn the scoreboard instead.

With these bits of advice, we can get to a full solution. You're going to need 3 command blocks in a chain, the first being a repeating command block followed by 2 chain command blocks. In this instance, you're going to want the chain command blocks to be always active (you can get into some much more advanced stuff later with bigger command block contraptions with them set to need redstone, but that's well out of the scope of this problem), but you can leave the repeating command block as needs redstone in order for you to be able to toggle it.

The commands you're going to need are as follows:

/scoreboard players tag @a remove TrainingHelmet
/scoreboard players tag @a add TrainingHelmet {Inventory:[{Slot:103b,id:"minecraft:skull",tag:{display:{Name:"Training Helmet"}}}]}
/tp @a[tag=TrainingHelmet] -160 102 60

So what do these commands do? Let's work from the end. The last command teleports all players that have the TrainingHelmet tag. The second command adds the tag to the appropriate players, by testing if the item type and name match (testing against the owner is a little difficult). Since we only want to teleport players when they have the helmet on, we remove the tag from everyone in the first command.

This introduces a problem though: when they have the hat on, they'll be continuously teleported to the training location. That might not be what you want. There's a few ways around this. One is to restrict the /tp command to not run on players in a certain area, for instance changing the target selector to @a[tag=TrainingHelmet,x=-160,y=102,z=60,rm=20] will exclude anyone within 20 blocks (straight line) of the destination. Another is to remove the hat from their inventory after they're teleported with the following command:

/clear @a[tag=TrainingHelmet] minecraft:skull -1 -1 {display:{Name:"Training Helmet"}}
| improve this answer | |
  • Thank you so much! This is EXACTLY what I need. I also have another question- do you know about some sort of command block tutorial? When I research commands, I normally only find specifics, and I hate simply copying and pasting commands without knowing how they work. I'd like to write my own codes (however you explained the whole idea beautifuly, and helped me understand everything). That would be extremely helpful! And thanks again for the explanation! – user187830 May 27 '17 at 0:40
  • This is slightly outdated, but probably one of the best tutorial series I've seen. Some of the best practices have changed since these were made, but most of it is still very relevant. Also, since this helped, you can show that to others by clicking the check mark beneath the answer score. – MBraedley May 27 '17 at 2:10

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