From d548647367a3578fa5e7dd6baa3d63bd69006254 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Wed, 16 Oct 2019 15:32:53 -0500 Subject: [PATCH] Fix/implement entity interaction and fix sprinting --- .../network/translators/TranslatorsInit.java | 1 + .../bedrock/BedrockActionTranslator.java | 19 +++++++------ .../bedrock/BedrockAnimateTranslator.java | 1 + .../bedrock/BedrockInteractTranslator.java | 27 +++++++++++-------- ...BedrockInventoryTransactionTranslator.java | 19 +++++++------ 5 files changed, 36 insertions(+), 31 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java b/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java index 259a08415..d4bc5b45e 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java @@ -151,6 +151,7 @@ public class TranslatorsInit { Registry.registerBedrock(MovePlayerPacket.class, new BedrockMovePlayerTranslator()); Registry.registerBedrock(PlayerActionPacket.class, new BedrockActionTranslator()); Registry.registerBedrock(SetLocalPlayerAsInitializedPacket.class, new BedrockPlayerInitializedTranslator()); + Registry.registerBedrock(InteractPacket.class, new BedrockInteractTranslator()); Registry.registerBedrock(TextPacket.class, new BedrockTextTranslator()); itemTranslator = new ItemTranslator(); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockActionTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockActionTranslator.java index f5d7d6af4..f0e63d2c4 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockActionTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockActionTranslator.java @@ -43,7 +43,7 @@ public class BedrockActionTranslator extends PacketTranslator { case SWING_ARM: ClientPlayerSwingArmPacket swingArmPacket = new ClientPlayerSwingArmPacket(Hand.MAIN_HAND); session.getDownstream().getSession().send(swingArmPacket); + break; } } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInteractTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInteractTranslator.java index 9b2060183..efd263075 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInteractTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInteractTranslator.java @@ -30,6 +30,8 @@ import com.github.steveice10.mc.protocol.data.game.entity.player.InteractAction; import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerInteractEntityPacket; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.packet.InteractPacket; +import org.geysermc.connector.entity.Entity; +import org.geysermc.connector.entity.PlayerEntity; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; @@ -37,18 +39,21 @@ public class BedrockInteractTranslator extends PacketTranslator @Override public void translate(InteractPacket packet, GeyserSession session) { - Vector3f vector = packet.getMousePosition(); - InteractAction action; + Entity entity = session.getEntityCache().getEntityByGeyserId(packet.getRuntimeEntityId()); + if (entity == null) + return; - if(packet.getAction() == 1) { - action = InteractAction.ATTACK; - } else { - action = InteractAction.INTERACT; + switch (packet.getAction()) { + case 1: + ClientPlayerInteractEntityPacket interactPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(), + InteractAction.INTERACT, Hand.MAIN_HAND); + session.getDownstream().getSession().send(interactPacket); + break; + case 2: + ClientPlayerInteractEntityPacket attackPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(), + InteractAction.ATTACK, Hand.MAIN_HAND); + session.getDownstream().getSession().send(attackPacket); + break; } - - ClientPlayerInteractEntityPacket entityPacket = new ClientPlayerInteractEntityPacket((int) packet.getRuntimeEntityId(), - action, vector.getX(), vector.getY(), vector.getZ(), Hand.MAIN_HAND); - - session.getDownstream().getSession().send(entityPacket); } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java index 71cf0a454..1e6b44a9e 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java @@ -35,6 +35,8 @@ import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlaye import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerUseItemPacket; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.packet.InventoryTransactionPacket; +import org.geysermc.connector.entity.Entity; +import org.geysermc.connector.entity.PlayerEntity; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; @@ -56,19 +58,16 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator