5

I want to make a setup with command blocks that will, if you hold a specific item, elevate you 100 blocks. For example, when you hold an ender pearl named "Sky Orb", you would be teleported 100 blocks up each couple of seconds. I already have the necessary commands:

/scoreboard objectives add Holding dummy
/scoreboard players set @a Holding 0
/scoreboard players set @a Holding 1 {SelectedItem:{id:"minecraft:ender_pearl",tag:{display:{Name:"Sky Orb"}}}}
/tp @a[score_Holding_min=1] ~ ~100 ~ 

Basically, the main problem is the delay. You should only be teleported every 2 seconds or so. Does anyone know a setup for this?

(I'm using the 1.9 snapshots)

5

This can be done by doing some additions to your commands, and introducing a scoreboard operation:

/scoreboard objectives add Holding dummy
/scoreboard objectives add flyTimer dummy
/scoreboard players set #MATH flyTimer 40

/scoreboard players set @a Holding 0
/scoreboard players set @a Holding 1 {SelectedItem:{id:"minecraft:ender_pearl",tag:{display:{Name:"Sky Orb"}}}}
/scoreboard players set @a[score_Holding=0] flyTimer 0
/scoreboard players add @a[score_Holding_min=1] flyTimer 1
/scoreboard players operation @a flyTimer %= #MATH flyTimer 
/tp @a[score_flyTimer_min=10,score_flyTimer=10] ~ ~100 ~

First, we add another score called flyTimer and set its score of a nonexistent player called #MATH to 40. The hash character ensures that this can never be a real player, and it will also not show up if you set the scoreboard display to sidebar.

We use the holding score to increase the timer. This decoupling is necessary because we can "negate" scores in a target selector but not in data tags. I.e. we need it to be able to target players not holding the ender pearl. Note that the flyTimer will reset immediately when swapping to another item.

After the score is increased, we perform a modulo operation on it, using the score of our #MATH dummy. This means that the score is reset to 0 whenever it reaches 40, i.e. every 2 seconds (for other timings, change the score of the #MATH dummy accordingly).

Lastly, we make it so that the teleport command is only executed when the score is exactly 10. This number controls the delay of the teleport after selecting the item in your hotbar. You can tweak this number to suit your needs.

  • I'm sorry, but the setup doesn't work for me. When I hold the ender pearl, I get teleported up multiple times a second. I've tried increasing the #MATH score, but it didn't help. Are you aware that I'm using chain and repeat command blocks and not a setblock or fill clock? – Jaïr Paalman Oct 28 '15 at 18:30
  • @JaïrPaalman you are correct. Since I set the score to -1 every tick, it never increased over 0. I fixed it, but I had to introduce another objective to do it. – MrLemon Oct 29 '15 at 10:01
0

I've also found an answer myself which I find a little easier than the answers I've recieved until now. I've used the following 3 commands:

/scoreboard players add @a Holding 1 {SelectedItem:{id:"minecraft:ender_pearl",tag:{display:{Name:"Sky Orb"}}}}
/execute @a[score_Holding_min=40] ~ ~ ~ /scoreboard players set @p Holding 0
/tp @a[score_Holding=1] ~ ~100 ~

The first command adds 20 points to your score each second, the second command resets that score once a score of 40 has been reached, and the last command teleports you if you have a score of 1.

You can change the amount of blocks you get teleported up by changing the "100" in the last command and you can change the delay by changing the "40" in the second command. Each 20 ticks gives a 1 second delay.

  • You may experience errors when adjusting the commands. I don't know why this happens, but restarting the command block af couple of times seems to help. If you're stuck in the air, use /scoreboard objectives remove Holding and then /tp ~ 100 ~ – Jaïr Paalman Oct 28 '15 at 20:33
  • 2
    You should not be using /execute like this. It only increases the processing the server must do. /scoreboard's target selector should be used instead. /scoreboard players set @a[score_Holding_min=40] Holding 0 – Skylinerw Oct 28 '15 at 23: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.