0

Is it possible to detect when a player right-clicks with a stick and activate a command?

What I'm trying to do is have several items with specific NBT data and set it so that right-clicking with those items uses certain commands (for instance, right-clicking with a specific sword will /summon a fireball, or right-clicking with a specific stick will activate a speed /effect). Is there a way to do this in vanilla Minecraft?

  • What's up with the downvote? – DonielF Jun 19 '17 at 3:02
2

dly's answer is fine, but DonielF is right. If you have a mob in you you can't hit anything.

In Minecraft you can't right click and trigger a command with all items. But some items (like carrot on a stick) can be used.

Example:

Type this in chat:

/scoreboard objectives add speed stat.useItem.minecraft.carrot_on_a_stick speed
/scoreboard objectives setdisplay sidebar speed


Run this on a 1 tick clock:
    /effect @p[score_speed_min=1,score_speed=1] minecraft:speed 30 1

This will detect whenever a player right-clicks with a carrot on a stick and it will give him the effect speed 1 for 30 seconds.

It will also work with an empty map (make sure to remove the new map and give the player another empty map!) or when a placed cake is eaten.

|improve this answer|||||
0

It's possible, but not easy.

I know of two ways to do this:

1. Villager + scoreboard objective:

/scoreboard objectives add rightclicked stat.talkedToVillager
/summon Villager ~ ~ ~ {NoAI:1,Invulnerable:1,Silent:1,ActiveEffects:[{Id:14,Amplifier:1,Duration:9999,Ambient:0}],CustomName:"somespecialguy",Offers:{}}

make it "follow" the player: /tp @e[type=Villager,name=somespecialguy] @a

Now you can use the objective rightclicked to execute your command(s).

2. Armor stand

  • Use an item which can be put into the hands of an armor stand
  • Have an (invisible) armor stand constantly teleported to you
  • whenever you right click your tool it will be put into the hand of that armor stand
  • test for the armor stand holding that tool and give another item to you + execute your command(s)
|improve this answer|||||
  • But wouldn't left-clicking then attack the villager/armor stand rather than whatever I'm trying to attack? – DonielF Jun 19 '17 at 11:32
0

In the german Minecraft technic wiki you will find different systems of this. The article is in german, but the commands are listed:

https://technic-de.gamepedia.com/Maschinen/Mausklick-Sensor_(Befehle)

|improve this answer|||||

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.