2

Right click detection

Saniritvikk's Avatar Saniritvikk6/17/22 5:20 pm
2 emeralds 1.5k 12
7/24/2022 10:40 am
lloyddominic26's Avatar lloyddominic26
I would like to add real right click detection like I see in hypixel skyblock when you right click an item you don't need a carrot on a stick so is there any way to do that?
Posted by Saniritvikk's Avatar
Saniritvikk
Level 14 : Journeyman Miner
0

Create an account or sign in to comment.

12

2
07/17/2022 5:40 am
Level 31 : Artisan Engineer
garlicbreathinator
garlicbreathinator's Avatar
There are several items that you can rightclick detect with, Carrot On A Stick is only the most common. You can also use the fungus on a stick and debug stick. The debug stick gives a "use" action you can detect with scoreboards when you rightclick on a block with it, and unless you are opped and in creative it doesn't do anything. This means you can use it as a tool you use on a block by raycasting whenever it is used to find what you used it on, but it has the downside of a permanent enchantment glint that can't be removed.

Throwables can also be used to rightclick detect, but are consumed on use and need to be replaced if you don't plan to make them consumable.

Rightclicking on a villager with an empty trade menu like a nitwit can also be detected, so summoning an invisible villager for you to click works but also creates a hitbox that can block attacks so is not recommended for combat items.
1
07/17/2022 2:43 am
Level 1 : New Network
LAMYR
LAMYR's Avatar
You can give the player a carrot_on_a_stick in the offhand and the carrot_on_a_stick has no texture and you cover the offhand slot. This has the downside,that you can not use shields or totems, etc. in the offhand, but you cann detect right click with any item. Instead of the carrot_on_a_stick, you can also use a warped_fungus_on_a_stick. Hypixel does not use datapacks. They use plugins.
2
06/18/2022 12:43 am
Level 52 : Grandmaster Blob
HoboMaggot
HoboMaggot's Avatar
Not really due to the limitations vanilla minecraft has in place with datapacks.
Other than carrot on a stick, it is either eye of enders or right clicking invisible villagers while holding that item
1
06/18/2022 12:17 pm
Level 14 : Journeyman Miner
Saniritvikk
Saniritvikk's Avatar
How can hypixel do it then? Did they like modifiy the game?
1
07/17/2022 4:34 am
Level 19 : Journeyman Birb
lloyddominic26
lloyddominic26's Avatar
Hypixel (and other huge servers) most likely don't use datapacks as they use a server implementation which allows for the use of plugins.
1
06/18/2022 10:59 pm
Level 52 : Grandmaster Blob
HoboMaggot
HoboMaggot's Avatar
Plugins
2
07/17/2022 5:04 am
Level 19 : Journeyman Birb
lloyddominic26
lloyddominic26's Avatar
Just for everyone's information, this is how Bukkit/Spigot plugins do it, in case you want to do it by coding it on your own:

public class RightClickListener implements Listener {

@EventHandler
public void onRightClick(PlayerInteractEvent event) {
Player player = event.getPlayer();

if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (player.getInventory().getItemInHand().getType() == Material.CARROT_ON_A_STICK) {
// Do something …
}
}
}
}

If you want to change the item (i.e. Carrot on a Stick), change the part where it says:
Material.CARROT_ON_A_STICK
1
07/22/2022 11:27 am
Level 14 : Journeyman Miner
Saniritvikk
Saniritvikk's Avatar
This this right click detection thing you did I have multiple questions 1 can I do this with any item? And 2 can specify a carrot on a stick with like custom model data or something?
1
07/22/2022 1:33 pm
Level 31 : Artisan Engineer
garlicbreathinator
garlicbreathinator's Avatar
This is for bukkit/spigot plugins, so it would not work with a datapack but you can use any item.

If you want to use carrot on a sticks with a datapack, you can use CustomModelData to tell them apart or any other NBT property. In fact, you can write whatever additional NBT values you want to an item like {CustomItem:"fireballWand"} and detect them too.

For that, you want to set up a scoreboard or whatever like normal, then when the scoreboard value = 1+, check if SelectedItem is a carrot on a stick. If it is, read its data to determine what item the player is using and if not check their offhand.
1
07/22/2022 1:19 pm
Level 19 : Journeyman Birb
lloyddominic26
lloyddominic26's Avatar
  1. Yes, you could do it with any item by just replacing the Material labeled in the code as "Material.CARROT_ON_A_STICK".
  2. I don't know if you've noticed or not, but the code I've posted is a Bukkit/Spigot code, which is used for making server plugins. You might be looking for the code for a data pack, which I will assume since you posted this in the Data Packs section.
    I'm not really the right person when it comes to dealing with this stuff as I have no experience with developing data packs. With that said, I might need someone who has data pack knowledge and experience to help you. (HoboMaggot?, garlicbreathinator?, Gamingbarn?)
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome