3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-03 14:50:19 +01:00

Fix edge case in health code since 1.18.30

Fixes #2957
Dieser Commit ist enthalten in:
Camotoy 2022-05-04 15:54:19 -04:00
Ursprung 31a84ea302
Commit 05e98c3a10
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 7EEFB66FE798081F
2 geänderte Dateien mit 17 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -134,6 +134,10 @@ public class SessionPlayerEntity extends PlayerEntity {
return maxHealth; return maxHealth;
} }
public float getHealth() {
return this.health;
}
public void setHealth(float health) { public void setHealth(float health) {
this.health = health; this.health = health;
} }

Datei anzeigen

@ -27,6 +27,7 @@ package org.geysermc.geyser.translator.protocol.java.entity.player;
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.player.ClientboundSetHealthPacket; import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.player.ClientboundSetHealthPacket;
import com.nukkitx.protocol.bedrock.data.AttributeData; import com.nukkitx.protocol.bedrock.data.AttributeData;
import com.nukkitx.protocol.bedrock.packet.RespawnPacket;
import com.nukkitx.protocol.bedrock.packet.UpdateAttributesPacket; import com.nukkitx.protocol.bedrock.packet.UpdateAttributesPacket;
import org.geysermc.geyser.entity.attribute.GeyserAttributeType; import org.geysermc.geyser.entity.attribute.GeyserAttributeType;
import org.geysermc.geyser.entity.type.player.SessionPlayerEntity; import org.geysermc.geyser.entity.type.player.SessionPlayerEntity;
@ -43,6 +44,18 @@ public class JavaSetHealthTranslator extends PacketTranslator<ClientboundSetHeal
public void translate(GeyserSession session, ClientboundSetHealthPacket packet) { public void translate(GeyserSession session, ClientboundSetHealthPacket packet) {
SessionPlayerEntity entity = session.getPlayerEntity(); SessionPlayerEntity entity = session.getPlayerEntity();
float oldHealth = entity.getHealth();
if (oldHealth <= 0f && Math.ceil(packet.getHealth()) > 0f) {
// Needed as of 1.18.30 (tested with a totem of undying on SPIGOT 1.12.2
// This shouldn't be triggered on a proper respawn because JavaSetHealthTranslator sets the health back to 20
// https://github.com/GeyserMC/Geyser/issues/2957
RespawnPacket respawnPacket = new RespawnPacket();
respawnPacket.setRuntimeEntityId(0);
respawnPacket.setPosition(entity.getPosition());
respawnPacket.setState(RespawnPacket.State.SERVER_READY);
session.sendUpstreamPacket(respawnPacket);
}
entity.setHealth(packet.getHealth()); entity.setHealth(packet.getHealth());
UpdateAttributesPacket attributesPacket = new UpdateAttributesPacket(); UpdateAttributesPacket attributesPacket = new UpdateAttributesPacket();