1.15.2 Damage Blocked By Shield

Discussion in 'Spigot Plugin Development' started by OmegaWeaponDev, Feb 27, 2020.

  1. Hi,

    I am currently developing a plugin an I'm wanting to get the damage amount that a player blocks when they raise a shield.

    I've been looking but i'm unable to find a way to get the damage amount that was actually blocked.

    Thanks,
    OmegaWeapon_
     
  2. When using a shield, it blocks all damage that would deal below 4 points of health. (2 hearts)

    When an attack is 4, or more, the incoming damage is reduced by 66%, then rounded to the next lowest int. (Please correct me if wrong here)

    I would recommend getting the damage value from the attacker, then simply reducing that value by around 66% to get the amount of damage dealt, when using a shield.

    For example. A diamond sword does 7 damage by default. So the value of its reduced hit would be 4. Meaning 3 points where blocked. (1,1/2 hearts.)
     
    • Like Like x 1
  3. Reading the minecraft wiki, that doesn't seem quite right. It looks like all attacks are blocked and deal no damage to the player, but the shield is damaged extra for hits above 4 health points.
     
    • Agree Agree x 1
  4. Shields don't outright block all incoming damage, no?

    I know they block out projectiles and their affects (if its poison etc)
     
  5. Using‌[Java Edition only] or Sneaking‌[Bedrock Edition only] causes a player to slow to a sneaking pace, and after 5 game ticks (0.25 seconds), blockable attacks coming from in front of the player are negated, dealing no damage.
     
    • Informative Informative x 1
  6. So what would be the best way to get the damage blocked?

    Get the attacker,
    Get the player blocking,
    Check if player is blocking (Holding the shield using Entity#isHandRaised (Unless there is a better way?))
    if player is blocking get the damage the attacker dealt

    Or would there be a better way to achieve it.

    My end goal for this is to store the total amount of damage a player blocks with a shield.
     
  7. Does #isBlocking() still work? It might be deprecated. I know it had a 6 tick delay or so, but if it still works, that could be your solution.
     
  8. I read somewhere it only does blocking with swords but according to https://hub.spigotmc.org/javadocs/spigot/org/bukkit/entity/HumanEntity.html#isBlocking-- it's all blocking so i'll give it a shot an update this post when I've tested it out.

    https://hub.spigotmc.org/jira/brows...issuetabpanels:comment-tabpanel#comment-21212 This comment does confirm that there is a delay for it, an that is it normal behavior so will not be fixed.
     
    • Like Like x 1