Jump to content

1.20 I need help with making a right click detector that detects when you right click while holding a specific sword


LittleLDude

Recommended Posts

Im gonna make it detect right click then shout out a custom beam here is most of the code in my moditems section I only need the code to detect right clicks atm

package com.littleldude.idleon.item;

import com.littleldude.idleon.IdleOn;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.SwordItem;
import net.minecraft.world.item.Tier;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraftforge.common.ForgeTier;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;

public class ModItems {
    public static final DeferredRegister<Item> ITEMS =
            DeferredRegister.create(ForgeRegistries.ITEMS, IdleOn.MODID);


    public static final RegistryObject<SwordItem> AMAROK_SWORD = ITEMS.register("amarok_sword",
            () -> new SwordItem(Tiers.AMAROK, 0, 0, new Item.Properties()));

    

    public static void register(IEventBus eventBus) {
        ITEMS.register(eventBus);
    }

    public static class Tiers {
        public static final Tier AMAROK = new ForgeTier(10, 10000, 15f, 0,40, null, () -> Ingredient.EMPTY);
    }
}

 

Link to comment
Share on other sites

  • 2 weeks later...

if you have a sword class you should override the method use(Level p_41432_, Player p_41433_, InteractionHand hand) that is called when you hold use key (right mouse button).

Or else you can subscribe to PlayerInteractEvent subclasses: EntityInteractSpecific EntityInteract RightClickBlock RightClickItem

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.