Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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 by Greyscail

  • 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?

  • 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.

  • 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?

  • Author

Solution!! Replace:

 

player.swingArm(EnumHand.OFF_HAND);

with:

player.setActiveHand(EnumHand.OFF_HAND);
player.swingArm(EnumHand.OFF_HAND);

 

  • 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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.