Fix health edge case
If the java server sent a health value between 0 and 1, the player would die in the bedrock client
@@ -40,8 +40,9 @@ public class JavaPlayerHealthTranslator extends PacketTranslator<ServerPlayerHea
if (entity == null)
return;
+ int health = (int) Math.ceil(packet.getHealth());
SetHealthPacket setHealthPacket = new SetHealthPacket();
- setHealthPacket.setHealth((int) Math.ceil(packet.getHealth()));
+ setHealthPacket.setHealth(health);
session.getUpstream().sendPacket(setHealthPacket);
float maxHealth = entity.getAttributes().containsKey(AttributeType.MAX_HEALTH) ? entity.getAttributes().get(AttributeType.MAX_HEALTH).getValue() : 20f;
@@ -50,7 +51,7 @@ public class JavaPlayerHealthTranslator extends PacketTranslator<ServerPlayerHea
maxHealth += 1;
}
- entity.getAttributes().put(AttributeType.HEALTH, AttributeType.HEALTH.getAttribute(packet.getHealth(), maxHealth));
+ entity.getAttributes().put(AttributeType.HEALTH, AttributeType.HEALTH.getAttribute(health, maxHealth));
entity.getAttributes().put(AttributeType.HUNGER, AttributeType.HUNGER.getAttribute(packet.getFood()));
entity.getAttributes().put(AttributeType.SATURATION, AttributeType.SATURATION.getAttribute(packet.getSaturation()));
entity.updateBedrockAttributes(session);
