mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-11-23 07:16:39 +01:00
Fix health edge case
If the java server sent a health value between 0 and 1, the player would die in the bedrock client
This commit is contained in:
parent
4153e98134
commit
377a87f7e3
1 changed files with 3 additions and 2 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue