Skip to content

Commit

Permalink
Fix #5347
Browse files Browse the repository at this point in the history
  • Loading branch information
onebeastchris committed Feb 27, 2025
1 parent 915986a commit dd7a0d3
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,19 @@

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

import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundUpdateMobEffectPacket;
import org.cloudburstmc.protocol.bedrock.packet.MobEffectPacket;
import org.cloudburstmc.protocol.bedrock.packet.UpdateAttributesPacket;
import org.geysermc.geyser.entity.attribute.GeyserAttributeType;
import org.geysermc.geyser.entity.type.Entity;
import org.geysermc.geyser.entity.vehicle.ClientVehicle;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.protocol.PacketTranslator;
import org.geysermc.geyser.translator.protocol.Translator;
import org.geysermc.geyser.util.EntityUtils;
import org.geysermc.mcprotocollib.protocol.data.game.entity.Effect;
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundUpdateMobEffectPacket;

import java.util.Collections;

@Translator(packet = ClientboundUpdateMobEffectPacket.class)
public class JavaUpdateMobEffectTranslator extends PacketTranslator<ClientboundUpdateMobEffectPacket> {
Expand All @@ -58,5 +63,20 @@ public void translate(GeyserSession session, ClientboundUpdateMobEffectPacket pa
mobEffectPacket.setParticles(packet.isShowParticles());
mobEffectPacket.setEffectId(EntityUtils.toBedrockEffectId(packet.getEffect()));
session.sendUpstreamPacket(mobEffectPacket);

// Fixes https://github.com/GeyserMC/Geyser/issues/5347 by re-sending the correct absorption hearts
if (entity == session.getPlayerEntity() && packet.getEffect() == Effect.ABSORPTION) {
var absorptionAttribute = session.getPlayerEntity().getAttributes().get(GeyserAttributeType.ABSORPTION);
if (absorptionAttribute == null) {
return;
}

UpdateAttributesPacket attributesPacket = new UpdateAttributesPacket();
attributesPacket.setRuntimeEntityId(entity.getGeyserId());
// Setting to a higher maximum since plugins/datapacks can probably extend the Bedrock soft limit
attributesPacket.setAttributes(Collections.singletonList(
GeyserAttributeType.ABSORPTION.getAttribute(absorptionAttribute.getValue())));
session.sendUpstreamPacket(attributesPacket);
}
}
}

0 comments on commit dd7a0d3

Please sign in to comment.