Jump to content

Recommended Posts

Posted

Is there an existing or accepted way of calling a method on a capability that is attached to armor or items based on update.

For instance, armor has an update method that gets called while the player is wearing it. If I want the update method on my capability called whenever that updated gets called is there an existing or accepted way of doing so or do I need to come up with something?

Current Project: Armerger 

Planned mods: Light Drafter  | Ore Swords

Looking for help getting a mod off the ground? Coding  | Textures

Posted

One way to do it for sure would be to use the PlayerUpdate event, check each wearn armor item if it has ur capability, if it has call the update method.

I dont think you can do this without using events

Posted

Thats what I was think, I was just hoping I was wrong. I am trying to minorly overhaul the damage system.  By adding capabilites to items (tools/weapons/armor) that alter damage done based on Resistances and damage types.

For example leather would help against a cutting edge but would do nothing against a hammer.

This means that essentially any item or armor could have one of these capabilities regardless of the entity that is using/wearing it.

 

Next question:

Since it seems I will likely need to use events for this primarily LivingHurtEvent, when does armor and enchantments get applied to the damage relative to this event?

Current Project: Armerger 

Planned mods: Light Drafter  | Ore Swords

Looking for help getting a mod off the ground? Coding  | Textures

Posted

It gets applied after, which is why I made this method - however, that neat little trick of creating a class in a vanilla package (even though it's still in YOUR mod's folder) doesn't seem to work anymore, see this post.

 

Unless someone knows how to get that to work, your options are either Reflection e.g. to make the method(s) publicly accessible, or to copy/paste those methods (which likely will still require Reflection to make private fields etc. accessible).

 

One thing you may want to think about: if your protection is going to completely nullify the damage received, doing so in LivingHurtEvent still results in the 'hurt' animation / getting knocked back, at least it used to, so you may also want to check in LivingAttackEvent - note that you cannot alter the damage in the attack event, only cancel it or allow it, but it is useful if something gives complete immunity (e.g. evasion).

Posted

What I am planning on doing is have any Resistance capability implement a method for LivingHurtEvent and a method for LivingAttackEvent. In my event handler I will check the Armor slots of the target entity and if any of those have one of the capabilities I will call the respective methods. In the LivingAttackEvent I will check the item/entity that is attacking and if it has on of my damage capabilities and if so I will cancel the event(before checking armor) and re post the event but with the new DamageSource.

Since enchantments/ armor value get applied after this event I might just cancel the livingHurtEvent and apply the damage directly.

Current Project: Armerger 

Planned mods: Light Drafter  | Ore Swords

Looking for help getting a mod off the ground? Coding  | Textures

Posted

Since enchantments/ armor value get applied after this event I might just cancel the livingHurtEvent and apply the damage directly.

I highly advise NOT doing that unless there is absolutely no other way, the reason being that the whole point of the Forge events is mod inter-compatibility, and directly damaging an entity will break that contract and circumvent any number of other mods' damage handlers.

 

Canceling and reposting an event is fine, but usually you can get by with a simple adjustment to the damage amount in the LivingHurtEvent - it is a publicly mutable field of the event class for a reason.

 

Now, if you are talking about the LivingAttackEvent, that'd be the perfect time to cancel and repost with a new DamageSource, e.g. Piercing, Slashing, Bludgeoning, etc. based on the weapon capability / type. At that point, you wouldn't even care about the armor calculations or other resistances as those would be handled in the hurt event.

Posted

I would only include the armor in the livingAttackEvent for the sake of something like evasion or deflection that completely stops damage and doesn't do the damage animation.

 

I suppose I can increase the damage by the amount the armor would block for the case where the armor is ineffective.

Current Project: Armerger 

Planned mods: Light Drafter  | Ore Swords

Looking for help getting a mod off the ground? Coding  | Textures

Posted

To clarify, you don't need to include the armor calculation for things like evasion - that was a bad example, since it is a binary (all or nothing) type of protection.

 

It is useful, however, for things like resistances, e.g. 50% resistance to slashing - well, okay, that takes you to half damage, but now you have to account for the player's armor and potion effects in order to decide if you want to cancel the LivingAttackEvent.

 

You're not changing the damage at this point, nor are you re-posting the event yet again, just deciding if you want to completely negate it to avoid the hurt animation. If there is any damage remaining, you let it all go through to the LivingHurtEvent which then does the same resistance calculations less the armor and potion calculations - those happen during the actual Entity#damageEntity method.

 

Increasing the damage amount during LivingHurtEvent is also fine, e.g. to simulate an armor type that is weak against the damage type, like you mentioned above.

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.