From 45984a57ac027a384fa47b68c9b5fd4332f2d544 Mon Sep 17 00:00:00 2001 From: David Choo Date: Fri, 6 Nov 2020 22:35:33 -0500 Subject: [PATCH] Fix crash with GSit lay and use Java bed position data --- .../org/geysermc/connector/entity/Entity.java | 23 +++++++++---------- .../living/merchant/VillagerEntity.java | 5 ++-- .../spawn/JavaSpawnPlayerTranslator.java | 22 +++++++++++------- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/Entity.java b/connector/src/main/java/org/geysermc/connector/entity/Entity.java index 2dfb0c04f..121e96a28 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/Entity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/Entity.java @@ -339,18 +339,6 @@ public class Entity { metadata.getFlags().setFlag(EntityFlag.SLEEPING, true); // Has to be a byte or it does not work metadata.put(EntityData.PLAYER_FLAGS, (byte) 2); - if (entityId == session.getPlayerEntity().getEntityId()) { - Vector3i lastInteractionPos = session.getLastInteractionPosition(); - metadata.put(EntityData.BED_POSITION, lastInteractionPos); - if (session.getConnector().getConfig().isCacheChunks()) { - int bed = session.getConnector().getWorldManager().getBlockAt(session, lastInteractionPos.getX(), - lastInteractionPos.getY(), lastInteractionPos.getZ()); - // Bed has to be updated, or else player is floating in the air - ChunkUtils.updateBlock(session, bed, lastInteractionPos); - } - } else { - metadata.put(EntityData.BED_POSITION, Vector3i.from(position.getFloorX(), position.getFloorY() - 2, position.getFloorZ())); - } metadata.put(EntityData.BOUNDING_BOX_WIDTH, 0.2f); metadata.put(EntityData.BOUNDING_BOX_HEIGHT, 0.2f); } else if (metadata.getFlags().getFlag(EntityFlag.SLEEPING)) { @@ -360,6 +348,17 @@ public class Entity { metadata.put(EntityData.PLAYER_FLAGS, (byte) 0); } break; + case 13: // Bed Position + Position bedPosition = (Position) entityMetadata.getValue(); + if (bedPosition != null) { + metadata.put(EntityData.BED_POSITION, Vector3i.from(bedPosition.getX(), bedPosition.getY(), bedPosition.getZ())); + if (session.getConnector().getConfig().isCacheChunks()) { + int bed = session.getConnector().getWorldManager().getBlockAt(session, bedPosition); + // Bed has to be updated, or else player is floating in the air + ChunkUtils.updateBlock(session, bed, bedPosition); + } + } + break; } } diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/merchant/VillagerEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/merchant/VillagerEntity.java index 7ada302c2..5fa272518 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/merchant/VillagerEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/merchant/VillagerEntity.java @@ -29,6 +29,7 @@ import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadat import com.github.steveice10.mc.protocol.data.game.entity.metadata.VillagerData; import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position; import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.math.vector.Vector3i; import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; import com.nukkitx.protocol.bedrock.data.entity.EntityFlags; @@ -100,8 +101,8 @@ public class VillagerEntity extends AbstractMerchantEntity { float bedPositionSubtractorW = 0; float bedPositionSubtractorN = 0; if (session.getConnector().getConfig().isCacheChunks()) { - Position bedLocation = new Position((int) position.getFloorX(), (int) position.getFloorY(), (int) position.getFloorZ()); - bedId = session.getConnector().getWorldManager().getBlockAt(session, bedLocation); + Vector3i bedPosition = metadata.getPos(EntityData.BED_POSITION); + bedId = session.getConnector().getWorldManager().getBlockAt(session, bedPosition); } String bedRotationZ = BlockTranslator.getJavaIdBlockMap().inverse().get(bedId); setRotation(rotation); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnPlayerTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnPlayerTranslator.java index 47beca8a6..99a6b0493 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnPlayerTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnPlayerTranslator.java @@ -43,15 +43,21 @@ public class JavaSpawnPlayerTranslator extends PacketTranslator