Jump to content

OffHand issues


Babelincoln1809

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • so i just got this crash report and i dont mod a lot so i literally have no idea what to do to fix this
    • Hello, I was trying to play a MOD in my preferred language, but I see that only some items are translated, and I go to debug and I get this information (the only thing that is translated is the bestiary):   [14sep.2024 17:14:36.415] [Render thread/WARN] [net.minecraft.client.resources.language.ClientLanguage/]: Skipped language file: mowziesmobs:lang/es_es.json (com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Expected name at line 394 column 2 path $.config.mowziesmobs.ice_crystal_attack_multiplier) [14sep.2024 17:14:36.421] [Render thread/WARN] [net.minecraft.client.resources.language.ClientLanguage/]: Skipped language file: iceandfire:lang/es_es.json (com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Unterminated object at line 1349 column 4 path $.iceandfire.sound.subtitle.dragonflute)   Is that the reason why everything is not translated? , and is there any way to fix it? Thanks
    • I got my model to render from the models renderToBuffer method. But still not quite what I want. I want to render the model from my renderer's render method. I feel that having access to the renderer and its methods will open some doors for me later down the line. //EntityRendererProvider.Context pContext = ; I want this //ToaPlayerRenderer render = new ToaPlayerRenderer(pContext, false); // if I can get the above line to work, having the methods from the renderer class would be incredibly helpful down the line RenderType rendertype = model.renderType(p.getSkinTextureLocation()); // this should be something like render.getTextureLocation() VertexConsumer vertexconsumer = buffer.getBuffer(rendertype); model.renderToBuffer(stack, vertexconsumer, paLights, 1, 1, 1, 1, 1); // I don't want the render to happen here since it doesn't use the renderer //model.render(p, 1f, pTicks, stack, buffer, paLights); I want to render the model using this It is certainly getting closer though. Probably. I am still worried that even if pContext is initialized this new instance of the renderer class will still hit me with the classic and all too familiar "can't use static method in non-static context"
    • Hello, I am learning how to create Multipart Entities and I tried creating a PartEntity based on the EnderDragonPart code. However, when I tested summoning the entity in the game, the PartEntity appeared at position x 0, y 0, z 0 within the game. I tried to make it follow the main entity, and after testing again, the part entity followed the main entity but seemed to teleport back to x 0, y 0, z 0 every tick (I'm just guessing). I don't know how to fix this can someone help me? My github https://github.com/SteveKK666/Forge-NewWorld-1.20.1/tree/master/src/main/java/net/kk/newworldmod/entity/custom Illustration  https://drive.google.com/file/d/157SPvyQCE8GcsRXyQQkD4Dyhalz6LjBn/view?usp=drive_link Sorry for my English; I’m not very good at it. 
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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