mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-05 18:32:28 +01:00
Support for additional hearts in Player#damage
This commit is contained in:
parent
e6f38e2773
commit
224a8a3b86
@ -226,6 +226,22 @@ public abstract class LivingEntity extends Entity implements EquipmentHandler {
|
|||||||
entityAnimationPacket.entityId = getEntityId();
|
entityAnimationPacket.entityId = getEntityId();
|
||||||
entityAnimationPacket.animation = EntityAnimationPacket.Animation.TAKE_DAMAGE;
|
entityAnimationPacket.animation = EntityAnimationPacket.Animation.TAKE_DAMAGE;
|
||||||
sendPacketToViewersAndSelf(entityAnimationPacket);
|
sendPacketToViewersAndSelf(entityAnimationPacket);
|
||||||
|
|
||||||
|
// Additional hearts support
|
||||||
|
if (this instanceof Player) {
|
||||||
|
Player player = (Player) this;
|
||||||
|
float additionalHearts = player.getAdditionalHearts();
|
||||||
|
if (additionalHearts > 0) {
|
||||||
|
if (damage > additionalHearts) {
|
||||||
|
damage -= additionalHearts;
|
||||||
|
player.setAdditionalHearts(0);
|
||||||
|
} else {
|
||||||
|
player.setAdditionalHearts(additionalHearts - damage);
|
||||||
|
damage = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setHealth(getHealth() - damage);
|
setHealth(getHealth() - damage);
|
||||||
|
|
||||||
// play damage sound
|
// play damage sound
|
||||||
|
@ -252,6 +252,7 @@ public class Player extends LivingEntity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean damage(DamageType type, float value) {
|
public boolean damage(DamageType type, float value) {
|
||||||
|
// Compute final heart based on health and additional hearts
|
||||||
boolean result = super.damage(type, value);
|
boolean result = super.damage(type, value);
|
||||||
if (result) {
|
if (result) {
|
||||||
lastDamageSource = type;
|
lastDamageSource = type;
|
||||||
|
Loading…
Reference in New Issue
Block a user