From 1857244eae7ed2a1d62e5c5249305196ab8e11e8 Mon Sep 17 00:00:00 2001 From: KennyTV <28825609+KennyTV@users.noreply.github.com> Date: Tue, 14 Jan 2020 14:15:40 +0100 Subject: [PATCH] We need playerteleport for caching, not entityteleport --- .../storage/object/PlayerPositionStorage.java | 12 ++++ .../Protocol1_12_2To1_13.java | 4 +- .../packets/EntityPackets1_13.java | 63 +++++-------------- .../storage/PlayerPositionStorage1_13.java | 10 --- 4 files changed, 31 insertions(+), 58 deletions(-) diff --git a/core/src/main/java/nl/matsv/viabackwards/api/entities/storage/object/PlayerPositionStorage.java b/core/src/main/java/nl/matsv/viabackwards/api/entities/storage/object/PlayerPositionStorage.java index 6dc62917..e557274f 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/entities/storage/object/PlayerPositionStorage.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/entities/storage/object/PlayerPositionStorage.java @@ -26,6 +26,18 @@ public abstract class PlayerPositionStorage extends StoredObject { return z; } + public void setX(final double x) { + this.x = x; + } + + public void setY(final double y) { + this.y = y; + } + + public void setZ(final double z) { + this.z = z; + } + public void setCoordinates(PacketWrapper wrapper, boolean relative) throws Exception { setCoordinates(wrapper.get(Type.DOUBLE, 0), wrapper.get(Type.DOUBLE, 1), wrapper.get(Type.DOUBLE, 2), relative); } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/Protocol1_12_2To1_13.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/Protocol1_12_2To1_13.java index 84054c56..3ef8824c 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/Protocol1_12_2To1_13.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/Protocol1_12_2To1_13.java @@ -65,13 +65,14 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol { out(State.PLAY, 0x20, 0x1E); // Change Game State out(State.PLAY, 0x21, 0x1F); // Keep Alive (clientbound) out(State.PLAY, 0x27, 0x25); // Entity + out(State.PLAY, 0x28, 0x26); // Entity Relative Move + out(State.PLAY, 0x29, 0x27); // Entity Look And Relative Move out(State.PLAY, 0x2A, 0x28); // Entity Look out(State.PLAY, 0x2B, 0x29); // Vehicle Move (clientbound) out(State.PLAY, 0x2C, 0x2A); // Open Sign Editor out(State.PLAY, 0x2D, 0x2B, cancel()); // Craft Recipe Response TODO MODIFIED out(State.PLAY, 0x2E, 0x2C); // Player Abilities (clientbound) out(State.PLAY, 0x2F, 0x2D); // Combat Event - out(State.PLAY, 0x32, 0x2F); // Player Position And Look (clientbound) out(State.PLAY, 0x33, 0x30); // Use Bed out(State.PLAY, 0x34, 0x31, cancel()); // Unlock Recipes TODO MODIFIED out(State.PLAY, 0x36, 0x33); // Remove Entity Effect @@ -93,6 +94,7 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol { out(State.PLAY, 0x4B, 0x48); // Title out(State.PLAY, 0x4E, 0x4A); // Player List Header And Footer out(State.PLAY, 0x4F, 0x4B); // Collect Item + out(State.PLAY, 0x50, 0x4C); // Entity Teleport out(State.PLAY, 0x51, 0x4D, cancel()); // Advancements out(State.PLAY, 0x52, 0x4E); // Entity Properties out(State.PLAY, 0x53, 0x4F); // Entity Effect diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/EntityPackets1_13.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/EntityPackets1_13.java index 766e920f..2d459cbb 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/EntityPackets1_13.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/EntityPackets1_13.java @@ -30,54 +30,37 @@ public class EntityPackets1_13 extends EntityRewriter { @Override protected void registerPackets(Protocol1_12_2To1_13 protocol) { - // Entity teleport - protocol.registerOutgoing(State.PLAY, 0x50, 0x4C, new PacketRemapper() { + // Player Position And Look (clientbound) + protocol.out(State.PLAY, 0x32, 0x2F, new PacketRemapper() { @Override public void registerMap() { - map(Type.VAR_INT); map(Type.DOUBLE); map(Type.DOUBLE); map(Type.DOUBLE); + map(Type.FLOAT); + map(Type.FLOAT); + map(Type.BYTE); handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { if (!ViaBackwards.getConfig().isFix1_13FacePlayer()) return; + PlayerPositionStorage1_13 playerStorage = wrapper.user().get(PlayerPositionStorage1_13.class); - if (playerStorage.getEntityId() == wrapper.get(Type.VAR_INT, 0)) { - playerStorage.setCoordinates(wrapper, false); - } + byte bitField = wrapper.get(Type.BYTE, 0); + playerStorage.setX(toSet(bitField, 0, playerStorage.getX(), wrapper.get(Type.DOUBLE, 0))); + playerStorage.setY(toSet(bitField, 1, playerStorage.getY(), wrapper.get(Type.DOUBLE, 1))); + playerStorage.setZ(toSet(bitField, 2, playerStorage.getZ(), wrapper.get(Type.DOUBLE, 2))); + } + + private double toSet(int field, int bitIndex, double origin, double packetValue) { + // If bit is set, coordinate is relative + return (field & (1 << bitIndex)) != 0 ? origin + packetValue : packetValue; } }); } }); - // Entity relative move + Entity look and relative move - PacketRemapper relativeMoveHandler = new PacketRemapper() { - @Override - public void registerMap() { - map(Type.VAR_INT); - map(Type.SHORT); - map(Type.SHORT); - map(Type.SHORT); - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - if (!ViaBackwards.getConfig().isFix1_13FacePlayer()) return; - PlayerPositionStorage1_13 playerStorage = wrapper.user().get(PlayerPositionStorage1_13.class); - if (playerStorage.getEntityId() == wrapper.get(Type.VAR_INT, 0)) { - double x = wrapper.get(Type.SHORT, 0) / EntityPositionHandler.RELATIVE_MOVE_FACTOR; - double y = wrapper.get(Type.SHORT, 1) / EntityPositionHandler.RELATIVE_MOVE_FACTOR; - double z = wrapper.get(Type.SHORT, 2) / EntityPositionHandler.RELATIVE_MOVE_FACTOR; - playerStorage.setCoordinates(x, y, z, true); - } - } - }); - } - }; - protocol.registerOutgoing(State.PLAY, 0x28, 0x26, relativeMoveHandler); - protocol.registerOutgoing(State.PLAY, 0x29, 0x27, relativeMoveHandler); - - //Spawn Object + // Spawn Object protocol.out(State.PLAY, 0x00, 0x00, new PacketRemapper() { @Override public void registerMap() { @@ -187,16 +170,6 @@ public class EntityPackets1_13 extends EntityRewriter { map(Types1_13.METADATA_LIST, Types1_12.METADATA_LIST); handler(getTrackerAndMetaHandler(Types1_12.METADATA_LIST, Entity1_13Types.EntityType.PLAYER)); - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - if (!ViaBackwards.getConfig().isFix1_13FacePlayer()) return; - PlayerPositionStorage1_13 positionStorage = wrapper.user().get(PlayerPositionStorage1_13.class); - if (positionStorage.getEntityId() == wrapper.get(Type.VAR_INT, 0)) { - positionStorage.setCoordinates(wrapper, false); - } - } - }); } }); @@ -229,10 +202,6 @@ public class EntityPackets1_13 extends EntityRewriter { handler(getTrackerHandler(Entity1_13Types.EntityType.PLAYER, Type.INT)); handler(getDimensionHandler(1)); - handler(wrapper -> { - if (!ViaBackwards.getConfig().isFix1_13FacePlayer()) return; - wrapper.user().get(PlayerPositionStorage1_13.class).setEntityId(wrapper.get(Type.INT, 0)); - }); } }); diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/storage/PlayerPositionStorage1_13.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/storage/PlayerPositionStorage1_13.java index 2f4dd753..b0b878c1 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/storage/PlayerPositionStorage1_13.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/storage/PlayerPositionStorage1_13.java @@ -5,17 +5,7 @@ import us.myles.ViaVersion.api.data.UserConnection; public class PlayerPositionStorage1_13 extends PlayerPositionStorage { - private int entityId; - public PlayerPositionStorage1_13(UserConnection user) { super(user); } - - public int getEntityId() { - return entityId; - } - - public void setEntityId(int entityId) { - this.entityId = entityId; - } }