Skip to content

Commit dd7a0d3

Browse files
committed
Fix #5347
1 parent 915986a commit dd7a0d3

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaUpdateMobEffectTranslator.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,19 @@
2525

2626
package org.geysermc.geyser.translator.protocol.java.entity;
2727

28-
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundUpdateMobEffectPacket;
2928
import org.cloudburstmc.protocol.bedrock.packet.MobEffectPacket;
29+
import org.cloudburstmc.protocol.bedrock.packet.UpdateAttributesPacket;
30+
import org.geysermc.geyser.entity.attribute.GeyserAttributeType;
3031
import org.geysermc.geyser.entity.type.Entity;
3132
import org.geysermc.geyser.entity.vehicle.ClientVehicle;
3233
import org.geysermc.geyser.session.GeyserSession;
3334
import org.geysermc.geyser.translator.protocol.PacketTranslator;
3435
import org.geysermc.geyser.translator.protocol.Translator;
3536
import org.geysermc.geyser.util.EntityUtils;
37+
import org.geysermc.mcprotocollib.protocol.data.game.entity.Effect;
38+
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundUpdateMobEffectPacket;
39+
40+
import java.util.Collections;
3641

3742
@Translator(packet = ClientboundUpdateMobEffectPacket.class)
3843
public class JavaUpdateMobEffectTranslator extends PacketTranslator<ClientboundUpdateMobEffectPacket> {
@@ -58,5 +63,20 @@ public void translate(GeyserSession session, ClientboundUpdateMobEffectPacket pa
5863
mobEffectPacket.setParticles(packet.isShowParticles());
5964
mobEffectPacket.setEffectId(EntityUtils.toBedrockEffectId(packet.getEffect()));
6065
session.sendUpstreamPacket(mobEffectPacket);
66+
67+
// Fixes https://github.com/GeyserMC/Geyser/issues/5347 by re-sending the correct absorption hearts
68+
if (entity == session.getPlayerEntity() && packet.getEffect() == Effect.ABSORPTION) {
69+
var absorptionAttribute = session.getPlayerEntity().getAttributes().get(GeyserAttributeType.ABSORPTION);
70+
if (absorptionAttribute == null) {
71+
return;
72+
}
73+
74+
UpdateAttributesPacket attributesPacket = new UpdateAttributesPacket();
75+
attributesPacket.setRuntimeEntityId(entity.getGeyserId());
76+
// Setting to a higher maximum since plugins/datapacks can probably extend the Bedrock soft limit
77+
attributesPacket.setAttributes(Collections.singletonList(
78+
GeyserAttributeType.ABSORPTION.getAttribute(absorptionAttribute.getValue())));
79+
session.sendUpstreamPacket(attributesPacket);
80+
}
6181
}
6282
}

0 commit comments

Comments
 (0)