Posted May 4, 20205 yr 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
May 4, 20205 yr 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.
May 4, 20205 yr Author 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.
May 4, 20205 yr 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.
May 4, 20205 yr Author 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
May 4, 20205 yr 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 Have you ever want the new operator to return a type that you didn't ask for? Well, now you can!
May 4, 20205 yr Author 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 May 4, 20205 yr by Babelincoln1809
May 4, 20205 yr 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: Intercept the right-click with a client listener for `InputEvent.ClickInputEvent` Check for your item (if (item instanceof YourItem) is likely best) If this is met: Send a custom attack packet Cancel the event Call `event.setSwingHand(true)` or call it with `false` and manually call `mc.player.swingArm(Hand.OFF_HAND)` 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 May 4, 20205 yr 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.