Sinsei Posted March 18 Posted March 18 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. Quote
dee12452 Posted March 19 Posted March 19 (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 March 19 by dee12452 Add boolean check Quote
Recommended Posts
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.