Is there anyway to detect for a right click and then run a command afterwards? For example, right clicking an item which turns u invisible for ten seconds? Just wondering.
Depends on which item you want to right click. Or if you want to make things a bit tricky and other abilities less functional, you can do it with any item.
Yes but DarkClaw1001 wants to detect right clicking. The 'stat.useItem' criteria for items will only go up when the item is used, not necessarily when right-clicked. For example you couldn't use `stat.useItem.diamond_sword`. It would not go up when right clicked, it would only go up if you attack with it and the attack does damage. Since right clicking a carrot on a stick is 'using' it, it goes up when right clicked.
See my answer. For other items like a stick or something, there is no good way to do that. But, depending on your project, you can change the texture of a carrot rods.
You can use an invisible, invulnerable armor stand always at the player's position and detect when the specific item is placed on the stand. Note this is not a good method though... Like I said earlier, you will lose other functionality, like left clicking, or right clicking buttons/chests/etc... Of course, you can make the armor stand only appear there while the player has the specific item in their hand, but still it isn't a perfect solution.
You could also use an invisible villager with no trades at the players position and use stat.talkedToVillager. Tag the player based on the item they are holding and run commands based on their tag and talkedToVillager score. However both the villager and ArmorStand methods come with draw backs. Most were mentioned but the biggest one I see is the fact that it won't work if the player is moving while right clicking, assuming you are teleporting the entity to the player, since there is always latency when using /tp and /teleport
With the stat.useItem.minecraft.wooden_sword scoreboard objective type, you can track when a player attacks with the sword. It might also increase when breaking blocks with them (like spider webs, leaves, or anything really.) According to the wiki, the stat will increase any time a player uses the sword in a way that should cause damage to it, regardless of unbreaking attributes.
Ok, so you want to choose a class... what you can do is use helmets, that when you right click, you put then in your head, so you can detect that..
example: You have two classes, Tank and Archer... to select, there will be two helmets in your hand, a Diamond one (renamed Tank Class) and a Gold one (renamed Archer Class). Then you will only have to detect when he puts a diamond/gold helmet. Note: to use diamond helmet in a gameplay, you will have to detect not only a type of helmet, but a renamed helmet... or a helmet with custom tag.
Rollback Post to RevisionRollBack
You know that you are lazy when you do a program to write a program
This part of the thingo is easy. I've sorted out how u pick ur class. The assassin class has a invisibility power, so I wanted the player to right click an item and then become invisible for 10 seconds or something like that
This is for using a carrot on a stick to teleport when used (Java 1.20.4). This should work for other commands if you replace the "tp" part on command block 2 with another command, but I can't be sure.
Command block 1 - Activates when player first presses a button - Impulse - Unconditional- Needs Redstone
: sets the objective named "click" for when the carrot on a stick is used, and that using it increases the score by 1. The objective can be any name but the name must be consistent with where I use "click" in the following commands.
Command block 2 - Located away from command block 2 - doesn't need redstone or player activation - repeat - unconditional - always active
execute if score @p click matches 1 run tp @p -9 73 55
: if the carrot on a stick is used once, this checks for that score of 1 and runs the teleport command. The next command will reset that score so it can be repeated on the next use
Command block 3 - Directly next to command block 2, I think at least the arrow on the face of command block 2 needs to be pointing towards this
- chain - conditional - always active
scoreboard players reset @p click
: This resets the score to 0 so that on the next use the score becomes 1, the teleport command runs, and the score then becomes 0 again so it can infinitely repeat
Is there anyway to detect for a right click and then run a command afterwards? For example, right clicking an item which turns u invisible for ten seconds? Just wondering.
Depends on which item you want to right click. Or if you want to make things a bit tricky and other abilities less functional, you can do it with any item.
As an item, use a CarrotOnAStick. Create a scoreboard to track it's usage:
Now make a clock which gives you the effect and resets the score:
My projects: https://blockbench.net/hub
Note that it doesn't have to be a carrot on a stick, you can use any of the items listed under "stat.useItem" here: http://minecraft.gamepedia.com/Scoreboard#Criteria
Thanks,
But has the item got to be one which u right click?
Yes but DarkClaw1001 wants to detect right clicking. The 'stat.useItem' criteria for items will only go up when the item is used, not necessarily when right-clicked. For example you couldn't use `stat.useItem.diamond_sword`. It would not go up when right clicked, it would only go up if you attack with it and the attack does damage. Since right clicking a carrot on a stick is 'using' it, it goes up when right clicked.
Yeah, I want to detect right click for items which u don't use
So does anyone know how to do this?
See my answer. For other items like a stick or something, there is no good way to do that. But, depending on your project, you can change the texture of a carrot rods.
My projects: https://blockbench.net/hub
You can use an invisible, invulnerable armor stand always at the player's position and detect when the specific item is placed on the stand. Note this is not a good method though... Like I said earlier, you will lose other functionality, like left clicking, or right clicking buttons/chests/etc... Of course, you can make the armor stand only appear there while the player has the specific item in their hand, but still it isn't a perfect solution.
You could also use an invisible villager with no trades at the players position and use stat.talkedToVillager. Tag the player based on the item they are holding and run commands based on their tag and talkedToVillager score. However both the villager and ArmorStand methods come with draw backs. Most were mentioned but the biggest one I see is the fact that it won't work if the player is moving while right clicking, assuming you are teleporting the entity to the player, since there is always latency when using /tp and /teleport
Hmmm... Thankyou for all these ideas. I shall see what I can do.
Is there anyway to detect when you hit a monster with a sword or other items?
With the stat.useItem.minecraft.wooden_sword scoreboard objective type, you can track when a player attacks with the sword. It might also increase when breaking blocks with them (like spider webs, leaves, or anything really.) According to the wiki, the stat will increase any time a player uses the sword in a way that should cause damage to it, regardless of unbreaking attributes.
I would recommend using a spawn egg.
You could use a rare mob that spawns when you right click the spawn egg. That way you can target the mob and kill it.
What about when your holding a specific item? This is for a dungeon map which you pick a class.
Ok, so you want to choose a class... what you can do is use helmets, that when you right click, you put then in your head, so you can detect that..
example: You have two classes, Tank and Archer... to select, there will be two helmets in your hand, a Diamond one (renamed Tank Class) and a Gold one (renamed Archer Class). Then you will only have to detect when he puts a diamond/gold helmet. Note: to use diamond helmet in a gameplay, you will have to detect not only a type of helmet, but a renamed helmet... or a helmet with custom tag.
You know that you are lazy when you do a program to write a program
Hmmm...
This part of the thingo is easy. I've sorted out how u pick ur class. The assassin class has a invisibility power, so I wanted the player to right click an item and then become invisible for 10 seconds or something like that
What do you mean clock o_O
This is for using a carrot on a stick to teleport when used (Java 1.20.4). This should work for other commands if you replace the "tp" part on command block 2 with another command, but I can't be sure.
Command block 1 - Activates when player first presses a button - Impulse - Unconditional- Needs Redstone
scoreboard objectives add click minecraft.used:minecraft.carrot_on_a_stick
: sets the objective named "click" for when the carrot on a stick is used, and that using it increases the score by 1. The objective can be any name but the name must be consistent with where I use "click" in the following commands.
Command block 2 - Located away from command block 2 - doesn't need redstone or player activation - repeat - unconditional - always active
execute if score @p click matches 1 run tp @p -9 73 55
: if the carrot on a stick is used once, this checks for that score of 1 and runs the teleport command. The next command will reset that score so it can be repeated on the next use
Command block 3 - Directly next to command block 2, I think at least the arrow on the face of command block 2 needs to be pointing towards this
- chain - conditional - always active
scoreboard players reset @p click
: This resets the score to 0 so that on the next use the score becomes 1, the teleport command runs, and the score then becomes 0 again so it can infinitely repeat
Hope this helps!!!