3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-27 08:30:12 +01:00

Fix respawn bugs - hopefully for good

Thanks to @bundabrg for spotting this one.
Dieser Commit ist enthalten in:
DoctorMacc 2020-07-01 12:28:03 -04:00
Ursprung 0f342c1e80
Commit c17f21eedc
5 geänderte Dateien mit 31 neuen und 32 gelöschten Zeilen

Datei anzeigen

@ -117,11 +117,15 @@ public class LivingEntity extends Entity {
for (Map.Entry<AttributeType, org.geysermc.connector.entity.attribute.Attribute> entry : this.attributes.entrySet()) { for (Map.Entry<AttributeType, org.geysermc.connector.entity.attribute.Attribute> entry : this.attributes.entrySet()) {
if (!entry.getValue().getType().isBedrockAttribute()) if (!entry.getValue().getType().isBedrockAttribute())
continue; continue;
if (entry.getValue().getType() == AttributeType.HEALTH) {
// Add health attribute to properly show hearts when mounting
// TODO: Not a perfect system, since it led to respawn bugs
attributes.add(new AttributeData("minecraft:health", 0.0f, maxHealth, metadata.getFloat(EntityData.HEALTH, 20f), maxHealth));
continue;
}
attributes.add(AttributeUtils.getBedrockAttribute(entry.getValue())); attributes.add(AttributeUtils.getBedrockAttribute(entry.getValue()));
} }
// Add health attribute to properly show hearts when mounting
attributes.add(new AttributeData("minecraft:health", 0.0f, maxHealth, metadata.getFloat(EntityData.HEALTH, 20f), maxHealth));
UpdateAttributesPacket updateAttributesPacket = new UpdateAttributesPacket(); UpdateAttributesPacket updateAttributesPacket = new UpdateAttributesPacket();
updateAttributesPacket.setRuntimeEntityId(geyserId); updateAttributesPacket.setRuntimeEntityId(geyserId);

Datei anzeigen

@ -39,15 +39,19 @@ import com.nukkitx.protocol.bedrock.packet.*;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.entity.attribute.Attribute;
import org.geysermc.connector.entity.attribute.AttributeType;
import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.session.cache.EntityEffectCache; import org.geysermc.connector.network.session.cache.EntityEffectCache;
import org.geysermc.connector.scoreboard.Team; import org.geysermc.connector.scoreboard.Team;
import org.geysermc.connector.utils.AttributeUtils;
import org.geysermc.connector.utils.MessageUtils; import org.geysermc.connector.utils.MessageUtils;
import org.geysermc.connector.utils.SkinUtils; import org.geysermc.connector.utils.SkinUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -293,4 +297,22 @@ public class PlayerEntity extends LivingEntity {
} }
} }
} }
@Override
public void updateBedrockAttributes(GeyserSession session) { // TODO: Don't use duplicated code
if (!valid) return;
List<AttributeData> attributes = new ArrayList<>();
for (Map.Entry<AttributeType, Attribute> entry : this.attributes.entrySet()) {
if (!entry.getValue().getType().isBedrockAttribute())
continue;
attributes.add(AttributeUtils.getBedrockAttribute(entry.getValue()));
}
UpdateAttributesPacket updateAttributesPacket = new UpdateAttributesPacket();
updateAttributesPacket.setRuntimeEntityId(geyserId);
updateAttributesPacket.setAttributes(attributes);
session.sendUpstreamPacket(updateAttributesPacket);
}
} }

Datei anzeigen

@ -25,14 +25,13 @@
package org.geysermc.connector.network.translators.bedrock; package org.geysermc.connector.network.translators.bedrock;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator;
import com.github.steveice10.mc.protocol.data.game.ClientRequest; import com.github.steveice10.mc.protocol.data.game.ClientRequest;
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket; import com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.packet.RespawnPacket; import com.nukkitx.protocol.bedrock.packet.RespawnPacket;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator;
@Translator(packet = RespawnPacket.class) @Translator(packet = RespawnPacket.class)
public class BedrockRespawnTranslator extends PacketTranslator<RespawnPacket> { public class BedrockRespawnTranslator extends PacketTranslator<RespawnPacket> {

Datei anzeigen

@ -28,14 +28,11 @@ package org.geysermc.connector.network.translators.java.entity;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityStatusPacket; import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityStatusPacket;
import com.nukkitx.protocol.bedrock.data.entity.EntityEventType; import com.nukkitx.protocol.bedrock.data.entity.EntityEventType;
import com.nukkitx.protocol.bedrock.packet.EntityEventPacket; import com.nukkitx.protocol.bedrock.packet.EntityEventPacket;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.entity.Entity; import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.network.translators.Translator;
import java.util.concurrent.TimeUnit;
@Translator(packet = ServerEntityStatusPacket.class) @Translator(packet = ServerEntityStatusPacket.class)
public class JavaEntityStatusTranslator extends PacketTranslator<ServerEntityStatusPacket> { public class JavaEntityStatusTranslator extends PacketTranslator<ServerEntityStatusPacket> {
@ -102,16 +99,5 @@ public class JavaEntityStatusTranslator extends PacketTranslator<ServerEntitySta
} }
session.sendUpstreamPacket(entityEventPacket); session.sendUpstreamPacket(entityEventPacket);
// This fixes some death events not getting registered on the client such as drowning
if (entityEventPacket.getType() == EntityEventType.DEATH) {
GeyserConnector.getInstance().getGeneralThreadPool().schedule(() -> {
EntityEventPacket eventPacket2 = new EntityEventPacket();
eventPacket2.setRuntimeEntityId(entityEventPacket.getRuntimeEntityId());
eventPacket2.setType(entityEventPacket.getType());
eventPacket2.setData(entityEventPacket.getData());
session.sendUpstreamPacket(eventPacket2);
}, 1, TimeUnit.MILLISECONDS);
}
} }
} }

Datei anzeigen

@ -34,7 +34,6 @@ import com.nukkitx.protocol.bedrock.packet.EntityEventPacket;
import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket; import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket;
import com.nukkitx.protocol.bedrock.packet.RespawnPacket; import com.nukkitx.protocol.bedrock.packet.RespawnPacket;
import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket; import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.entity.PlayerEntity; import org.geysermc.connector.entity.PlayerEntity;
import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
@ -43,8 +42,6 @@ import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.network.translators.Translator;
import org.geysermc.connector.utils.ChunkUtils; import org.geysermc.connector.utils.ChunkUtils;
import java.util.concurrent.TimeUnit;
@Translator(packet = ServerPlayerPositionRotationPacket.class) @Translator(packet = ServerPlayerPositionRotationPacket.class)
public class JavaPlayerPositionRotationTranslator extends PacketTranslator<ServerPlayerPositionRotationPacket> { public class JavaPlayerPositionRotationTranslator extends PacketTranslator<ServerPlayerPositionRotationPacket> {
@ -74,15 +71,6 @@ public class JavaPlayerPositionRotationTranslator extends PacketTranslator<Serve
eventPacket.setData(0); eventPacket.setData(0);
session.sendUpstreamPacket(eventPacket); session.sendUpstreamPacket(eventPacket);
// This will prevent the client getting stuck at the respawn screen
GeyserConnector.getInstance().getGeneralThreadPool().schedule(() -> {
EntityEventPacket eventPacket2 = new EntityEventPacket();
eventPacket2.setRuntimeEntityId(entity.getGeyserId());
eventPacket2.setType(EntityEventType.RESPAWN);
eventPacket2.setData(0);
session.sendUpstreamPacket(eventPacket2);
}, 1, TimeUnit.MILLISECONDS);
SetEntityDataPacket entityDataPacket = new SetEntityDataPacket(); SetEntityDataPacket entityDataPacket = new SetEntityDataPacket();
entityDataPacket.setRuntimeEntityId(entity.getGeyserId()); entityDataPacket.setRuntimeEntityId(entity.getGeyserId());
entityDataPacket.getMetadata().putAll(entity.getMetadata()); entityDataPacket.getMetadata().putAll(entity.getMetadata());