Solved - How To Remove Absorption Hearts When Damaging A Player?

  • Home
    • Recent Posts
    • Recent Activity
  • Forums
    • Search Forums
    • Recent Posts
  • Resources
    • Search Resources
    • Most Resources
    • Latest Reviews
  • Wiki
    • Wiki Index
    • Page List
    • Recent Activity
  • Team
    • Administrator
    • Moderator
    • Sponsor
    • Developer
    • Wiki Team
    • Services Moderator
    • Junior Moderator
    • Resources Moderator
  • Downloads
    • Spigot / BuildTools
    • BungeeCord
  • Discord
  • Hub
  • Issues
  • Members
    • Notable Members
    • Current Visitors
    • Recent Activity
    • New Profile Posts
  • Donate
Your username or email address: Password: Forgot your password? Stay logged in SpigotMC - High Performance Minecraft Software Home Forums Spigot Spigot Plugin Development Solved How to remove absorption hearts when damaging a player?

Discussion in 'Spigot Plugin Development' started by Swiftlicious, Sep 2, 2020.

Thread Status: Not open for further replies.
  1. Swiftlicious

    Swiftlicious

    I've tried event#setDamage from EntityDamageByEntityEvent and the player#damage method but neither of them damage a player's absorption amount.. is there another way to do this yet? I did have it using event#setDamage(DamageModifier#ABSORPTION, double amount) but that's deprecated so I would prefer not to use it if it's not the only way.
    #1 Swiftlicious, Sep 2, 2020
  2. Elementeral

    Elementeral

    https://hub.spigotmc.org/javadocs/s...y/Damageable.html#setAbsorptionAmount(double) you can use player#setAbsorptionAmount to set the amount of absorption hearts a player has. (you will have to do your own calculations)
    #2 Elementeral, Sep 2, 2020
  3. Swiftlicious

    Swiftlicious

    Elementeral said: ↑
    https://hub.spigotmc.org/javadocs/s...y/Damageable.html#setAbsorptionAmount(double) you can use player#setAbsorptionAmount to set the amount of absorption hearts a player has. (you will have to do your own calculations)Click to expand...
    setting the player's absorption amount that way won't show the damage animation though.
    #3 Swiftlicious, Sep 2, 2020
  4. Elementeral

    Elementeral

    Swiftlicious said: ↑
    setting the player's absorption amount that way won't show the damage animation though.Click to expand...
    Would setting the event damage to 0 still not show the animation? If not then I think damaging the player by 0 will
    #4 Elementeral, Sep 2, 2020
  5. Swiftlicious

    Swiftlicious

    Elementeral said: ↑
    Would setting the event damage to 0 still not show the animation? If not then I think damaging the player by 0 willClick to expand...
    i'll check that, didn't think about damaging by 0.
    #5 Swiftlicious, Sep 2, 2020
  6. jstnf

    jstnf

    Combining the setAbsorptionHearts and Player#damage(0.0001) would do the trick.
    #6 jstnf, Sep 2, 2020
  7. Swiftlicious

    Swiftlicious

    jstnf said: ↑
    Combining the setAbsorptionHearts and Player#damage(0.0001) would do the trick.Click to expand...
    is there a way to get the absorption health damage taken from doing something like you suggested?
    #7 Swiftlicious, Sep 2, 2020
  8. Elementeral

    Elementeral

    Swiftlicious said: ↑
    is there a way to get the absorption health damage taken from doing something like you suggested?Click to expand...
    You could call EntityDamageEvent, or create your own event. Pass in the damage taken, and it should work.
    #8 Elementeral, Sep 2, 2020
    • Informative Informative x 1
  9. Swiftlicious

    Swiftlicious

    Elementeral said: ↑
    You could call EntityDamageEvent, or create your own event. Pass in the damage taken, and it should work.Click to expand...
    I tried using an entity damage event constructor and it didn't affect the absorption health. I can't use the damage modifier one since that's deprecated. How else would I use the constructor.
    #9 Swiftlicious, Sep 2, 2020 Last edited: Sep 2, 2020
  10. jstnf

    jstnf

    If you don't mind not taking armor into account, then the task of damaging a player with absorption and making it look legit (with animation) could best be done with a custom method. You also wanted the amount of absorption damage taken so I took that into account. Code (Java): public void damagePlayerWithAbsoprtion(Player p, double damage) { double absorptionHealth = p.getAbsorptionAmount(); double newAbsorptionHealth = absorptionHealth - damage; if (newAbsorptionHealth >= 0.0) { p.setAbsorptionAmount(newAbsorptionHealth); } else { p.setAbsorptionAmount(0); // newAbsorptionHealth contains the amount of damage that exceeded the original absorption health p.setHealth(Math.max(p.getHealth() + newAbsorptionHealth, 0.0)); } // Fake a damage animation/sound p.damage(0.0001); // This is the amount of absorption damage that was taken double difference = Math.min(absorptionHealth, absorptionHealth - newAbsorptionHealth); // Do something with difference... Bukkit.broadcastMessage(p.getName() + " took " + difference + " absorption damage!"); } Here it is in action! (Sorry for the initial FPS lag, my PC isn't the greatest)
    #10 jstnf, Sep 2, 2020
    • Agree Agree x 1
  11. Swiftlicious

    Swiftlicious

    jstnf said: ↑
    If you don't mind not taking armor into account, then the task of damaging a player with absorption and making it look legit (with animation) could best be done with a custom method. You also wanted the amount of absorption damage taken so I took that into account. Code (Java): public void damagePlayerWithAbsoprtion(Player p, double damage) { double absorptionHealth = p.getAbsorptionAmount(); double newAbsorptionHealth = absorptionHealth - damage; if (newAbsorptionHealth >= 0.0) { p.setAbsorptionAmount(newAbsorptionHealth); } else { p.setAbsorptionAmount(0); // newAbsorptionHealth contains the amount of damage that exceeded the original absorption health p.setHealth(Math.max(p.getHealth() + newAbsorptionHealth, 0.0)); } // Fake a damage animation/sound p.damage(0.0001); // This is the amount of absorption damage that was taken double difference = Math.min(absorptionHealth, absorptionHealth - newAbsorptionHealth); // Do something with difference... Bukkit.broadcastMessage(p.getName() + " took " + difference + " absorption damage!"); } Here it is in action! (Sorry for the initial FPS lag, my PC isn't the greatest) Click to expand...
    Well from looking at this i would assume that this would be inaccurate for health taken from your regular hearts too then right? could I just add the AbsorptionHealth and the player's getHealth() value to get the total damage overall taken?
    #11 Swiftlicious, Sep 2, 2020
  12. jstnf

    jstnf

    The total damage overall was passed into the method. See parameter "double damage". If you wanted the amount of health that was taken from the regular hearts, it would be (damage - difference) from the code excerpts. Playing around with the variables from the method can get you all kinds of values that you need. Hope this helps!
    #12 jstnf, Sep 4, 2020
    • Winner Winner x 1
Show Ignored Content Thread Status: Not open for further replies. Your username or email address: Do you already have an account?
  • No, create an account now.
  • Yes, my password is:
  • Forgot your password?
Stay logged in SpigotMC - High Performance Minecraft Software Home Forums Spigot Spigot Plugin Development SpigotMC - High Performance Minecraft Software Home Forums Spigot Spigot Plugin Development

Tag » What Does Absorption Do In Minecraft