1 package com.irtimaled.bbor.common.messages;
3 import com.irtimaled.bbor.common.BoundingBoxType;
4 import com.irtimaled.bbor.common.models.AbstractBoundingBox;
5 import com.irtimaled.bbor.common.models.BoundingBoxCuboid;
6 import com.irtimaled.bbor.common.models.BoundingBoxVillage;
7 import com.irtimaled.bbor.common.models.Coords;
10 import java.util.HashSet;
13 class BoundingBoxDeserializer {
14 static AbstractBoundingBox deserialize(PayloadReader reader) {
15 if (!reader.isReadable(2)) return null;
17 char type = reader.readChar();
20 return deserializeVillage(reader);
22 return deserializeStructure(reader);
27 private static AbstractBoundingBox deserializeStructure(PayloadReader reader) {
28 BoundingBoxType type = BoundingBoxType.getByNameHash(reader.readInt());
29 if (type == null) return null;
30 Coords minCoords = reader.readCoords();
31 Coords maxCoords = reader.readCoords();
32 return BoundingBoxCuboid.from(minCoords, maxCoords, type);
35 private static AbstractBoundingBox deserializeVillage(PayloadReader reader) {
36 Coords center = reader.readCoords();
37 int radius = reader.readVarInt();
38 boolean spawnsIronGolems = reader.readBoolean();
39 Color color = new Color(reader.readVarInt());
40 Set<Coords> doors = new HashSet<>();
41 while (reader.isReadable()) {
42 doors.add(reader.readCoords());
44 return BoundingBoxVillage.from(center, radius, color, spawnsIronGolems, doors);