How to get the damage caused to a certain area on a players body

Discussion in 'Spigot Plugin Development' started by iCodinqs, Jun 1, 2017.

  1. So at the moment I am trying to code a custom durability module, as I can't use Minecraft one (because I have no idea how to reflect into the item class to use the protected setMaxDurability).

    I am wondering if its possible to check when a player is damaged where they got hit (eg, they got hit in the legs, head, chest etc) so I can deduct the durability away from the armour if they are wearing any armour.

    if it is, whats the code to get the item? As I can't seem to find it on JavaDocs

  2. There is a way to create it if you know the correct height of a player and do your own checks in each place of the body but it won't be 100% correct.
  3. There is not going to be any API code to do this for you.

    One approach I can think of is to raycast each time a player swings their weapon. So you would find the intersection of the player's look direction vector and the hitbox of the target entity, that intersection will be the hit location. From there you can make some determination (maybe just based on Y-value) which armor component was hit.
  4. There is an ItemDamageEvent. You could possibly check if the item damaged is a armor piece, and if so, get the damage amount. And manipulate further.
  5. The problem with this is, it's going to be handled under my custom durability event. As the armor will have the unbreakable NBT Tag on it
    I will try this out, and see what I can get from this :)
  6. If you already have an event which gets the item damaged, can't you just go from there to the armor damaged and the damage amount?