From 334e4fb05928378fecae8dee431a3e78f37d2e67 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Thu, 8 Jul 2021 20:21:21 -0400 Subject: [PATCH] Fix players being 'dead' even with half heart --- .../entity/living/monster/EnderDragonEntity.java | 2 +- .../geysermc/connector/entity/player/PlayerEntity.java | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/monster/EnderDragonEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/monster/EnderDragonEntity.java index 942d006cf..e6491bde5 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/monster/EnderDragonEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/monster/EnderDragonEntity.java @@ -110,7 +110,7 @@ public class EnderDragonEntity extends InsentientEntity implements Tickable { @Override protected AttributeData createHealthAttribute() { // Round health up, so that Bedrock doesn't consider the dragon to be dead when health is between 0 and 1 - return GeyserAttributeType.HEALTH.getAttribute((float) Math.ceil(this.health), this.maxHealth); + return new AttributeData(GeyserAttributeType.HEALTH.getBedrockIdentifier(), 0f, this.maxHealth, (float) Math.ceil(this.health), this.maxHealth); } @Override diff --git a/connector/src/main/java/org/geysermc/connector/entity/player/PlayerEntity.java b/connector/src/main/java/org/geysermc/connector/entity/player/PlayerEntity.java index 7b182da38..5b4e657e9 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/player/PlayerEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/player/PlayerEntity.java @@ -46,6 +46,7 @@ import lombok.Setter; import net.kyori.adventure.text.Component; import org.geysermc.connector.entity.Entity; import org.geysermc.connector.entity.LivingEntity; +import org.geysermc.connector.entity.attribute.GeyserAttributeType; import org.geysermc.connector.entity.living.animal.tameable.ParrotEntity; import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.network.session.GeyserSession; @@ -244,6 +245,13 @@ public class PlayerEntity extends LivingEntity { this.position = includeOffset ? position.add(0, entityType.getOffset(), 0) : position; } + @Override + protected AttributeData createHealthAttribute() { + // Round health up, so that Bedrock doesn't consider the player to be dead when health is between 0 and 1 (half a heart) + // This issue, as of Bedrock 1.17.0, does not appear to persist with any other entity except the ender dragon + return new AttributeData(GeyserAttributeType.HEALTH.getBedrockIdentifier(), 0f, this.maxHealth, (float) Math.ceil(this.health), this.maxHealth); + } + @Override public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { super.updateBedrockMetadata(entityMetadata, session);