]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/commitdiff
Stop using PacketBuffer and Packet types
authorIrtimaled <irtimaled@gmail.com>
Mon, 18 Mar 2019 04:20:57 +0000 (21:20 -0700)
committerIrtimaled <irtimaled@gmail.com>
Mon, 25 Mar 2019 03:56:28 +0000 (20:56 -0700)
src/main/java/com/irtimaled/bbor/common/CommonProxy.java
src/main/java/com/irtimaled/bbor/common/messages/AddBoundingBox.java
src/main/java/com/irtimaled/bbor/common/messages/BoundingBoxDeserializer.java
src/main/java/com/irtimaled/bbor/common/messages/BoundingBoxSerializer.java
src/main/java/com/irtimaled/bbor/common/messages/InitializeClient.java
src/main/java/com/irtimaled/bbor/common/messages/PayloadBuilder.java [new file with mode: 0644]
src/main/java/com/irtimaled/bbor/common/messages/PayloadReader.java [new file with mode: 0644]
src/main/java/com/irtimaled/bbor/common/messages/RemoveBoundingBox.java
src/main/java/com/irtimaled/bbor/common/messages/SubscribeToServer.java
src/main/java/com/irtimaled/bbor/mixin/network/play/client/MixinCPacketCustomPayload.java
src/main/java/com/irtimaled/bbor/mixin/network/play/server/MixinSPacketCustomPayload.java

index 2c2064227555962375ebd4ba20483cd69c1dd704..0656dcccce8b65c6a9d39b3f13852721ac1a8e46 100644 (file)
@@ -8,6 +8,7 @@ import com.irtimaled.bbor.common.chunkProcessors.OverworldChunkProcessor;
 import com.irtimaled.bbor.common.events.*;
 import com.irtimaled.bbor.common.messages.AddBoundingBox;
 import com.irtimaled.bbor.common.messages.InitializeClient;
+import com.irtimaled.bbor.common.messages.PayloadBuilder;
 import com.irtimaled.bbor.common.messages.RemoveBoundingBox;
 import com.irtimaled.bbor.common.models.BoundingBox;
 import com.irtimaled.bbor.common.models.BoundingBoxMobSpawner;
@@ -15,7 +16,6 @@ import com.irtimaled.bbor.common.models.Coords;
 import com.irtimaled.bbor.common.models.WorldData;
 import io.netty.channel.local.LocalAddress;
 import net.minecraft.entity.player.EntityPlayerMP;
-import net.minecraft.network.play.server.SPacketCustomPayload;
 import net.minecraft.world.World;
 import net.minecraft.world.WorldServer;
 import net.minecraft.world.chunk.Chunk;
@@ -83,7 +83,7 @@ public class CommonProxy {
 
     private void playerLoggedIn(EntityPlayerMP player) {
         if (player.connection.netManager.getRemoteAddress() instanceof LocalAddress) return;
-        player.connection.sendPacket(InitializeClient.getPayload(worldData));
+        player.connection.sendPacket(InitializeClient.getPayload(worldData).build());
     }
 
     private void playerLoggedOut(EntityPlayerMP player) {
@@ -92,12 +92,12 @@ public class CommonProxy {
     }
 
     private void sendRemoveBoundingBox(DimensionType dimensionType, BoundingBox boundingBox) {
-        SPacketCustomPayload payload = RemoveBoundingBox.getPayload(dimensionType, boundingBox);
-        if (payload == null) return;
+        PayloadBuilder payloadBuilder = RemoveBoundingBox.getPayload(dimensionType, boundingBox);
+        if (payloadBuilder == null) return;
 
         for (EntityPlayerMP player : players) {
             if (DimensionType.getById(player.dimension) == dimensionType) {
-                player.connection.sendPacket(payload);
+                player.connection.sendPacket(payloadBuilder.build());
 
                 if (playerBoundingBoxesCache.containsKey(player)) {
                     playerBoundingBoxesCache.get(player).remove(boundingBox);
@@ -121,9 +121,9 @@ public class CommonProxy {
 
         for (BoundingBox key : cacheSubset.keySet()) {
             Set<BoundingBox> boundingBoxes = cacheSubset.get(key);
-            SPacketCustomPayload payload = AddBoundingBox.getPayload(dimensionType, key, boundingBoxes);
-            if (payload != null)
-                player.connection.sendPacket(payload);
+            PayloadBuilder payloadBuilder = AddBoundingBox.getPayload(dimensionType, key, boundingBoxes);
+            if (payloadBuilder != null)
+                player.connection.sendPacket(payloadBuilder.build());
 
             if (!playerBoundingBoxesCache.containsKey(player)) {
                 playerBoundingBoxesCache.put(player, new HashSet<>());
index 447d125a4b1f11793670aad356f739ea47b4c39d..9bdbadc0d055f83f201f0a5e84187fcecc4c1546 100644 (file)
@@ -2,44 +2,40 @@ package com.irtimaled.bbor.common.messages;
 
 import com.irtimaled.bbor.client.events.AddBoundingBoxReceived;
 import com.irtimaled.bbor.common.models.BoundingBox;
-import io.netty.buffer.Unpooled;
-import net.minecraft.network.PacketBuffer;
-import net.minecraft.network.play.server.SPacketCustomPayload;
-import net.minecraft.util.ResourceLocation;
 import net.minecraft.world.dimension.DimensionType;
 
 import java.util.HashSet;
 import java.util.Set;
 
 public class AddBoundingBox {
-    public static final ResourceLocation NAME = new ResourceLocation("bbor:add_bounding_box");
+    public static final String NAME = "bbor:add_bounding_box";
 
-    public static SPacketCustomPayload getPayload(DimensionType dimensionType, BoundingBox key, Set<BoundingBox> boundingBoxes) {
-        if(!BoundingBoxSerializer.canSerialize(key)) return null;
+    public static PayloadBuilder getPayload(DimensionType dimensionType, BoundingBox key, Set<BoundingBox> boundingBoxes) {
+        if (!BoundingBoxSerializer.canSerialize(key)) return null;
 
-        PacketBuffer buf = new PacketBuffer(Unpooled.buffer());
-        buf.writeVarInt(dimensionType.getId());
-        BoundingBoxSerializer.serialize(key, buf);
+        PayloadBuilder builder = PayloadBuilder.clientBound(NAME)
+                .writeVarInt(dimensionType.getId());
+        BoundingBoxSerializer.serialize(key, builder);
         if (boundingBoxes != null && boundingBoxes.size() > 1) {
             for (BoundingBox boundingBox : boundingBoxes) {
-                BoundingBoxSerializer.serialize(boundingBox, buf);
+                BoundingBoxSerializer.serialize(boundingBox, builder);
             }
         }
-        return new SPacketCustomPayload(NAME, buf);
+        return builder;
     }
 
-    public static AddBoundingBoxReceived getEvent(PacketBuffer buf) {
-        DimensionType dimensionType = DimensionType.getById(buf.readVarInt());
-        BoundingBox key = BoundingBoxDeserializer.deserialize(buf);
+    public static AddBoundingBoxReceived getEvent(PayloadReader reader) {
+        int dimensionId = reader.readVarInt();
+        BoundingBox key = BoundingBoxDeserializer.deserialize(reader);
         if (key == null) return null;
 
         Set<BoundingBox> boundingBoxes = new HashSet<>();
-        while (buf.isReadable()) {
-            BoundingBox boundingBox = BoundingBoxDeserializer.deserialize(buf);
+        while (reader.isReadable()) {
+            BoundingBox boundingBox = BoundingBoxDeserializer.deserialize(reader);
             boundingBoxes.add(boundingBox);
         }
         if (boundingBoxes.size() == 0)
             boundingBoxes.add(key);
-        return new AddBoundingBoxReceived(dimensionType, key, boundingBoxes);
+        return new AddBoundingBoxReceived(DimensionType.getById(dimensionId), key, boundingBoxes);
     }
 }
index 1cb8b50ee1dd6887161065c94dad75503252cee3..2e3d50f7e675a5c1d896605c6c1550f543ab070a 100644 (file)
@@ -2,58 +2,48 @@ package com.irtimaled.bbor.common.messages;
 
 import com.irtimaled.bbor.common.BoundingBoxType;
 import com.irtimaled.bbor.common.models.*;
-import net.minecraft.network.PacketBuffer;
 
 import java.awt.*;
 import java.util.HashSet;
 import java.util.Set;
 
 class BoundingBoxDeserializer {
-    static BoundingBox deserialize(PacketBuffer buf) {
-        if (!buf.isReadable(2)) return null;
+    static BoundingBox deserialize(PayloadReader reader) {
+        if (!reader.isReadable(2)) return null;
 
-        char type = buf.readChar();
+        char type = reader.readChar();
         switch (type) {
             case 'V':
-                return deserializeVillage(buf);
+                return deserializeVillage(reader);
             case 'S':
-                return deserializeStructure(buf);
+                return deserializeStructure(reader);
             case 'M':
-                return deserializeMobSpawner(buf);
+                return deserializeMobSpawner(reader);
         }
         return null;
     }
 
-    private static BoundingBox deserializeStructure(PacketBuffer buf) {
-        BoundingBoxType type = BoundingBoxType.getByNameHash(buf.readInt());
+    private static BoundingBox deserializeStructure(PayloadReader reader) {
+        BoundingBoxType type = BoundingBoxType.getByNameHash(reader.readInt());
         if (type == null) return null;
-        Coords minCoords = deserializeCoords(buf);
-        Coords maxCoords = deserializeCoords(buf);
+        Coords minCoords = reader.readCoords();
+        Coords maxCoords = reader.readCoords();
         return BoundingBoxStructure.from(minCoords, maxCoords, type);
     }
 
-    private static BoundingBox deserializeVillage(PacketBuffer buf) {
-        Coords center = deserializeCoords(buf);
-        int radius = buf.readVarInt();
-        boolean spawnsIronGolems = buf.readBoolean();
-        Color color = new Color(buf.readVarInt());
+    private static BoundingBox deserializeVillage(PayloadReader reader) {
+        Coords center = reader.readCoords();
+        int radius = reader.readVarInt();
+        boolean spawnsIronGolems = reader.readBoolean();
+        Color color = new Color(reader.readVarInt());
         Set<Coords> doors = new HashSet<>();
-        while (buf.isReadable()) {
-            Coords door = deserializeCoords(buf);
-            doors.add(door);
+        while (reader.isReadable()) {
+            doors.add(reader.readCoords());
         }
         return BoundingBoxVillage.from(center, radius, color, spawnsIronGolems, doors);
     }
 
-    private static BoundingBox deserializeMobSpawner(PacketBuffer buf) {
-        Coords center = deserializeCoords(buf);
-        return BoundingBoxMobSpawner.from(center);
-    }
-
-    private static Coords deserializeCoords(PacketBuffer buf) {
-        int x = buf.readVarInt();
-        int y = buf.readVarInt();
-        int z = buf.readVarInt();
-        return new Coords(x, y, z);
+    private static BoundingBox deserializeMobSpawner(PayloadReader reader) {
+        return BoundingBoxMobSpawner.from(reader.readCoords());
     }
 }
index 2d902a7cfcb26c2af223861b1d880a86a2ae49ca..024a6e3548c55224399e4a15f186923358e58ad9 100644 (file)
@@ -1,67 +1,51 @@
 package com.irtimaled.bbor.common.messages;
 
 import com.irtimaled.bbor.common.models.*;
-import net.minecraft.network.PacketBuffer;
 
-import java.awt.*;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.function.BiConsumer;
 
 class BoundingBoxSerializer {
-    private static final Map<Class, BiConsumer<BoundingBox, PacketBuffer>> serializers = new HashMap<>();
+    private static final Map<Class, BiConsumer<BoundingBox, PayloadBuilder>> serializers = new HashMap<>();
 
     static {
-        serializers.put(BoundingBoxVillage.class, (bb, buf) -> serializeVillage((BoundingBoxVillage) bb, buf));
-        serializers.put(BoundingBoxStructure.class, (bb, buf) -> serializeStructure((BoundingBoxStructure) bb, buf));
-        serializers.put(BoundingBoxMobSpawner.class, (bb, buf) -> serializeMobSpawner((BoundingBoxMobSpawner) bb, buf));
+        serializers.put(BoundingBoxVillage.class, (bb, pb) -> serializeVillage((BoundingBoxVillage) bb, pb));
+        serializers.put(BoundingBoxStructure.class, (bb, pb) -> serializeStructure((BoundingBoxStructure) bb, pb));
+        serializers.put(BoundingBoxMobSpawner.class, (bb, pb) -> serializeMobSpawner((BoundingBoxMobSpawner) bb, pb));
     }
 
     static boolean canSerialize(BoundingBox key) {
         return serializers.containsKey(key.getClass());
     }
 
-    static void serialize(BoundingBox boundingBox, PacketBuffer buf) {
-        BiConsumer<BoundingBox, PacketBuffer> serializer = serializers.get(boundingBox.getClass());
+    static void serialize(BoundingBox boundingBox, PayloadBuilder builder) {
+        BiConsumer<BoundingBox, PayloadBuilder> serializer = serializers.get(boundingBox.getClass());
         if (serializer == null) return;
 
-        serializer.accept(boundingBox, buf);
+        serializer.accept(boundingBox, builder);
     }
 
-    private static void serializeVillage(BoundingBoxVillage boundingBox, PacketBuffer buf) {
-        buf.writeChar('V');
-        serializeCoords(boundingBox.getCenter(), buf);
-        buf.writeVarInt(boundingBox.getRadius());
-        buf.writeBoolean(boundingBox.getSpawnsIronGolems());
-        serializeColor(boundingBox.getColor(), buf);
+    private static void serializeVillage(BoundingBoxVillage boundingBox, PayloadBuilder builder) {
+        builder.writeChar('V')
+                .writeCoords(boundingBox.getCenter())
+                .writeVarInt(boundingBox.getRadius())
+                .writeBoolean(boundingBox.getSpawnsIronGolems())
+                .writeVarInt(boundingBox.getColor().getRGB());
         for (Coords door : boundingBox.getDoors()) {
-            serializeCoords(door, buf);
+            builder.writeCoords(door);
         }
     }
 
-    private static void serializeStructure(BoundingBoxStructure boundingBox, PacketBuffer buf) {
-        buf.writeChar('S');
-        buf.writeInt(boundingBox.getTypeName().hashCode());
-        serializeCuboid(boundingBox, buf);
+    private static void serializeStructure(BoundingBoxStructure boundingBox, PayloadBuilder builder) {
+        builder.writeChar('S')
+                .writeInt(boundingBox.getTypeName().hashCode())
+                .writeCoords(boundingBox.getMinCoords())
+                .writeCoords(boundingBox.getMaxCoords());
     }
 
-    private static void serializeMobSpawner(BoundingBoxMobSpawner boundingBox, PacketBuffer buf) {
-        buf.writeChar('M');
-        serializeCoords(boundingBox.getCoords(), buf);
-    }
-
-    private static void serializeColor(Color color, PacketBuffer buf) {
-        buf.writeVarInt(color.getRGB());
-    }
-
-    private static void serializeCuboid(BoundingBox boundingBox, PacketBuffer buf) {
-        serializeCoords(boundingBox.getMinCoords(), buf);
-        serializeCoords(boundingBox.getMaxCoords(), buf);
-    }
-
-    private static void serializeCoords(Coords coords, PacketBuffer buf) {
-        buf.writeVarInt(coords.getX());
-        buf.writeVarInt(coords.getY());
-        buf.writeVarInt(coords.getZ());
+    private static void serializeMobSpawner(BoundingBoxMobSpawner boundingBox, PayloadBuilder builder) {
+        builder.writeChar('M')
+                .writeCoords(boundingBox.getCoords());
     }
 }
index d580029f3f33c2e7be5c77a6820af73988565736..054fb8823c2584d80bceb97e064f9cb4ca7fc908 100644 (file)
@@ -2,27 +2,21 @@ package com.irtimaled.bbor.common.messages;
 
 import com.irtimaled.bbor.client.events.InitializeClientReceived;
 import com.irtimaled.bbor.common.models.WorldData;
-import io.netty.buffer.Unpooled;
-import net.minecraft.network.PacketBuffer;
-import net.minecraft.network.play.server.SPacketCustomPayload;
-import net.minecraft.util.ResourceLocation;
 
 public class InitializeClient {
-    public static final ResourceLocation NAME = new ResourceLocation("bbor:initialize");
+    public static final String NAME = "bbor:initialize";
 
-    public static SPacketCustomPayload getPayload(WorldData worldData) {
-        PacketBuffer buf = new PacketBuffer(Unpooled.buffer());
-        buf.writeLong(worldData.getSeed());
-        buf.writeInt(worldData.getSpawnX());
-        buf.writeInt(worldData.getSpawnZ());
-
-        return new SPacketCustomPayload(NAME, buf);
+    public static PayloadBuilder getPayload(WorldData worldData) {
+        return PayloadBuilder.clientBound(NAME)
+                .writeLong(worldData.getSeed())
+                .writeInt(worldData.getSpawnX())
+                .writeInt(worldData.getSpawnZ());
     }
 
-    public static InitializeClientReceived getEvent(PacketBuffer buf) {
-        long seed = buf.readLong();
-        int spawnX = buf.readInt();
-        int spawnZ = buf.readInt();
+    public static InitializeClientReceived getEvent(PayloadReader reader) {
+        long seed = reader.readLong();
+        int spawnX = reader.readInt();
+        int spawnZ = reader.readInt();
         return new InitializeClientReceived(seed, spawnX, spawnZ);
     }
 }
diff --git a/src/main/java/com/irtimaled/bbor/common/messages/PayloadBuilder.java b/src/main/java/com/irtimaled/bbor/common/messages/PayloadBuilder.java
new file mode 100644 (file)
index 0000000..ec2579a
--- /dev/null
@@ -0,0 +1,79 @@
+package com.irtimaled.bbor.common.messages;
+
+import com.irtimaled.bbor.common.models.Coords;
+import io.netty.buffer.Unpooled;
+import net.minecraft.network.Packet;
+import net.minecraft.network.PacketBuffer;
+import net.minecraft.network.play.client.CPacketCustomPayload;
+import net.minecraft.network.play.server.SPacketCustomPayload;
+import net.minecraft.util.ResourceLocation;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.BiFunction;
+
+public class PayloadBuilder {
+    private static Map<String, ResourceLocation> packetNames = new HashMap<>();
+
+    static PayloadBuilder clientBound(String name) {
+        return new PayloadBuilder(packetNames.computeIfAbsent(name, ResourceLocation::new), SPacketCustomPayload::new);
+    }
+
+    static PayloadBuilder serverBound(String name) {
+        return new PayloadBuilder(packetNames.computeIfAbsent(name, ResourceLocation::new), CPacketCustomPayload::new);
+    }
+
+    private final ResourceLocation name;
+    private final BiFunction<ResourceLocation, PacketBuffer, Packet<?>> packetBuilder;
+    private final PacketBuffer buffer;
+
+    private PayloadBuilder(ResourceLocation name, BiFunction<ResourceLocation, PacketBuffer, Packet<?>> packetBuilder) {
+        this.name = name;
+        this.buffer = new PacketBuffer(Unpooled.buffer());
+        this.packetBuilder = packetBuilder;
+    }
+
+    private Packet<?> packet;
+
+    public Packet<?> build() {
+        if (packet == null)
+            packet = packetBuilder.apply(name, buffer);
+        return packet;
+    }
+
+    PayloadBuilder writeLong(long value) {
+        buffer.writeLong(value);
+        packet = null;
+        return this;
+    }
+
+    PayloadBuilder writeInt(int value) {
+        buffer.writeInt(value);
+        packet = null;
+        return this;
+    }
+
+    PayloadBuilder writeVarInt(int value) {
+        buffer.writeVarInt(value);
+        packet = null;
+        return this;
+    }
+
+    PayloadBuilder writeChar(char value) {
+        buffer.writeChar(value);
+        packet = null;
+        return this;
+    }
+
+    PayloadBuilder writeBoolean(boolean value) {
+        buffer.writeBoolean(value);
+        packet = null;
+        return this;
+    }
+
+    PayloadBuilder writeCoords(Coords coords) {
+        return writeVarInt(coords.getX())
+                .writeVarInt(coords.getY())
+                .writeVarInt(coords.getZ());
+    }
+}
diff --git a/src/main/java/com/irtimaled/bbor/common/messages/PayloadReader.java b/src/main/java/com/irtimaled/bbor/common/messages/PayloadReader.java
new file mode 100644 (file)
index 0000000..8af867d
--- /dev/null
@@ -0,0 +1,47 @@
+package com.irtimaled.bbor.common.messages;
+
+import com.irtimaled.bbor.common.models.Coords;
+import net.minecraft.network.PacketBuffer;
+
+public class PayloadReader {
+    private PacketBuffer buffer;
+
+    public PayloadReader(PacketBuffer buffer) {
+        this.buffer = buffer;
+    }
+
+    long readLong() {
+        return buffer.readLong();
+    }
+
+    int readInt() {
+        return buffer.readInt();
+    }
+
+    int readVarInt() {
+        return buffer.readVarInt();
+    }
+
+    boolean isReadable() {
+        return buffer.isReadable();
+    }
+
+    boolean isReadable(int count) {
+        return buffer.isReadable(count);
+    }
+
+    char readChar() {
+        return buffer.readChar();
+    }
+
+    boolean readBoolean() {
+        return buffer.readBoolean();
+    }
+
+    Coords readCoords() {
+        int x = readVarInt();
+        int y = readVarInt();
+        int z = readVarInt();
+        return new Coords(x, y, z);
+    }
+}
index 605f53a46ced0a74a6410b89f2d0204814e17ad1..20eaf721ca47a38f5538b9fe05a88aae928e3a1f 100644 (file)
@@ -2,30 +2,25 @@ package com.irtimaled.bbor.common.messages;
 
 import com.irtimaled.bbor.client.events.RemoveBoundingBoxReceived;
 import com.irtimaled.bbor.common.models.BoundingBox;
-import io.netty.buffer.Unpooled;
-import net.minecraft.network.PacketBuffer;
-import net.minecraft.network.play.server.SPacketCustomPayload;
-import net.minecraft.util.ResourceLocation;
 import net.minecraft.world.dimension.DimensionType;
 
 public class RemoveBoundingBox {
-    public static final ResourceLocation NAME = new ResourceLocation("bbor:remove_bounding_box");
+    public static final String NAME = "bbor:remove_bounding_box";
 
-    public static SPacketCustomPayload getPayload(DimensionType dimensionType, BoundingBox key) {
-        if(!BoundingBoxSerializer.canSerialize(key)) return null;
+    public static PayloadBuilder getPayload(DimensionType dimensionType, BoundingBox key) {
+        if (!BoundingBoxSerializer.canSerialize(key)) return null;
 
-        PacketBuffer buf = new PacketBuffer(Unpooled.buffer());
-        buf.writeVarInt(dimensionType.getId());
-        BoundingBoxSerializer.serialize(key, buf);
-
-        return new SPacketCustomPayload(NAME, buf);
+        PayloadBuilder builder = PayloadBuilder.clientBound(NAME)
+                .writeVarInt(dimensionType.getId());
+        BoundingBoxSerializer.serialize(key, builder);
+        return builder;
     }
 
-    public static RemoveBoundingBoxReceived getEvent(PacketBuffer buf) {
-        DimensionType dimensionType = DimensionType.getById(buf.readVarInt());
-        BoundingBox key = BoundingBoxDeserializer.deserialize(buf);
-        if(key == null) return null;
+    public static RemoveBoundingBoxReceived getEvent(PayloadReader reader) {
+        int dimensionId = reader.readVarInt();
+        BoundingBox key = BoundingBoxDeserializer.deserialize(reader);
+        if (key == null) return null;
 
-        return new RemoveBoundingBoxReceived(dimensionType, key);
+        return new RemoveBoundingBoxReceived(DimensionType.getById(dimensionId), key);
     }
 }
index 09a4dfd60fc12294f412666a59259e8820150749..5ddf390682d13bcb5012f8bbc6facee1541158df 100644 (file)
@@ -1,14 +1,9 @@
 package com.irtimaled.bbor.common.messages;
 
-import io.netty.buffer.Unpooled;
-import net.minecraft.network.PacketBuffer;
-import net.minecraft.network.play.client.CPacketCustomPayload;
-import net.minecraft.util.ResourceLocation;
-
 public class SubscribeToServer {
-    public static final ResourceLocation NAME = new ResourceLocation("bbor:subscribe");
+    public static final String NAME = "bbor:subscribe";
 
-    public static CPacketCustomPayload getPayload() {
-        return new CPacketCustomPayload(NAME, new PacketBuffer(Unpooled.buffer()));
+    public static PayloadBuilder getPayload() {
+        return PayloadBuilder.serverBound(NAME);
     }
 }
index c95369ff06b7184d61d4496a515fb5dda461a54c..9f6693acf4eee0b1802e763b88c6c66fd1b09271 100644 (file)
@@ -20,7 +20,7 @@ public class MixinCPacketCustomPayload {
 
     @Redirect(method = "processPacket", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/play/INetHandlerPlayServer;processCustomPayload(Lnet/minecraft/network/play/client/CPacketCustomPayload;)V"))
     private void processPacket(INetHandlerPlayServer netHandlerPlayServer, CPacketCustomPayload packet) {
-        if (this.channel.equals(SubscribeToServer.NAME)) {
+        if (this.channel.toString().equals(SubscribeToServer.NAME)) {
             EntityPlayerMP player = ((NetHandlerPlayServer) netHandlerPlayServer).player;
             EventBus.publish(new PlayerSubscribed(player));
         } else {
index 360f2b52be81951ddefcd4d1c55ee4d72002e12b..adb72e7addef9db1e28d25e5d74e6677069248fb 100644 (file)
@@ -1,10 +1,7 @@
 package com.irtimaled.bbor.mixin.network.play.server;
 
 import com.irtimaled.bbor.common.EventBus;
-import com.irtimaled.bbor.common.messages.AddBoundingBox;
-import com.irtimaled.bbor.common.messages.InitializeClient;
-import com.irtimaled.bbor.common.messages.RemoveBoundingBox;
-import com.irtimaled.bbor.common.messages.SubscribeToServer;
+import com.irtimaled.bbor.common.messages.*;
 import net.minecraft.client.network.NetHandlerPlayClient;
 import net.minecraft.network.PacketBuffer;
 import net.minecraft.network.play.INetHandlerPlayClient;
@@ -25,15 +22,25 @@ public abstract class MixinSPacketCustomPayload {
         PacketBuffer data = null;
         try {
             data = packet.getBufferData();
-            if (InitializeClient.NAME.equals(channel)) {
-                EventBus.publish(InitializeClient.getEvent(data));
-                ((NetHandlerPlayClient) netHandlerPlayClient).sendPacket(SubscribeToServer.getPayload());
-            } else if (AddBoundingBox.NAME.equals(channel)) {
-                EventBus.publish(AddBoundingBox.getEvent(data));
-            } else if (RemoveBoundingBox.NAME.equals(channel)) {
-                EventBus.publish(RemoveBoundingBox.getEvent(data));
-            } else {
-                netHandlerPlayClient.handleCustomPayload(packet);
+            PayloadReader reader = new PayloadReader(data);
+            switch (channel.toString()) {
+                case InitializeClient.NAME: {
+                    EventBus.publish(InitializeClient.getEvent(reader));
+                    ((NetHandlerPlayClient) netHandlerPlayClient).sendPacket(SubscribeToServer.getPayload().build());
+                    break;
+                }
+                case AddBoundingBox.NAME: {
+                    EventBus.publish(AddBoundingBox.getEvent(reader));
+                    break;
+                }
+                case RemoveBoundingBox.NAME: {
+                    EventBus.publish(RemoveBoundingBox.getEvent(reader));
+                    break;
+                }
+                default: {
+                    netHandlerPlayClient.handleCustomPayload(packet);
+                    break;
+                }
             }
         } finally {
             if (data != null)