Fix respawn bugs - hopefully for good

Thanks to @bundabrg for spotting this one.
This commit is contained in:
DoctorMacc 2020-07-01 12:28:03 -04:00
parent 0f342c1e80
commit c17f21eedc
5 changed files with 31 additions and 32 deletions

View file

@ -117,11 +117,15 @@ public class LivingEntity extends Entity {
for (Map.Entry<AttributeType, org.geysermc.connector.entity.attribute.Attribute> entry : this.attributes.entrySet()) {
if (!entry.getValue().getType().isBedrockAttribute())
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()));
}
// 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.setRuntimeEntityId(geyserId);

View file

@ -39,15 +39,19 @@ import com.nukkitx.protocol.bedrock.packet.*;
import lombok.Getter;
import lombok.Setter;
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.network.session.GeyserSession;
import org.geysermc.connector.network.session.cache.EntityEffectCache;
import org.geysermc.connector.scoreboard.Team;
import org.geysermc.connector.utils.AttributeUtils;
import org.geysermc.connector.utils.MessageUtils;
import org.geysermc.connector.utils.SkinUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
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);
}
}

View file

@ -25,14 +25,13 @@
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.packet.ingame.client.ClientRequestPacket;
import com.nukkitx.math.vector.Vector3f;
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)
public class BedrockRespawnTranslator extends PacketTranslator<RespawnPacket> {

View file

@ -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.nukkitx.protocol.bedrock.data.entity.EntityEventType;
import com.nukkitx.protocol.bedrock.packet.EntityEventPacket;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator;
import java.util.concurrent.TimeUnit;
@Translator(packet = ServerEntityStatusPacket.class)
public class JavaEntityStatusTranslator extends PacketTranslator<ServerEntityStatusPacket> {
@ -102,16 +99,5 @@ public class JavaEntityStatusTranslator extends PacketTranslator<ServerEntitySta
}
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);
}
}
}

View file

@ -34,7 +34,6 @@ import com.nukkitx.protocol.bedrock.packet.EntityEventPacket;
import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket;
import com.nukkitx.protocol.bedrock.packet.RespawnPacket;
import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.entity.PlayerEntity;
import org.geysermc.connector.entity.type.EntityType;
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.utils.ChunkUtils;
import java.util.concurrent.TimeUnit;
@Translator(packet = ServerPlayerPositionRotationPacket.class)
public class JavaPlayerPositionRotationTranslator extends PacketTranslator<ServerPlayerPositionRotationPacket> {
@ -74,15 +71,6 @@ public class JavaPlayerPositionRotationTranslator extends PacketTranslator<Serve
eventPacket.setData(0);
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();
entityDataPacket.setRuntimeEntityId(entity.getGeyserId());
entityDataPacket.getMetadata().putAll(entity.getMetadata());