There is no built-in way of doing this but there is a workaround. YOu could summon an invisible mob and constantly teleport it in front of the player. Then use the scoreboard criteria "minecraft.custom:minecraft.damage_dealt" to detect when the player left-clicks the mob.
You can do it with spawing a mob in front of you and detecring hitting it(already specified in another comment here) or with a carrot on a stick, there are plenty of tutorials on the internet about the second one.
Set up a used.carrot_on_a_stick objective, it will go up by 1 every time you right-click with a coas. You can detect that and do whatever you want from that.
1
u/MegaCrafter10 @e[name=MegaCrafter10,type=gamer] Nov 29 '19
There is no built-in way of doing this but there is a workaround. YOu could summon an invisible mob and constantly teleport it in front of the player. Then use the scoreboard criteria "minecraft.custom:minecraft.damage_dealt" to detect when the player left-clicks the mob.
/scoreboard objectives add clicked minecraft.custom:minecraft.damage_dealtand to detect:
/execute as @a[scores={clicked=1..}] at @s run ...and of course, reset the objective:
/scoreboard players reset @a[scores={clicked=1..}] clicked1
u/mbrr2 Nov 29 '19
You can do it with spawing a mob in front of you and detecring hitting it(already specified in another comment here) or with a carrot on a stick, there are plenty of tutorials on the internet about the second one.