Jump to content

Recommended Posts

Posted

Getting the offhand to work is.. tricky from what I've been seeing. I'm trying to get my custom weapon to be able to do damage on the offhand as if it were in the mainhand. Like a sword basically. I got it to do the animation, and, although a little buggy, set the damage and speed attributes when it is in the offhand. I just can't get it to actually hit mobs. Here's my code.

 

https://paste.dimdev.org/roxedimuku.java

Posted

That would make sense. Right clicking an entity triggers the Entity#processInitialInteract method or eventually MobEntity#processInteract. I would recommend using the event PlayerInteractEvent#EntityInteract to program in the damage of the offhand item for easy access.

Posted
2 minutes ago, ChampionAsh5357 said:

PlayerInteractEvent#EntityInteract to program in the damage of the offhand item for easy access.

Would I just put in the same code I have for The RightClick Event and add the damage stuff to it? I want the player to still have to right click when using it off hand so they can use say a pickaxe in the other.

Posted
23 minutes ago, ChampionAsh5357 said:

I think you just have to add the damage code to the event. I'm not sure whether the code in the overrided method would execute in the interact event. However, you could always test and make sure.

I mean, it has the damage already when it is in the offhand. I did that through the attribute modifiers, the current issue is getting it to actually just hit when I rightclick. Right now it doesn't do anything, besides play the swing animation

Posted (edited)
37 minutes ago, Vinyarion said:

I recently wrote a mod that allows for true dual wielding attacks, you may want to take some inspiration from this:
https://github.com/SybylineNetwork/Anduril/blob/master/src/main/java/sybyline/anduril/coremods/DualWield.java

 

Thanks! Looking through has made me started to connect some things, but no solution yet sadly. Anywhere I should start looking in the DuelWield class specifically? Or just anywhere, there's a lot lol

Edited by Babelincoln1809
Posted (edited)

You might want to start with the `Client` inner class, and look at the method `public void playerRightClick(InputEvent.ClickInputEvent event)` in particular. This method catches the almost-raw input click and redirects right clicks to attack entities.
It should be noted that this completely redirects inputs to use a custom packet for attacking entities, where I can more easily specify the hand being used and the behavior I want to result. Near the bottom, you will see custom rendering code that displays two mini-sword-icons instead of just one.
Additionally, I am actually injecting a new field of type `DualWield` into the `LivingEntity` class with a coremod. This may or may not be something you want to do for just one item.
In your case, and for only a few items, I might recommend taking the following actions:

  1. Intercept the right-click with a client listener for `InputEvent.ClickInputEvent`
  2. Check for your item (if (item instanceof YourItem) is likely best)
  3. If this is met:
    1. Send a custom attack packet
    2. Cancel the event
    3. Call `event.setSwingHand(true)` or call it with `false` and manually call `mc.player.swingArm(Hand.OFF_HAND)`
    4. In your custom packet, swap the player's held items without resetting the cooldown, call the vanilla behavior, and swap the items back

This would be a lot more lightweight than my implementation, as I am adding a custom Stamina feature.

Edit:
For reference, you may want to take a look at https://github.com/SybylineNetwork/Anduril/blob/master/src/main/java/sybyline/anduril/network/C2SAttackEntity.java. This is how I made sure that the entity was properly attacked, as well as a consideration of the player's reach distance, something that I am a bit surprised that Forge doesn't do. I should probably make a pull/feature/bugfix request at some point about that.

 

Edit 2:

It is essential that the entity is attacked before the arm is swung, as arm swings reset attack cooldown.

Edited by Vinyarion
Packet, ordering

Have you ever want the new operator to return a type that you didn't ask for? Well, now you can!

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.