Implement last death position translation

This commit is contained in:
Camotoy 2022-05-26 19:34:27 -04:00
parent 85800eb32b
commit 4a9eec4c54
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F
3 changed files with 21 additions and 6 deletions

View file

@ -27,6 +27,7 @@ package org.geysermc.geyser.entity.type.player;
import com.github.steveice10.mc.protocol.data.game.entity.attribute.Attribute; import com.github.steveice10.mc.protocol.data.game.entity.attribute.Attribute;
import com.github.steveice10.mc.protocol.data.game.entity.attribute.AttributeType; import com.github.steveice10.mc.protocol.data.game.entity.attribute.AttributeType;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.GlobalPos;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Pose; import com.github.steveice10.mc.protocol.data.game.entity.metadata.Pose;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
@ -40,11 +41,10 @@ import org.geysermc.geyser.entity.attribute.GeyserAttributeType;
import org.geysermc.geyser.registry.type.ItemMapping; import org.geysermc.geyser.registry.type.ItemMapping;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.util.AttributeUtils; import org.geysermc.geyser.util.AttributeUtils;
import org.geysermc.geyser.util.DimensionUtils;
import java.util.Collections; import javax.annotation.Nullable;
import java.util.List; import java.util.*;
import java.util.Map;
import java.util.UUID;
/** /**
* The entity class specifically for a {@link GeyserSession}'s player. * The entity class specifically for a {@link GeyserSession}'s player.
@ -222,4 +222,14 @@ public class SessionPlayerEntity extends PlayerEntity {
this.attributes.put(type, attributeData); this.attributes.put(type, attributeData);
return attributeData; return attributeData;
} }
public void setLastDeathPosition(@Nullable GlobalPos pos) {
if (pos != null) {
dirtyMetadata.put(EntityData.PLAYER_LAST_DEATH_POS, pos.getPosition());
dirtyMetadata.put(EntityData.PLAYER_LAST_DEATH_DIMENSION, DimensionUtils.javaToBedrock(pos.getDimension()));
dirtyMetadata.put(EntityData.PLAYER_HAS_DIED, (byte) 1);
} else {
dirtyMetadata.put(EntityData.PLAYER_HAS_DIED, (byte) 0);
}
}
} }

View file

@ -36,7 +36,7 @@ import com.nukkitx.protocol.bedrock.packet.AdventureSettingsPacket;
import com.nukkitx.protocol.bedrock.packet.GameRulesChangedPacket; import com.nukkitx.protocol.bedrock.packet.GameRulesChangedPacket;
import com.nukkitx.protocol.bedrock.packet.SetPlayerGameTypePacket; import com.nukkitx.protocol.bedrock.packet.SetPlayerGameTypePacket;
import org.geysermc.floodgate.pluginmessage.PluginMessageChannels; import org.geysermc.floodgate.pluginmessage.PluginMessageChannels;
import org.geysermc.geyser.entity.type.player.PlayerEntity; import org.geysermc.geyser.entity.type.player.SessionPlayerEntity;
import org.geysermc.geyser.level.JavaDimension; import org.geysermc.geyser.level.JavaDimension;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.session.auth.AuthType; import org.geysermc.geyser.session.auth.AuthType;
@ -56,7 +56,7 @@ public class JavaLoginTranslator extends PacketTranslator<ClientboundLoginPacket
@Override @Override
public void translate(GeyserSession session, ClientboundLoginPacket packet) { public void translate(GeyserSession session, ClientboundLoginPacket packet) {
PlayerEntity entity = session.getPlayerEntity(); SessionPlayerEntity entity = session.getPlayerEntity();
entity.setEntityId(packet.getEntityId()); entity.setEntityId(packet.getEntityId());
Map<String, JavaDimension> dimensions = session.getDimensions(); Map<String, JavaDimension> dimensions = session.getDimensions();
@ -116,6 +116,8 @@ public class JavaLoginTranslator extends PacketTranslator<ClientboundLoginPacket
session.sendUpstreamPacket(playerGameTypePacket); session.sendUpstreamPacket(playerGameTypePacket);
} }
entity.setLastDeathPosition(packet.getLastDeathPos());
entity.updateBedrockMetadata(); entity.updateBedrockMetadata();
// Send if client should show respawn screen // Send if client should show respawn screen

View file

@ -55,6 +55,9 @@ public class JavaRespawnTranslator extends PacketTranslator<ClientboundRespawnPa
session.setOpenInventory(null); session.setOpenInventory(null);
session.setClosingInventory(false); session.setClosingInventory(false);
entity.setLastDeathPosition(packet.getLastDeathPos());
entity.updateBedrockMetadata();
SetPlayerGameTypePacket playerGameTypePacket = new SetPlayerGameTypePacket(); SetPlayerGameTypePacket playerGameTypePacket = new SetPlayerGameTypePacket();
playerGameTypePacket.setGamemode(packet.getGamemode().ordinal()); playerGameTypePacket.setGamemode(packet.getGamemode().ordinal());
session.sendUpstreamPacket(playerGameTypePacket); session.sendUpstreamPacket(playerGameTypePacket);