]> 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 2766663ff591090bbe4aec8b0fee54a60853e00e..e6930c373817e262082cfd1a12fd12fae81cd3de 100644 (file)
@@ -1,61 +1,23 @@
 package com.irtimaled.bbor.common.messages;
 
 import com.irtimaled.bbor.common.BoundingBoxType;
-import com.irtimaled.bbor.common.models.BoundingBox;
-import com.irtimaled.bbor.common.models.BoundingBoxMobSpawner;
-import com.irtimaled.bbor.common.models.BoundingBoxStructure;
-import com.irtimaled.bbor.common.models.BoundingBoxVillage;
-import net.minecraft.network.PacketBuffer;
-import net.minecraft.util.math.BlockPos;
-
-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) {
-        char type = buf.readChar();
-        switch (type) {
-            case 'V':
-                return deserializeVillage(buf);
-            case 'S':
-                return deserializeStructure(buf);
-            case 'M':
-                return deserializeMobSpawner(buf);
-        }
-        return null;
-    }
-
-    private static BoundingBox deserializeStructure(PacketBuffer buf) {
-        BoundingBoxType type = BoundingBoxType.getByNameHash(buf.readInt());
-        if(type == null) return null;
-        BlockPos minBlockPos = deserializeBlockPos(buf);
-        BlockPos maxBlockPos = deserializeBlockPos(buf);
-        return BoundingBoxStructure.from(minBlockPos, maxBlockPos, type);
-    }
-
-    private static BoundingBox deserializeVillage(PacketBuffer buf) {
-        BlockPos center = deserializeBlockPos(buf);
-        int radius = buf.readVarInt();
-        boolean spawnsIronGolems = buf.readBoolean();
-        Color color = new Color(buf.readVarInt());
-        Set<BlockPos> doors = new HashSet<>();
-        while (buf.isReadable()) {
-            BlockPos door = deserializeBlockPos(buf);
-            doors.add(door);
-        }
-        return BoundingBoxVillage.from(center, radius, color, spawnsIronGolems, doors);
-    }
+    static AbstractBoundingBox deserialize(PayloadReader reader) {
+        if (!reader.isReadable(2)) return null;
 
-    private static BoundingBox deserializeMobSpawner(PacketBuffer buf) {
-        BlockPos center = deserializeBlockPos(buf);
-        return BoundingBoxMobSpawner.from(center);
+        char type = reader.readChar();
+        return type == 'S' ? deserializeStructure(reader) : null;
     }
 
-    private static BlockPos deserializeBlockPos(PacketBuffer buf) {
-        int x = buf.readVarInt();
-        int y = buf.readVarInt();
-        int z = buf.readVarInt();
-        return new BlockPos(x, y, z);
+    private static AbstractBoundingBox deserializeStructure(PayloadReader reader) {
+        BoundingBoxType type = BoundingBoxType.getByNameHash(reader.readInt());
+        if (type == null) return null;
+        Coords minCoords = reader.readCoords();
+        Coords maxCoords = reader.readCoords();
+        return BoundingBoxCuboid.from(minCoords, maxCoords, type);
     }
 }