Skip to content

Commit 659369a

Browse files
authored
Fix: prevent max health smaller than health (#5988)
1 parent bf13757 commit 659369a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,13 @@ protected void setSpinAttack(boolean value) {
226226
}
227227

228228
public void setHealth(FloatEntityMetadata entityMetadata) {
229-
this.health = entityMetadata.getPrimitiveValue();
229+
// The server can send health value early, causing health to be larger than maxHealth, which can freaks out Bedrock client
230+
// in some weird way, eg: https://github.com/GeyserMC/Geyser/issues/5918 or it could be intentional.... Either way
231+
// we do this to account for it, since currently it seems like Java client doesn't care while Bedrock does.
232+
this.health = Math.max(0, entityMetadata.getPrimitiveValue());
233+
if (this.health > this.maxHealth) {
234+
this.maxHealth = this.health;
235+
}
230236

231237
AttributeData healthData = createHealthAttribute();
232238
UpdateAttributesPacket attributesPacket = new UpdateAttributesPacket();

0 commit comments

Comments
 (0)