forked from GeyserMC/Geyser
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)
|
if (entity == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
int health = (int) Math.ceil(packet.getHealth());
|
||||||
SetHealthPacket setHealthPacket = new SetHealthPacket();
|
SetHealthPacket setHealthPacket = new SetHealthPacket();
|
||||||
setHealthPacket.setHealth((int) Math.ceil(packet.getHealth()));
|
setHealthPacket.setHealth(health);
|
||||||
session.getUpstream().sendPacket(setHealthPacket);
|
session.getUpstream().sendPacket(setHealthPacket);
|
||||||
|
|
||||||
float maxHealth = entity.getAttributes().containsKey(AttributeType.MAX_HEALTH) ? entity.getAttributes().get(AttributeType.MAX_HEALTH).getValue() : 20f;
|
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;
|
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.HUNGER, AttributeType.HUNGER.getAttribute(packet.getFood()));
|
||||||
entity.getAttributes().put(AttributeType.SATURATION, AttributeType.SATURATION.getAttribute(packet.getSaturation()));
|
entity.getAttributes().put(AttributeType.SATURATION, AttributeType.SATURATION.getAttribute(packet.getSaturation()));
|
||||||
entity.updateBedrockAttributes(session);
|
entity.updateBedrockAttributes(session);
|
||||||
|
|
Loading…
Reference in a new issue