Support for additional hearts in Player#damage

This commit is contained in:
Felix Cravic 2020-05-26 23:15:09 +02:00
parent e6f38e2773
commit 224a8a3b86
2 changed files with 17 additions and 0 deletions

View File

@ -226,6 +226,22 @@ public abstract class LivingEntity extends Entity implements EquipmentHandler {
entityAnimationPacket.entityId = getEntityId();
entityAnimationPacket.animation = EntityAnimationPacket.Animation.TAKE_DAMAGE;
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);
// play damage sound

View File

@ -252,6 +252,7 @@ public class Player extends LivingEntity {
@Override
public boolean damage(DamageType type, float value) {
// Compute final heart based on health and additional hearts
boolean result = super.damage(type, value);
if (result) {
lastDamageSource = type;