1 package com.irtimaled.bbor.messages;
3 import com.irtimaled.bbor.*;
4 import io.netty.buffer.ByteBuf;
5 import net.minecraft.util.BlockPos;
6 import net.minecraftforge.fml.common.network.ByteBufUtils;
10 public class BoundingBoxDeserializer {
11 public static BoundingBox deserialize(ByteBuf buf) {
12 char type = (char) ByteBufUtils.readVarShort(buf);
15 return deserializeVillage(buf);
17 return deserializeStructure(buf);
22 private static BoundingBox deserializeStructure(ByteBuf buf) {
23 BlockPos minBlockPos = deserializeBlockPos(buf);
24 BlockPos maxBlockPos = deserializeBlockPos(buf);
25 Color color = new Color(ByteBufUtils.readVarInt(buf, 5));
26 return BoundingBoxStructure.from(minBlockPos, maxBlockPos, color);
29 private static BoundingBox deserializeVillage(ByteBuf buf) {
30 BlockPos center = deserializeBlockPos(buf);
31 int radius = ByteBufUtils.readVarInt(buf, 5);
32 boolean spawnsIronGolems = ByteBufUtils.readVarShort(buf) == 1;
33 Color color = new Color(ByteBufUtils.readVarInt(buf, 5));
34 return BoundingBoxVillage.from(center, radius, spawnsIronGolems, color);
37 private static BlockPos deserializeBlockPos(ByteBuf buf) {
38 int x = ByteBufUtils.readVarInt(buf, 5);
39 int y = ByteBufUtils.readVarInt(buf, 5);
40 int z = ByteBufUtils.readVarInt(buf, 5);
41 return new BlockPos(x, y, z);