Solved - How To Remove Absorption Hearts When Damaging A Player?
Maybe your like
- 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
Discussion in 'Spigot Plugin Development' started by Swiftlicious, Sep 2, 2020.
Thread Status: Not open for further replies.-
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 -
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 -
Swiftlicious
Elementeral said: ↑
#3 Swiftlicious, Sep 2, 2020https://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. -
Elementeral
Swiftlicious said: ↑
#4 Elementeral, Sep 2, 2020setting 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 -
Swiftlicious
Elementeral said: ↑
#5 Swiftlicious, Sep 2, 2020Would 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. -
jstnf
Combining the setAbsorptionHearts and Player#damage(0.0001) would do the trick.
#6 jstnf, Sep 2, 2020 -
Swiftlicious
jstnf said: ↑
#7 Swiftlicious, Sep 2, 2020Combining 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? -
Elementeral
Swiftlicious said: ↑
#8 Elementeral, Sep 2, 2020is 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.-
Informative x 1
-
-
Swiftlicious
Elementeral said: ↑
#9 Swiftlicious, Sep 2, 2020 Last edited: Sep 2, 2020You 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. -
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 x 1
-
-
Swiftlicious
jstnf said: ↑
#11 Swiftlicious, Sep 2, 2020If 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? -
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 x 1
-
- No, create an account now.
- Yes, my password is:
- Forgot your password?
Tag » What Does Absorption Do In Minecraft
-
What Does Absorption Do In Minecraft? - Sportskeeda
-
Absorption - Minecraft Wiki - Fandom
-
Absorption | Minecraft Wiki | Fandom
-
Absorption In Minecraft - DigMinecraft
-
What's The Difference Between Absorption And Health Boost? - Reddit
-
How To Craft Absorption - Minecraft
-
What Does Absorption Do? | Hypixel - Minecraft Server And Maps
-
Absorption Bug - Extra Hearts With No Effects/Attributes | Minecraft
-
Minecraft: Every Status Effect & How To Get Them - Game Rant
-
Natural Absorption - Mods - Minecraft - CurseForge
-
Leeching/Absorbing (Enchantment) - Minecraft Feedback
-
Absorption Effects Overlapping Causes Them To Become Permanent
-
Why Did I Get Absorption Hearts? - Survival Mode - Minecraft Forum
-
Useful Armor - Absorption Addon Minecraft Data Pack