1

How can I modify this code to detect a right click when right-clicking a specific block only, without any item in a player hand? This is not like others, for I am not using an Item or I am not right-clicking any object. Just a specific one like a torch, to act like a button. I can use scorebords with this though.

/scoreboard players set @e[type=ArmorStand,name=Activated] action 1 {Equipment:[{},{},{},{},{}]}
/scoreboard players set @e[type=ArmorStand,name=Activated] action 0 {Equipment:[{id:"minecraft:carpet"},{},{­},{},{}]}
/execute @e[name=Activated,score_action_min=1] ~ ~ ~ /setblock XYZ-Coordinates redstone_block
/execute @e[name=Activated,score_action=0] ~ ~ ~ /setblock Same XYZ-Coordinates air
2
  • I believe this is a limitation that minecraft has. There is no way to really detect a right click without having mobs surround a players and doing lots of funky stuff for a system that halfway works. It would be nice if they added a stat that states "times right clicked", but without that or a scoreboard value we can't do it.
    – Judge2020
    Commented Mar 2, 2016 at 3:58
  • I can have a scoreboard. Or are you saying that won't work?
    – Akidus
    Commented Mar 2, 2016 at 5:01

1 Answer 1

1

You can do this using a villager with no trades and a stat.talkedToVillager objective. This is because a villager without trades doesn't show the trade interface at all.

Summon an invisible ArmorStand with an invisible, silent Villager as it's passenger, like this:

/summon ArmorStand <x> <y> <z> {
  Invisible:1b,
  Marker:1b,
  NoGravity:1b,
  Passengers:[{
    id:Villager,
    Silent:1b,
    NoAI:1b,
    Invulnerable:1b,
    Career:1,
    CareerLevel:6,
    Offers:{Recipes:[]},
    ActiveEffects:[{
      Id:14b,
      Amplifier:0b,
      ShowParticles:0b,
      Duration:2147483647
    }]
  }]
}

Copy-paste version of the command:

/summon ArmorStand <x> <y> <z> {Invisible:1b,Marker:1b,NoGravity:1b,Passengers:[{id:Villager,Silent:1b,NoAI:1b,Invulnerable:1b,Career:1,CareerLevel:6,Offers:{Recipes:[]},ActiveEffects:[{Id:14b,Amplifier:0b,ShowParticles:0b,Duration:2147483647}]}]}

The armor stand serves purely as a way to hold the villager in place. Play around with <x> <y> <z> until you find a good position for the villager. I suggest temporarily removing the villager's invisibility effect for "alignment" by replacing 2147483647 with 0.

Now, create your objective

/scoreboard objectives add torchLever stat.talkedToVillager

Use a repeat/chain command block line to run the following commands:

/execute @a[x=X,y=Y,z=Z,r=R,score_torchLever_min=1] ~ ~ ~ <your command>
/scoreboard players set @a torchLever 0

Replace X, Y, Z and R with appropriate values. This is to prevent triggering your torch lever when interacting with any villagers.

4
  • I have not used anything this large and complicated yet, but reading this should work. I will be able to try it later today, and I will get back to you if this works. Thanks.
    – Akidus
    Commented Mar 2, 2016 at 14:40
  • I'm not sure if I did it right. Could you show me an example? With the command set to change the time to day?
    – Akidus
    Commented Mar 2, 2016 at 19:26
  • @Akidus I have created a small testworld showcasing the commands: drive.switch.ch/index.php/s/7X7AaxbZm2YzJYI
    – MrLemon
    Commented Mar 2, 2016 at 20:10
  • I have one more question. I can't figure out how to make it be used again to change it to day and night. But I'm using it with blocks. So, when you hit the block, it will glow. Hit it again, it will go off. How?
    – Akidus
    Commented Mar 3, 2016 at 2:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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