From 7fda025c0d262916cdd736ccfe7e0e7e2cd2cfe8 Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Thu, 28 Jun 2018 07:34:56 -0300 Subject: [PATCH] maybe cleaner code? --- .../ProtocolSnapshotTo1_12_2.java | 49 ++++++++++--------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/ProtocolSnapshotTo1_12_2.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/ProtocolSnapshotTo1_12_2.java index 0d90cb988..5c3620ef5 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/ProtocolSnapshotTo1_12_2.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/ProtocolSnapshotTo1_12_2.java @@ -658,22 +658,19 @@ public class ProtocolSnapshotTo1_12_2 extends Protocol { } }); handler(POS_TO_3_INT); - map(Type.VAR_INT, Type.BYTE); // Action - handler(new PacketHandler() { + map(Type.VAR_INT, new ValueTransformer(Type.BYTE) { // Action @Override - public void handle(PacketWrapper wrapper) throws Exception { - wrapper.set(Type.BYTE, 0, (byte) (wrapper.get(Type.BYTE, 0) + 1)); // Action + public Byte transform(PacketWrapper wrapper, Integer action) throws Exception { + return (byte) (action + 1); } - }); - handler(new PacketHandler() { + }); // Action + map(Type.VAR_INT, new ValueTransformer(Type.STRING) { @Override - public void handle(PacketWrapper wrapper) throws Exception { - int mode = wrapper.read(Type.VAR_INT); - String stringMode = mode == 0 ? "SAVE" + public String transform(PacketWrapper wrapper, Integer mode) throws Exception { + return mode == 0 ? "SAVE" : mode == 1 ? "LOAD" : mode == 2 ? "CORNER" : "DATA"; - wrapper.write(Type.STRING, stringMode); } }); map(Type.STRING); // Name @@ -683,27 +680,31 @@ public class ProtocolSnapshotTo1_12_2 extends Protocol { map(Type.BYTE, Type.INT); // Size X map(Type.BYTE, Type.INT); // Size Y map(Type.BYTE, Type.INT); // Size Z + map(Type.VAR_INT, new ValueTransformer(Type.STRING) { // Mirror + @Override + public String transform(PacketWrapper wrapper, Integer mirror) throws Exception { + return mirror == 0 ? "NONE" + : mirror == 1 ? "LEFT_RIGHT" + : "FRONT_BACK"; + } + }); + map(Type.VAR_INT, new ValueTransformer(Type.STRING) { // Rotation + @Override + public String transform(PacketWrapper wrapper, Integer rotation) throws Exception { + return rotation == 0 ? "NONE" + : rotation == 1 ? "CLOCKWISE_90" + : rotation == 2 ? "CLOCKWISE_180" + : "COUNTERCLOCKWISE_90"; + } + }); + map(Type.STRING); handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { - int mirror = wrapper.read(Type.VAR_INT); - int rotation = wrapper.read(Type.VAR_INT); - String metadata = wrapper.read(Type.STRING); float integrity = wrapper.read(Type.FLOAT); long seed = wrapper.read(Type.VAR_LONG); byte flags = wrapper.read(Type.BYTE); - String stringMirror = mirror == 0 ? "NONE" - : mirror == 1 ? "LEFT_RIGHT" - : "FRONT_BACK"; - String stringRotation = rotation == 0 ? "NONE" - : rotation == 1 ? "CLOCKWISE_90" - : rotation == 2 ? "CLOCKWISE_180" - : "COUNTERCLOCKWISE_90"; - - wrapper.write(Type.STRING, stringMirror); - wrapper.write(Type.STRING, stringRotation); - wrapper.write(Type.STRING, metadata); wrapper.write(Type.BOOLEAN, (flags & 0x1) != 0); // Ignore Entities wrapper.write(Type.BOOLEAN, (flags & 0x2) != 0); // Show air wrapper.write(Type.BOOLEAN, (flags & 0x4) != 0); // Show bounding box