What if I told you there was a method of detecting right clicks, that was easier to set up than the carrot on a stick. Hey! If you clicked on this video, I am going to assume that you’re Interested in learning how to detect when someone presses the right mouse button. In the video game Minecraft, using only the commands provided in game. Now mojang has made this really hard, because for some reason they just they don’t want data pack creators to have access to core Functions of the game like clicking or pressing buttons. That would be too much power. So all the ways to detect right click are a little bit jank, and have their own pros and cons. So in This video I’m gonna go over all the ones that I’m aware of, and tell you when you should use them, what they’re good for, and what they’re not good for. So to start off we’re going to be going with the classic right-click detection method of going into your controls Setting the 9th hot bar slot to right-click and then, when a player right-clicks you just detect when their slot is on number nine and um… Okay on to the real stuff. Let’s start with the method all the cool kids are raging about. Carrot on a stick. Now, why should you use a Carrot on a stick to detect right clicks? Well, it’s got its own spot in the statistics page, you can see I’ve used the carrot on a stick 1526 times, which means we can detect that number with commands and whenever it goes up we do something. This is as simple as adding a Scoreboard with “/scoreboard objectives add carrot minecraft.used:minecraft.carrot_on_a_stick”. Then if we set that to display on the sidebar with: “/scoreboard objectives set display sidebar carrot”, and we right click with the carrot on a stick, you can see we have a score of 1. Every Time we right click that’s going to go up 1 more, but before I go and show you how to do that in a data pack let’s just uh let’s just uh. Let’s just consider for a moment the oft-forgotten warped Fungus on a stick. Carrot on a stick is great. It’s a good way to detect things, but it has one fatal flaw. Which is that pigs will be attracted to you when you’re holding it. So if you’re Planning on retexturing this to an awesome sniper rifle and, every time you hold it out around pigs they just follow you around uh that’s that’s not gonna be so good. no no no no no. Many people opt To use the warped fungus on a stick, which leaves pigs completely neutral, however good old striders will still be attracted to you. How often do you see striders versus how often do you see pigs? You gotta pick one if you want to go this method. Although there are other methods later that don’t Involve any of these problems I’ll get to those. So how do you go about actually detecting when this nice old carrot thing on the sidebar goes up? Well I’ll show you, it’s real simple. You’re gonna want to make yourself a nice datapack, just make one here called “right click detection”. Put in your pack and make sure the pack format is correct. If you don’t know how to do any of this stuff, check out my data pack tutorial up in the top right. Okay, I’ve finished setting up my Data pack, following my own tutorial. Here I am in my load.mcfunction it’s always good form to just create your objectives in here. I’m adding the carrot scoreboard every time just just because. Over here in your tick.mcfunction, or any kind of repeating command, We’re going to just use a simple execute command. “execute as @a if score @s matches 1..” If you’re not sure about all this execute stuff, I’ve got an execute tutorial. And then we’re just gonna add “run say Click!”. So this should, if they have clicked their carrot at least once, It should say click in the chat. So let’s go in game. Now you can see our chat is absolutely filled with the word Click!, if I say something it it’s just gone. That’s because we’re never setting Our carrot score back to zero, it’s just staying above 1 at all times, so let’s fix that. Here in our tick.mcfunction we’re actually going to break this carrot thing out into its own function. So if They have more than one click, then we’re going to call function:carrot. A fun thing you can do with the Data Pack Helper+ extension in VSCode is you can hit control + period, to open up this little dialog box on a function you haven’t created. And then just click create tutorial carrot in The same data pack, and there it is. It’s just been automatically generated for us. Now in here, this is where we are now going to say Click!, and then we are going to set our scoreboard back To zero “scoreboard players reset @s carrot”. Now I’m using reset not set 0. This is not a big deal, I just like this more. It doesn’t technically set it to 0 it sets it to nothing. So now if we Go in game and reload after saving. You’ll see we say Click! once and then it stops. So let’s test this out with our carrot. Every time we click you can see it appears on the scoreboard for like 0.1 seconds. We’re detecting right clicks, it’s amazing! You can now run whatever code you want In our carrot.mcfunction here. You could summon a sheep. [excited noises] oh. Actually you can’t summon a sheep, because we’re missing an @s. I’ve used data packs before. We had to set our position here with “at @s”. Now we can summon a sheep, amazing. One of the most popular things For certain kinds of map making is to put the carrot or fungus in your offhand only when you’re holding a certain item. So if you want to detect when you’re holding, say a diamond, just make it so whenever you select the diamond the carrot on a stick magically appears in your Offhand. And then you can just texture it so that there is absolutely nothing in your offhand, and you just hide the slot. The commands for it pretty much just look like this. You can copy and paste the commands from the description. Okay, that’s enough of carrot- and fungus on a stick Type detection. Let’s get into the more spicier stuff. Hey you know it just occurred to me, that not everybody has this button bound to right click. Maybe I should call this a use item / place block detection tutorial. You know what else not everyone has done? Subscribe to the legitimoose Channel on youtube.com/legitimoose. That’s right, it’s me, you’re watching legitimoose. Please press gently the subscribe button, with whichever button or key you have bound to main click. There are a couple of archaic methods that involve detecting right clicks on entities, such as a villager. There is a scoreboard statistic called “minecraft.custom:minecraft.talked_to_villager”, And you can use this to detect whenever you open the trade menu of a villager. But wait, it gets better. Even if a villager like this doesn’t have any trades, it will still count as talking to the villager in the sidebar over here. So we can actually detect whenever you talk To a villager. This is useful for when you don’t want to be tied to a specific item, like a carrot or fungus on a stick, but rather tied to like a specific location. We summon a villager here that Is NoAi and Silent with this command, command in the description. Whenever we right click this guy we’ll be able to get our number up. Now we could put him, for example, inside a block that we want To detect right clicks on. Of course you’d want to make this guy invisible, but I trust you know how to do that. The commands for this method are virtually identical to the commands for the carrot On a stick section. So just do that, but change out every instance of “carrot on a stick” with “talked_to_villager”, and you’ve got yourself a working right click detection. Okay, what’s next? There is a certain circumstance where the best kind of right-click detection you can have, Is detecting when you give an item to an armor stand. So I’d like you to think to yourself: What advantages could this have over the other methods? The main one is that you can detect what item you right-clicked with. So if I right-click with a flower, I can now detect that this armor Stand is holding a flower which means obviously somebody right clicked on it. Now, a slightly more difficult question is who is that somebody? The answer is it’s actually pretty much impossible to find out with a hundred percent certainty as far as I’m aware. Your best bet is just gonna be The nearest player, but if you’re in multiplayer, this has a high chance of being jank, but if you want to detect when an armor stand is holding an item this is the command for it. “execute as @e[type=armor_stand,nbt={HandItems:[{id:”minecraft:poppy”},{}]}] At @s run whatever code you want to”. This is quite a big chunk of code to be writing off the top of your head. Like I just did, So I’ve put it down in the description for you to copy and paste And write whatever you want into it. And it’s not my favorite, but it is popular. I’ve seen that there are other tutorials on youtube that say this is the way to do it I disagree. What if I told you There was a method of detecting right clicks that was easier to set up than the carrot on a stick. Several times faster, more precise, and more lag friendly. That’s right, we’re gonna talk about the black sheep of right-click detection. Ender eye detection. First off, why would you want to Detect the right click of an ender eye over right clicking with a carrot on a stick or a fungus on a stick? It is fast. Now, what does that even mean? Well keep an eye on that scoreboard on the right Side of the screen. If I hold down right click with a carrot on a stick, you can see it increases at a moderate pace, but if I wanted to detect whether or not I am holding down right click right Now that would be kind of a challenge. Now let’s switch over to this eye of ender I’ve rigged up and hold down the right click button. Now it increases the number every single tick. 20 ticks per second baby. How do you set this up? There’s not a scoreboard objective for detecting Throwing an eye of ender. What you have to do, is use an advancement. Good old reliable misode.github.io, link in the description. All right, here we are. We’re going to just slap together an ender eye detection thingy. Under criteria I’m going to type in a name. Eye… Doesn’t really matter. Hit the plus button. Then I’m going to select my criteria down here, scroll to the bottom. Weirdly enough, it’s not “used under eye”. That is not going to work for our purposes. No no, you want “using item”. Add a condition, and add An item to that condition. Then click the plus next to items and type in “minecraft:ender_eye”. Alright this is our advancement, this is going to activate whenever we right click with an eye of ender. Now in order to have this call a function, we have to add a reward. Which right here, There is a spot called function. You can name your function anything you want, just make sure it’s the same in your data pack. Then we’re gonna go over here, copy our advancement go into ye olde visual studio code. And maybe add a scoreboard for this. “scoreboard objectives add eye dummy, Just in our load.mcfunction. Now if you don’t have an advancements folder in your namespace, you’re going to need to create one. Click on your namespace and make sure functions is not selected, the namespace. And add a folder called advancements. Inside this create a folder call it I don’t know eye.json, and paste in your advancement. Beautiful we got some errors over here, those are not real. Now we’re going to create our function called eye.mcfunction, and in here is the code that’s gonna run whenever we right click. So the first Thing you have to do is reset the advancement. Because you can only get an advancement once. So after you have received it, you’ll just have to reset it. In this case with “advancement revoke @s only tutorial:eye”, or whatever your function was called. Then we can do whatever code we want. In this case I’ll just do “scoreboard players add @s eye 1”. Now in game I’m gonna reload, set eye to my sidebar and hold down right click. And there we go, it’s counting, up every time we right click it does that. You don’t really have to bother with resetting the score here because You don’t even need to track a score. You could just, oh, you could summon a sheep every time. There we go. This is true power. So now that I’ve taught you the perfect method of right-click detection, let me just quickly tell you why this is pretty obviously not the perfect Method of right-click detection. It’s an eye of ender, you throw it it goes to the stronghold! It gets consumed when you right-click, this doesn’t work in survival. Shhhh. It only works in worlds that doesn’t have a stronghold. You will see that me right-clicking, Shows up in the chat. It works perfectly, it doesn’t consume the item, it doesn’t get thrown towards the stronghold. That’s because there is no stronghold in this super flat world. If you ever want to use your data pack in a world that has a stronghold. If you’re Making something for normal survival, uh yeah, that’s not gonna work. Okay now you’re a right-click detection god. Uh, see you in the next one Bye-Bye ๐ Video Information
This video, titled ‘Minecraft Right Click Detection [1.19] Several Ways’, was uploaded by Legitimoose on 2021-09-14 13:00:00. It has garnered 108334 views and 4421 likes. The duration of the video is 00:13:11 or 791 seconds.
Learn all about right click detection in vanilla Minecraft 1.17/1.18/1.19! I’ll show you several methods (carrot on a stick, armor stand, villager, eye of ender, and more!*) Detecting right clicks is very useful for basically any project, ranging from custom guns/weapons, interactive menus, or… literally anything you want to be able to click. A must know! ;^)
Advancement Generator: https://misode.github.io/advancement/
Chapters: 0:00 – Intro 0:44 – 10,000 IQ Method 1:02 – Carrot on a Stick vs. Warped Fungus on a Stick 2:38 – How to Code Carrot/Warped Fungus Detection 5:19 – Detecting Any Item (w/ Carrot on a Stick) 5:49 – subscribe ๐ 6:17 – Villager Method 7:24 – Armor Stand Method 8:50 – BEST Method?!?! (Eye of Ender Method)
CARROT/WARPED FUNGUS ON A STICK COMMANDS: scoreboard objectives add carrot minecraft.used:minecraft.carrot_on_a_stick OR scoreboard objectives add carrot minecraft.used:minecraft.warped_fungus_on_a_stick ^ you should probably change this to “fungus” or something
execute as @a if score @s carrot matches 1.. at @s run function tutorial:carrot (Make sure to change “tutorial:carrot” to your function name!)
scoreboard players reset @s carrot
PUT CARROT IN OFFHAND WHEN HOLDING ITEM (in this case, a diamond): execute as @a[nbt={SelectedItem:{id:”minecraft:diamond”}}] run item replace entity @s weapon.offhand with carrot_on_a_stick execute as @a[nbt=!{SelectedItem:{id:”minecraft:diamond”}}] run item replace entity @s weapon.offhand with air
ARMOR STAND METHOD: execute as @e[type=armor_stand,nbt={HandItems:[{id:”minecraft:poppy”},{}]}]at @s run say detect! (Replace “say detect!” with running a function that does whatever you want!)
My eye.json file (don’t forget to change the function at the bottom): { “criteria”: { “eye”: { “trigger”: “minecraft:using_item”, “conditions”: { “item”: { “items”: [ “minecraft:ender_eye” ] } } } }, “rewards”: { “function”: “tutorial:eye” } }
=== l o n k s === Discord Server [ https://discord.gg/n7z4sVG ] Twitter [ https://twitter.com/Legitimoose ] Twitch [ https://www.twitch.tv/legitimoose ] My Editor [ https://www.youtube.com/channel/UC09ZSJRaKiM4cHQmqu27osA ]
*that is actually how many i’ll show you yes** **but don’t forget warped fungus on a stick