Set damage taking into account the armour

Discussion in 'Plugin Development' started by KingFaris11, Aug 4, 2014.

Thread Status:
Not open for further replies.
  1. Hi, I want to make it so when a snowball hits a player, it damages them the same amount of damage as an iron sword. Though, I know about using event.setDamage() in EntityDamageByEntityEvent, but I don't know how to take into account the damaged player's armour. Is there a way to get the final damage based on their armour?

    I hope there's already a util in the resource section. :S This'd take ages to write if I based it off of:
    http://minecraft.gamepedia.com/Armor#Defense_statistics
     
  2. Offline

    Gater12

  3. Offline

    Gater12

    KingFaris11
    Actually, the code would return a double which represents the percentage of the damage reduced.
    Like how full diamond armor reduces damage by 80% so the code would return 0.8
     
  4. Oh...
    So I'd do something like:
    Code:
    double newDamage = 14 * this.getDamageReduced(damage); // Iron sword does 7 hearts (14 damage)
    if (newDamage <= 0D) newDamage = 1D; // To make sure they definitely do get damaged.
    event.setDamage(newDamage);
    
     
  5. Offline

    Gater12

    KingFaris11
    I would probably go like this:
    Code:java
    1. double reducedPercent = this.getDamagedReduced(damaged);
    2. double reducedDam = 14 * reducedPercent;
    3. double finalReducedDam = 14 - reducedDam;
     
    KingFaris11 likes this.
Thread Status:
Not open for further replies.

Share This Page