Jump to content

Recommended Posts

Posted (edited)

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
Posted

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?

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

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

Posted

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

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