From 85e416171cb580ba3dc4b73cb99adf6e627a14b2 Mon Sep 17 00:00:00 2001 From: Mats Date: Tue, 28 Jun 2016 13:16:36 +0200 Subject: [PATCH] Let the transformer handle the signs (#456) --- .../myles/ViaVersion/api/PacketWrapper.java | 23 ++++++++++++++++--- .../us/myles/ViaVersion/api/type/Type.java | 1 - .../protocol1_9_1_2to1_9_3_4/BlockEntity.java | 22 ++---------------- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java b/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java index 6a76829de..07e16f335 100644 --- a/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java +++ b/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java @@ -276,10 +276,11 @@ public class PacketWrapper { * Be careful not to send packets twice. * (Sends it after current) * - * @param packetProtocol - The protocol version of the packet. + * @param packetProtocol - The protocol version of the packet. + * @param skipCurrentPipeline - Skip the current pipeline * @throws Exception if it fails to write */ - public void send(Class packetProtocol) throws Exception { + public void send(Class packetProtocol, boolean skipCurrentPipeline) throws Exception { if (!isCancelled()) { // Apply current pipeline List protocols = new ArrayList<>(user().get(ProtocolInfo.class).getPipeline().pipes()); @@ -288,10 +289,14 @@ public class PacketWrapper { int index = 0; for (int i = 0; i < protocols.size(); i++) { if (protocols.get(i).getClass().equals(packetProtocol)) { - index = i + 1; + index = skipCurrentPipeline ? (i + 1) : (i); break; } } + + // Reset reader before we start + resetReader(); + // Apply other protocols apply(Direction.OUTGOING, user().get(ProtocolInfo.class).getState(), index, protocols); // Send @@ -301,6 +306,18 @@ public class PacketWrapper { } } + /** + * Send this packet to the associated user. + * Be careful not to send packets twice. + * (Sends it after current) + * + * @param packetProtocol - The protocol version of the packet. + * @throws Exception if it fails to write + */ + public void send(Class packetProtocol) throws Exception { + send(packetProtocol, true); + } + /** * Send this packet to the associated user. * Be careful not to send packets twice. diff --git a/src/main/java/us/myles/ViaVersion/api/type/Type.java b/src/main/java/us/myles/ViaVersion/api/type/Type.java index 784806f9a..938ed4da9 100644 --- a/src/main/java/us/myles/ViaVersion/api/type/Type.java +++ b/src/main/java/us/myles/ViaVersion/api/type/Type.java @@ -10,7 +10,6 @@ import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.type.types.*; import us.myles.ViaVersion.api.type.types.minecraft.*; -import java.util.List; import java.util.UUID; @Getter diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_1_2to1_9_3_4/BlockEntity.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_1_2to1_9_3_4/BlockEntity.java index da8d2f67e..4d6c15246 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_1_2to1_9_3_4/BlockEntity.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_1_2to1_9_3_4/BlockEntity.java @@ -26,9 +26,6 @@ public class BlockEntity { types.put("UNKNOWN", 7); types.put("EndGateway", 8); types.put("Sign", 9); - - //I didn't see anything that didn't work about chests -// types.put("Chest", -1); } public static void handle(List tags, UserConnection connection) { @@ -51,14 +48,7 @@ public class BlockEntity { Position pos = new Position((long) x, (long) y, (long) z); - if (newId != 9) { - updateBlockEntity(pos, (short) newId, tag, connection); - } else { - String[] lines = new String[4]; - for (int i = 1; i < 5; i++) - lines[i - 1] = (String) tag.get("Text" + i).getValue(); - updateSign(pos, lines, connection); - } + updateBlockEntity(pos, (short) newId, tag, connection); } catch (Exception e) { if (ViaVersion.getInstance().isDebug()) { System.out.println("Block Entity: " + e.getMessage() + ": " + tag); @@ -72,14 +62,6 @@ public class BlockEntity { wrapper.write(Type.POSITION, pos); wrapper.write(Type.UNSIGNED_BYTE, id); wrapper.write(Type.NBT, tag); - wrapper.send(Protocol1_9_1_2TO1_9_3_4.class); - } - - private static void updateSign(Position pos, String[] lines, UserConnection connection) throws Exception { - PacketWrapper wrapper = new PacketWrapper(0x46, null, connection); - wrapper.write(Type.POSITION, pos); - for (String s : lines) - wrapper.write(Type.STRING, s); - wrapper.send(Protocol1_9_1_2TO1_9_3_4.class); + wrapper.send(Protocol1_9_1_2TO1_9_3_4.class, false); } }