From 81ad1542eecfea64c276e607983e1746f21f3d1d Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sun, 21 Jul 2019 20:11:55 -0500 Subject: [PATCH] Add some entity translators --- .../network/translators/TranslatorsInit.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) 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 55107a5a3..61e2b1354 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 @@ -32,6 +32,10 @@ import com.github.steveice10.mc.protocol.data.message.TranslationMessage; import com.github.steveice10.mc.protocol.packet.ingame.server.ServerChatPacket; import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket; import com.github.steveice10.mc.protocol.packet.ingame.server.ServerTitlePacket; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPositionPacket; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPositionRotationPacket; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityTeleportPacket; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityVelocityPacket; import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateTimePacket; import com.nukkitx.nbt.CompoundTagBuilder; import com.nukkitx.nbt.NbtUtils; @@ -70,6 +74,7 @@ public class TranslatorsInit { addChatPackets(); addTitlePackets(); addTimePackets(); + addEntityPackets(); } private static void addLoginPackets() { @@ -223,4 +228,47 @@ public class TranslatorsInit { session.getUpstream().sendPacket(setTimePacket); }); } + + public static void addEntityPackets() { + Registry.add(ServerEntityPositionPacket.class, (packet, session) -> { + MoveEntityAbsolutePacket moveEntityPacket = new MoveEntityAbsolutePacket(); + moveEntityPacket.setRuntimeEntityId(packet.getEntityId()); + moveEntityPacket.setPosition(new Vector3f(packet.getMovementX(), packet.getMovementY(), packet.getMovementZ())); + moveEntityPacket.setRotation(new Vector3f(packet.getMovementX(), packet.getMovementY(), packet.getMovementZ())); + moveEntityPacket.setOnGround(packet.isOnGround()); + moveEntityPacket.setTeleported(false); + + session.getUpstream().sendPacket(moveEntityPacket); + }); + + Registry.add(ServerEntityPositionRotationPacket.class, (packet, session) -> { + MoveEntityAbsolutePacket moveEntityPacket = new MoveEntityAbsolutePacket(); + moveEntityPacket.setRuntimeEntityId(packet.getEntityId()); + moveEntityPacket.setPosition(new Vector3f(packet.getMovementX(), packet.getMovementY(), packet.getMovementZ())); + moveEntityPacket.setRotation(new Vector3f(packet.getMovementX(), packet.getMovementY(), packet.getMovementZ())); + moveEntityPacket.setOnGround(true); + moveEntityPacket.setTeleported(false); + + session.getUpstream().sendPacket(moveEntityPacket); + }); + + Registry.add(ServerEntityTeleportPacket.class, (packet, session) -> { + MoveEntityAbsolutePacket moveEntityPacket = new MoveEntityAbsolutePacket(); + moveEntityPacket.setRuntimeEntityId(packet.getEntityId()); + moveEntityPacket.setPosition(new Vector3f(packet.getX(), packet.getY(), packet.getZ())); + moveEntityPacket.setRotation(new Vector3f(packet.getX(), packet.getY(), packet.getZ())); + moveEntityPacket.setOnGround(packet.isOnGround()); + moveEntityPacket.setTeleported(true); + + session.getUpstream().sendPacket(moveEntityPacket); + }); + + Registry.add(ServerEntityVelocityPacket.class, (packet, session) -> { + SetEntityMotionPacket entityMotionPacket = new SetEntityMotionPacket(); + entityMotionPacket.setRuntimeEntityId(packet.getEntityId()); + entityMotionPacket.setMotion(new Vector3f(packet.getMotionX(), packet.getMotionY(), packet.getMotionZ())); + + session.getUpstream().sendPacket(entityMotionPacket); + }); + } }