Posted November 12, 20177 yr I've literally tried everything, I don't get any errors and the function just doesn't work like it's supposed to. private static final int LMB = 0, RMB = 1; @SubscribeEvent public static void dualWield(MouseEvent event) { if (event.getButton() == LMB) { EntityPlayerSP player = Minecraft.getMinecraft().player; ItemStack mainhand = player.getHeldItemMainhand(); ItemStack offhand = player.getHeldItemOffhand(); if (offhand.getItem() instanceof ItemSword) { if (mainhand.getItem() instanceof ItemSword) { player.swingArm(EnumHand.OFF_HAND); } else { // player.setHeldItem(EnumHand.MAIN_HAND, offhand); // player.setHeldItem(EnumHand.OFF_HAND, mainhand); } } else { return; } } } When in game and I have a sword in my mainhand and offhand and attack it very rarely swings the sword in the offhand. If it didn't work at all then I'd think my code was wrong but it works rarely and even when I simplify it to be: private static final int LMB = 0, RMB = 1; @SubscribeEvent public static void dualWield(MouseEvent event) { if (event.getButton() == LMB) { EntityPlayerSP player = Minecraft.getMinecraft().player; oplayer.swingarm(EnumHand.OFF_HAND); } } It still only works when it wants to. Edited November 12, 20177 yr by Greyscail
November 12, 20177 yr Author So I tried binding it to the right mouse button instead and that works, so I guess having the offhand arm swinging conflicts with the mainhand arm swinging during an attack. Is there a way to prevent the mainhand arm from swinging during an attack?
November 12, 20177 yr Author 45 minutes ago, diesieben07 said: You must check whether the mouse button was actually pressed. MouseEvent fires whenever there is a mouse event, this includes mouse movement. Only if MouseEvent::isButtonstate (terrible name, but what can you do) is true, a mouse button was actually pressed. With your code you are basically telling the game to swing the arm every tick. Thanks for pointing that out but it still didn't solve my issue, I think it's that swinging the offhand conflicts with the default attacking animation if they happen simultaneously.
November 12, 20177 yr Author 2 minutes ago, diesieben07 said: Yes, I realize what you are trying to do now. The default swinging code can only handle one swinging arm at a time. I see, I've noticed under EntitiyPlayerSP there's two commands, namely resetActiveHand() and stopActiveHand(), I haven't gotten either of them to work like I thought they would.. Any ideas? or is this truly not possible?
November 13, 20177 yr Author Solution!! Replace: player.swingArm(EnumHand.OFF_HAND); with: player.setActiveHand(EnumHand.OFF_HAND); player.swingArm(EnumHand.OFF_HAND);
November 13, 20177 yr Author @diesieben07 I got it to where the offhand is swung, is there a simple command in the api to simulate the player attacking? Like, a function I could call that makes the character attack forward without actually clicking the attack key
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.