Stripping Down EntityDamageEvent - DamageModifier

Discussion in 'API Discussion' started by md_5, Nov 19, 2016.

?

Remove DamageModifier API?

  1. Yes

  2. No

Results are only viewable after voting.
  1. What about reducing damage potion effects from +3 to +1,5? Any way to do this without this API?
     
  2. check damageCause if it's MAGIC then reduce final damage by half

    if you want to make it a bit more specific you need to check if damager is an instance of SplashPotion/LingeringPotion or both with ThrownPotion, use the getEffects() or getItem() and check the PotionMeta
     
    #82 emanon, Jun 28, 2017
    Last edited: Jun 28, 2017
  3. Sorry, I was a bit unspecific. I think this would only work for direct damage potions. I'm trying to reduce the effect of strength 1 and strength 2 potions.
     
  4. why do you need the EntityDamageEvent? ?_?
    just listen for the PlayerItemConsumeEvent, cancel it if the right item (potion) was used and apply the effect yourself with your own parameters.
     
  5. Strength 1 effect gives +3 attack damage, strength 2 +6. For strength 2 potions I could just apply strength 1 effect (would be confusing for players though), how would this work for strength 1 potions?
     
  6. that's a bit more complex,
    you should check on EntityDamageByEntityEvent:
    if the attack is a melee attack by a player
    if the damager has an active potioneffect of strenght,

    if both are true, check which tier (should be 1 for strength 1, 2 for strength 2) finally.... calculate how much damage does the weapon alone and you have the equation:
    result (= the damage you want to set as final damage) = eventFinalDamage * (weaponDamage + yourCustomPotionDamage) / (weaponDamage + vanillaPotionDamage)

    where:
    the result is what you need to set as final damage,
    eventFinalDamage is event.getFinalDamage(),
    weaponDamage is the damage caused by the weapon in the main hand on a full charged attack (remember to add also enchants damage),
    vanillaPotionDamage is the damage caused by potionEffect (Strength I effect gives +3 attack damage, Strength II effect +6 attack damage),
    yourCustomPotionDamage is the damage you want to set as damage bonus for potion effects (if you want to reduce potion bonus by half it's
    Strength I -> +1.5 attack damage, Strength II effect-> +3 attack damage)
     
  7. Thanks, I'm gonna try it out and see if the damage values appear correct. How can I determine weaponDamage value? Is there an API for this or do I have to do it manually with a database? In total however much more annoying than my current setup, where strengthReducePerLevel is a double that can be defined via config:

    Code (Text):
    if (effect.getType().equals(PotionEffectType.INCREASE_DAMAGE)) {

                        double newDamage = e.getDamage(EntityDamageEvent.DamageModifier.BASE)
                                - strengthReducePerLevel * (effect.getAmplifier() + 1);
                        double damageRatio = newDamage / e.getDamage(EntityDamageEvent.DamageModifier.BASE);

                        e.setDamage(EntityDamageEvent.DamageModifier.BASE, newDamage);
                        e.setDamage(EntityDamageEvent.DamageModifier.ARMOR,
                                e.getDamage(EntityDamageEvent.DamageModifier.ARMOR) * damageRatio);
                        e.setDamage(EntityDamageEvent.DamageModifier.MAGIC,
                                e.getDamage(EntityDamageEvent.DamageModifier.MAGIC) * damageRatio);
                        e.setDamage(EntityDamageEvent.DamageModifier.RESISTANCE,
                                e.getDamage(EntityDamageEvent.DamageModifier.RESISTANCE) * damageRatio);
                        e.setDamage(EntityDamageEvent.DamageModifier.BLOCKING,
                                e.getDamage(EntityDamageEvent.DamageModifier.BLOCKING) * damageRatio);
    }
     
  8. Is this still going to be removed? I found "setDamage(DamageModifier)" useful for balancing the armor tiers such that it's not impossible to win even if your opponent has the best armor available. I'm not so sure how I would do it otherwise.
     
  9. ^ That's pretty much what it's useful for
     
  10. I love you <3
     
  11. Is this the end, lads? o_O
     
  12. Wrong thread :p?
     
  13. MiniDigger

    Supporter

    I think he fears that the planed removal described in this thread will happen in 1.13
     
  14. You are correct.
     
  15. I used it once just to see what I can do with it. If you can't replace it I would just remove it. But I wonder how wynncraft and other RPG server will be affected by that
     
  16. All plugins used will have to rewrite their damage handling to be aware of each other. No two plugins affecting the same kind of damage [reduction] will work properly without specifically supporting each other.

    Solely because you cannot see whether an arbitrary plugin has already affected e.g. armor reduction.

    But apparently @md_5 is still planning to get rid of it regardless (considering the responses to this thread, and the deprecation warnings in the documentation - although I haven't checked whether stash contains any work towards replacing this) without providing the API with a suitable alternative.
     
    • Informative Informative x 1
  17. All but the biggest will finally be killed off, likely.
     
  18. Anyone who actually wants this could possibly write their own way around it using reflection, like I did following an example from Foodyling. I needed to find out information such as if a beacon is was turned on but the information I needed was not available in the API. All the information people need is already in memory, all they need to do is get to it and im sure someone will write a plugin to provide this data if its really needed.

    https://github.com/Stuperfied/Util/blob/master/src/main/java/au/com/mshcraft/util/BeaconState.java
     
    • Optimistic Optimistic x 1
  19. Anyone who actually wants sneak detection could possibly write their own way around it using reflection. All the information people need is already in memory, all they need to do is get to it and im sure someone will write a plugin to provide this data if its really needed.

    ^ Why I think we don't need player.isSneaking(), or anything else, in this API.

    Hell, why use an API at all amirite?
     
    • Agree Agree x 1
  20. Since every complex plugin is bloated with NMS code I can't even disagree.
     
    • Like Like x 1