mirror of
https://github.com/GeyserMC/Geyser.git
synced 2025-12-20 15:29:27 +00:00
Fix: beacon speed effect causing visual glitches looking like a heartbeat
almost looks like the player is alive, lol fixes https://github.com/GeyserMC/Geyser/issues/5388
This commit is contained in:
@@ -25,10 +25,10 @@
|
|||||||
|
|
||||||
package org.geysermc.geyser.entity.attribute;
|
package org.geysermc.geyser.entity.attribute;
|
||||||
|
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
|
||||||
import org.cloudburstmc.protocol.bedrock.data.AttributeData;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
import org.cloudburstmc.protocol.bedrock.data.AttributeData;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
|||||||
@@ -25,16 +25,17 @@
|
|||||||
|
|
||||||
package org.geysermc.geyser.translator.protocol.java.entity;
|
package org.geysermc.geyser.translator.protocol.java.entity;
|
||||||
|
|
||||||
|
import org.cloudburstmc.protocol.bedrock.data.AttributeData;
|
||||||
import org.cloudburstmc.protocol.bedrock.packet.MobEffectPacket;
|
import org.cloudburstmc.protocol.bedrock.packet.MobEffectPacket;
|
||||||
import org.cloudburstmc.protocol.bedrock.packet.UpdateAttributesPacket;
|
import org.cloudburstmc.protocol.bedrock.packet.UpdateAttributesPacket;
|
||||||
import org.geysermc.geyser.entity.attribute.GeyserAttributeType;
|
import org.geysermc.geyser.entity.attribute.GeyserAttributeType;
|
||||||
import org.geysermc.geyser.entity.type.Entity;
|
import org.geysermc.geyser.entity.type.Entity;
|
||||||
import org.geysermc.geyser.entity.vehicle.ClientVehicle;
|
import org.geysermc.geyser.entity.vehicle.ClientVehicle;
|
||||||
import org.geysermc.geyser.session.GeyserSession;
|
import org.geysermc.geyser.session.GeyserSession;
|
||||||
|
import org.geysermc.geyser.session.cache.EntityEffectCache;
|
||||||
import org.geysermc.geyser.translator.protocol.PacketTranslator;
|
import org.geysermc.geyser.translator.protocol.PacketTranslator;
|
||||||
import org.geysermc.geyser.translator.protocol.Translator;
|
import org.geysermc.geyser.translator.protocol.Translator;
|
||||||
import org.geysermc.geyser.util.EntityUtils;
|
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 org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundUpdateMobEffectPacket;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -49,8 +50,15 @@ public class JavaUpdateMobEffectTranslator extends PacketTranslator<ClientboundU
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var event = MobEffectPacket.Event.ADD;
|
||||||
|
|
||||||
if (entity == session.getPlayerEntity()) {
|
if (entity == session.getPlayerEntity()) {
|
||||||
session.getEffectCache().setEffect(packet.getEffect(), packet.getAmplifier());
|
EntityEffectCache cache = session.getEffectCache();
|
||||||
|
cache.setEffect(packet.getEffect(), packet.getAmplifier());
|
||||||
|
// Matches BDS
|
||||||
|
if (cache.getEntityEffects().contains(packet.getEffect())) {
|
||||||
|
event = MobEffectPacket.Event.MODIFY;
|
||||||
|
}
|
||||||
} else if (entity instanceof ClientVehicle clientVehicle) {
|
} else if (entity instanceof ClientVehicle clientVehicle) {
|
||||||
clientVehicle.getVehicleComponent().setEffect(packet.getEffect(), packet.getAmplifier());
|
clientVehicle.getVehicleComponent().setEffect(packet.getEffect(), packet.getAmplifier());
|
||||||
}
|
}
|
||||||
@@ -58,24 +66,29 @@ public class JavaUpdateMobEffectTranslator extends PacketTranslator<ClientboundU
|
|||||||
MobEffectPacket mobEffectPacket = new MobEffectPacket();
|
MobEffectPacket mobEffectPacket = new MobEffectPacket();
|
||||||
mobEffectPacket.setAmplifier(packet.getAmplifier());
|
mobEffectPacket.setAmplifier(packet.getAmplifier());
|
||||||
mobEffectPacket.setDuration(packet.getDuration());
|
mobEffectPacket.setDuration(packet.getDuration());
|
||||||
mobEffectPacket.setEvent(MobEffectPacket.Event.ADD);
|
mobEffectPacket.setEvent(event);
|
||||||
mobEffectPacket.setRuntimeEntityId(entity.getGeyserId());
|
mobEffectPacket.setRuntimeEntityId(entity.getGeyserId());
|
||||||
mobEffectPacket.setParticles(packet.isShowParticles());
|
mobEffectPacket.setParticles(packet.isShowParticles());
|
||||||
mobEffectPacket.setEffectId(EntityUtils.toBedrockEffectId(packet.getEffect()));
|
mobEffectPacket.setEffectId(EntityUtils.toBedrockEffectId(packet.getEffect()));
|
||||||
session.sendUpstreamPacket(mobEffectPacket);
|
session.sendUpstreamPacket(mobEffectPacket);
|
||||||
|
|
||||||
// Fixes https://github.com/GeyserMC/Geyser/issues/5347 by re-sending the correct absorption hearts
|
// Bedrock expects some attributes to be updated in the same tick as the effect causing them
|
||||||
if (entity == session.getPlayerEntity() && packet.getEffect() == Effect.ABSORPTION) {
|
if (entity == session.getPlayerEntity()) {
|
||||||
var absorptionAttribute = session.getPlayerEntity().getAttributes().get(GeyserAttributeType.ABSORPTION);
|
AttributeData attribute = switch (packet.getEffect()) {
|
||||||
if (absorptionAttribute == null) {
|
// Fixes https://github.com/GeyserMC/Geyser/issues/5347
|
||||||
|
case ABSORPTION -> session.getPlayerEntity().getAttributes().get(GeyserAttributeType.ABSORPTION);
|
||||||
|
// Fixes https://github.com/GeyserMC/Geyser/issues/5388
|
||||||
|
case SPEED -> session.getPlayerEntity().getAttributes().get(GeyserAttributeType.MOVEMENT_SPEED);
|
||||||
|
default -> null;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (attribute == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateAttributesPacket attributesPacket = new UpdateAttributesPacket();
|
UpdateAttributesPacket attributesPacket = new UpdateAttributesPacket();
|
||||||
attributesPacket.setRuntimeEntityId(entity.getGeyserId());
|
attributesPacket.setRuntimeEntityId(entity.getGeyserId());
|
||||||
// Setting to a higher maximum since plugins/datapacks can probably extend the Bedrock soft limit
|
attributesPacket.setAttributes(Collections.singletonList(attribute));
|
||||||
attributesPacket.setAttributes(Collections.singletonList(
|
|
||||||
GeyserAttributeType.ABSORPTION.getAttribute(absorptionAttribute.getValue())));
|
|
||||||
session.sendUpstreamPacket(attributesPacket);
|
session.sendUpstreamPacket(attributesPacket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user