]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/blobdiff - src/main/java/com/irtimaled/bbor/common/messages/BoundingBoxDeserializer.java
1.18.1
[BoundingBoxOutlineReloaded.git] / src / main / java / com / irtimaled / bbor / common / messages / BoundingBoxDeserializer.java
index 1cb8b50ee1dd6887161065c94dad75503252cee3..e6930c373817e262082cfd1a12fd12fae81cd3de 100644 (file)
@@ -1,59 +1,23 @@
 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;
+import com.irtimaled.bbor.common.models.AbstractBoundingBox;
+import com.irtimaled.bbor.common.models.BoundingBoxCuboid;
+import com.irtimaled.bbor.common.models.Coords;
 
 class BoundingBoxDeserializer {
-    static BoundingBox deserialize(PacketBuffer buf) {
-        if (!buf.isReadable(2)) return null;
+    static AbstractBoundingBox deserialize(PayloadReader reader) {
+        if (!reader.isReadable(2)) return null;
 
-        char type = buf.readChar();
-        switch (type) {
-            case 'V':
-                return deserializeVillage(buf);
-            case 'S':
-                return deserializeStructure(buf);
-            case 'M':
-                return deserializeMobSpawner(buf);
-        }
-        return null;
+        char type = reader.readChar();
+        return type == 'S' ? deserializeStructure(reader) : null;
     }
 
-    private static BoundingBox deserializeStructure(PacketBuffer buf) {
-        BoundingBoxType type = BoundingBoxType.getByNameHash(buf.readInt());
+    private static AbstractBoundingBox deserializeStructure(PayloadReader reader) {
+        BoundingBoxType type = BoundingBoxType.getByNameHash(reader.readInt());
         if (type == null) return null;
-        Coords minCoords = deserializeCoords(buf);
-        Coords maxCoords = deserializeCoords(buf);
-        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());
-        Set<Coords> doors = new HashSet<>();
-        while (buf.isReadable()) {
-            Coords door = deserializeCoords(buf);
-            doors.add(door);
-        }
-        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);
+        Coords minCoords = reader.readCoords();
+        Coords maxCoords = reader.readCoords();
+        return BoundingBoxCuboid.from(minCoords, maxCoords, type);
     }
 }