Minecraft: Using /execute to detect if a Bottle O’ Enchanting has been thrown

minecraft-commandsminecraft-java-edition

I'm creating an adventure map for Minecraft and I need to use the /execute command with command blocks to detect when a player has thrown a Bottle O' Enchanting (Exp Bottle). If that has happened, the command teleports the player to the coordinates 0 0 0.

I tried the following command but it didn't work: /execute @e[type=ThrownExpBottle] ~ ~ ~ tp @p 0 0 0

Best Answer

Your command is working perfectly fine. Make sure it runs on a clock!

It has a couple flaws though:

  • not multiplayer friendly: You would teleport every player, once a bottle is in the air
  • suspended player: The player will not be able to move until the bottle hits the ground, as you're constantly teleporting him. This is especially bad if you happen to throw a bottle down a high cliff.

But here is an alternative solution, that is more reliable and multiplayer friendly!
The first thing you need to do, is to set up a scoreboard achievement: (type this in chat)

/scoreboard objectives add ExpThrown stat.useItem.minecraft.experience_bottle

This will count the number of times a player has thrown an experience bottle.
The next thing you want to do is to build a clock that activates a command block with the following command:

tp @a[score_ExpThrown_min=1] x y z

That is going to teleport all the players that have thrown an experience bottle to the specified coordinates (replace x, y and z).
Now, place a comparator facing away from that command block, into a new one with this command:

scoreboard players set @a[score_ExpThrown_min=1] ExpThrown 0

That will reset the objective, so that you only get teleported once.