From 4a9eec4c549338d9d5d85904ed6120013f980569 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Thu, 26 May 2022 19:34:27 -0400 Subject: [PATCH] Implement last death position translation --- .../type/player/SessionPlayerEntity.java | 18 ++++++++++++++---- .../protocol/java/JavaLoginTranslator.java | 6 ++++-- .../protocol/java/JavaRespawnTranslator.java | 3 +++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java index 6edcd60f3..db39a34db 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java @@ -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.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.type.ByteEntityMetadata; 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.session.GeyserSession; import org.geysermc.geyser.util.AttributeUtils; +import org.geysermc.geyser.util.DimensionUtils; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.UUID; +import javax.annotation.Nullable; +import java.util.*; /** * The entity class specifically for a {@link GeyserSession}'s player. @@ -222,4 +222,14 @@ public class SessionPlayerEntity extends PlayerEntity { this.attributes.put(type, 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); + } + } } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaLoginTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaLoginTranslator.java index 46e9b2f12..27bab75bb 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaLoginTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaLoginTranslator.java @@ -36,7 +36,7 @@ import com.nukkitx.protocol.bedrock.packet.AdventureSettingsPacket; import com.nukkitx.protocol.bedrock.packet.GameRulesChangedPacket; import com.nukkitx.protocol.bedrock.packet.SetPlayerGameTypePacket; 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.session.GeyserSession; import org.geysermc.geyser.session.auth.AuthType; @@ -56,7 +56,7 @@ public class JavaLoginTranslator extends PacketTranslator dimensions = session.getDimensions(); @@ -116,6 +116,8 @@ public class JavaLoginTranslator extends PacketTranslator