0

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!

1

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"}}
  • 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

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.