Jump to content

Recommended Posts

Posted

I created an item with different modes. To cycle through those modes i wanted to use shift left and right clicks with the item in hand. But i cant seem to find a way to hook myself into left clicks.

 

Right clicks are easy:

For right clicks on a Block i can use:

 @Override
 public InteractionResult useOn(UseOnContext pContext)

For right clicks in the air i can use:

@Override
public InteractionResult useOn(UseOnContext pContext)

 

For left clicks on block it also is kinda similar. I can just override this:

@Override
public boolean canAttackBlock(BlockState pState, Level pLevel, BlockPos pPos, Player pPlayer)

But what about left clicks in the air?

 

Obviously i can just say that you can only cycle through the modes when you look at a block, but that feels iffy to me.

Posted (edited)

How about Subscribe to the MouseButton event? That's what I'm using.

ex:

public class ClientEventSubscriber {
  /**
     * Subscribe to Forge-defined events
     * <p>
     * These events will be derived from Event
     */
    @EventBusSubscriber(modid = MOD_ID, bus = EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT)
    public static class ForgeBus {
      
        @SubscribeEvent
        public static void onMouseClickPreEvent(InputEvent.MouseButton.Pre event) {
          final boolean isLeftClick = event.getButton() == GLFW.GLFW_MOUSE_BUTTON_LEFT;
        }
      
    }
}

 

Alternatively you could do on ClientTick `Minecraft.getInstance().mouseHandler.isLeftPressed()`

Edited by dee12452
Add boolean check

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.