diff --git a/core/src/main/java/de/bluecolored/bluemap/core/map/renderstate/CellStorage.java b/core/src/main/java/de/bluecolored/bluemap/core/map/renderstate/CellStorage.java index 0d9ee99b..713a696e 100644 --- a/core/src/main/java/de/bluecolored/bluemap/core/map/renderstate/CellStorage.java +++ b/core/src/main/java/de/bluecolored/bluemap/core/map/renderstate/CellStorage.java @@ -25,7 +25,6 @@ package de.bluecolored.bluemap.core.map.renderstate; import com.flowpowered.math.vector.Vector2i; -import com.google.gson.reflect.TypeToken; import de.bluecolored.bluemap.core.logger.Logger; import de.bluecolored.bluemap.core.storage.GridStorage; import de.bluecolored.bluemap.core.storage.compression.CompressedInputStream; @@ -33,6 +32,7 @@ import de.bluecolored.bluemap.core.util.PalettedArrayAdapter; import de.bluecolored.bluemap.core.util.RegistryAdapter; import de.bluecolored.bluenbt.BlueNBT; +import de.bluecolored.bluenbt.TypeToken; import lombok.Getter; import java.io.IOException; @@ -44,8 +44,8 @@ abstract class CellStorage { private static final BlueNBT BLUE_NBT = new BlueNBT(); static { - BLUE_NBT.register(TypeToken.get(TileState.class), new RegistryAdapter<>(TileState.REGISTRY, Key.BLUEMAP_NAMESPACE, TileState.UNKNOWN)); - BLUE_NBT.register(TypeToken.get(TileState[].class), new PalettedArrayAdapter<>(BLUE_NBT, TileState.class)); + BLUE_NBT.register(TypeToken.of(TileState.class), new RegistryAdapter<>(TileState.REGISTRY, Key.BLUEMAP_NAMESPACE, TileState.UNKNOWN)); + BLUE_NBT.register(TypeToken.of(TileState[].class), new PalettedArrayAdapter<>(BLUE_NBT, TileState.class)); } private static final int CACHE_SIZE = 4; diff --git a/core/src/main/java/de/bluecolored/bluemap/core/map/renderstate/TileInfoRegion.java b/core/src/main/java/de/bluecolored/bluemap/core/map/renderstate/TileInfoRegion.java index 475da710..4048fc67 100644 --- a/core/src/main/java/de/bluecolored/bluemap/core/map/renderstate/TileInfoRegion.java +++ b/core/src/main/java/de/bluecolored/bluemap/core/map/renderstate/TileInfoRegion.java @@ -24,12 +24,9 @@ */ package de.bluecolored.bluemap.core.map.renderstate; -import com.google.gson.reflect.TypeToken; import de.bluecolored.bluemap.core.util.Key; import de.bluecolored.bluemap.core.util.RegistryAdapter; -import de.bluecolored.bluenbt.BlueNBT; -import de.bluecolored.bluenbt.NBTName; -import de.bluecolored.bluenbt.NBTPostDeserialize; +import de.bluecolored.bluenbt.*; import lombok.AllArgsConstructor; import lombok.Data; import lombok.Getter; @@ -132,7 +129,7 @@ private static class PaletteOnly { private final static BlueNBT BLUE_NBT = new BlueNBT(); static { - BLUE_NBT.register(TypeToken.get(TileState.class), new RegistryAdapter<>(TileState.REGISTRY, Key.BLUEMAP_NAMESPACE, TileState.UNKNOWN)); + BLUE_NBT.register(TypeToken.of(TileState.class), new RegistryAdapter<>(TileState.REGISTRY, Key.BLUEMAP_NAMESPACE, TileState.UNKNOWN)); } @NBTName("tile-states") diff --git a/core/src/main/java/de/bluecolored/bluemap/core/util/PalettedArrayAdapter.java b/core/src/main/java/de/bluecolored/bluemap/core/util/PalettedArrayAdapter.java index fea7ae19..550e0bef 100644 --- a/core/src/main/java/de/bluecolored/bluemap/core/util/PalettedArrayAdapter.java +++ b/core/src/main/java/de/bluecolored/bluemap/core/util/PalettedArrayAdapter.java @@ -24,11 +24,7 @@ */ package de.bluecolored.bluemap.core.util; -import com.google.gson.reflect.TypeToken; -import de.bluecolored.bluenbt.BlueNBT; -import de.bluecolored.bluenbt.NBTReader; -import de.bluecolored.bluenbt.NBTWriter; -import de.bluecolored.bluenbt.TypeAdapter; +import de.bluecolored.bluenbt.*; import de.bluecolored.bluenbt.adapter.ArrayAdapterFactory; import lombok.RequiredArgsConstructor; @@ -45,7 +41,7 @@ public class PalettedArrayAdapter implements TypeAdapter { @SuppressWarnings("unchecked") public PalettedArrayAdapter(BlueNBT blueNBT, Class type) { this.type = type; - this.paletteAdapter = ArrayAdapterFactory.INSTANCE.create((TypeToken) TypeToken.getArray(type), blueNBT).orElseThrow(); + this.paletteAdapter = ArrayAdapterFactory.INSTANCE.create((TypeToken) TypeToken.array(type), blueNBT).orElseThrow(); } @SuppressWarnings("unchecked") diff --git a/core/src/main/java/de/bluecolored/bluemap/core/world/block/entity/BlockEntity.java b/core/src/main/java/de/bluecolored/bluemap/core/world/block/entity/BlockEntity.java index de36da57..5b42e134 100644 --- a/core/src/main/java/de/bluecolored/bluemap/core/world/block/entity/BlockEntity.java +++ b/core/src/main/java/de/bluecolored/bluemap/core/world/block/entity/BlockEntity.java @@ -24,12 +24,8 @@ */ package de.bluecolored.bluemap.core.world.block.entity; -import com.google.gson.reflect.TypeToken; import de.bluecolored.bluemap.core.util.Key; -import de.bluecolored.bluenbt.BlueNBT; -import de.bluecolored.bluenbt.NBTDeserializer; -import de.bluecolored.bluenbt.NBTReader; -import de.bluecolored.bluenbt.TypeDeserializer; +import de.bluecolored.bluenbt.*; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -65,7 +61,7 @@ public static class BlockEntityDeserializer implements TypeDeserializer raw = (Map) blueNBT.read(reader, TypeToken.getParameterized(Map.class, String.class, Object.class)); + Map raw = (Map) blueNBT.read(reader, TypeToken.of(Map.class, String.class, Object.class)); String id = (String) raw.get("id"); if (id == null) return null; diff --git a/core/src/main/java/de/bluecolored/bluemap/core/world/mca/MCAUtil.java b/core/src/main/java/de/bluecolored/bluemap/core/world/mca/MCAUtil.java index 8772f2e1..2c8bcce1 100644 --- a/core/src/main/java/de/bluecolored/bluemap/core/world/mca/MCAUtil.java +++ b/core/src/main/java/de/bluecolored/bluemap/core/world/mca/MCAUtil.java @@ -24,13 +24,14 @@ */ package de.bluecolored.bluemap.core.world.mca; -import com.google.gson.reflect.TypeToken; import de.bluecolored.bluemap.core.util.Key; import de.bluecolored.bluemap.core.world.BlockState; import de.bluecolored.bluemap.core.world.block.entity.BlockEntity; import de.bluecolored.bluemap.core.world.mca.data.BlockStateDeserializer; import de.bluecolored.bluemap.core.world.mca.data.KeyDeserializer; import de.bluecolored.bluenbt.BlueNBT; +import de.bluecolored.bluenbt.NamingStrategy; +import de.bluecolored.bluenbt.TypeToken; import org.jetbrains.annotations.Contract; public class MCAUtil { @@ -39,26 +40,13 @@ public class MCAUtil { @Contract(value = "_ -> param1", mutates = "param1") public static BlueNBT addCommonNbtAdapters(BlueNBT nbt) { - nbt.register(TypeToken.get(BlockState.class), new BlockStateDeserializer()); - nbt.register(TypeToken.get(Key.class), new KeyDeserializer()); - nbt.register(TypeToken.get(BlockEntity.class), new BlockEntity.BlockEntityDeserializer(nbt)); + nbt.setNamingStrategy(NamingStrategy.lowerCaseWithDelimiter("_")); + nbt.register(TypeToken.of(BlockState.class), new BlockStateDeserializer()); + nbt.register(TypeToken.of(Key.class), new KeyDeserializer()); + nbt.register(TypeToken.of(BlockEntity.class), new BlockEntity.BlockEntityDeserializer(nbt)); return nbt; } - /** - * Having a long array where each long contains as many values as fit in it without overflowing, returning the "valueIndex"-th value when each value has "bitsPerValue" bits. - */ - public static long getValueFromLongArray(long[] data, int valueIndex, int bitsPerValue) { - int valuesPerLong = 64 / bitsPerValue; - int longIndex = valueIndex / valuesPerLong; - int bitIndex = (valueIndex % valuesPerLong) * bitsPerValue; - - if (longIndex >= data.length) return 0; - long value = data[longIndex] >>> bitIndex; - - return value & (0xFFFFFFFFFFFFFFFFL >>> -bitsPerValue); - } - /** * Treating the long array "data" as a continuous stream of bits, returning the "valueIndex"-th value when each value has "bitsPerValue" bits. */ diff --git a/core/src/main/java/de/bluecolored/bluemap/core/world/mca/MCAWorld.java b/core/src/main/java/de/bluecolored/bluemap/core/world/mca/MCAWorld.java index 7363d534..7754b7f7 100644 --- a/core/src/main/java/de/bluecolored/bluemap/core/world/mca/MCAWorld.java +++ b/core/src/main/java/de/bluecolored/bluemap/core/world/mca/MCAWorld.java @@ -28,7 +28,6 @@ import com.flowpowered.math.vector.Vector3i; import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.LoadingCache; -import com.google.gson.reflect.TypeToken; import de.bluecolored.bluemap.core.BlueMap; import de.bluecolored.bluemap.core.logger.Logger; import de.bluecolored.bluemap.core.resources.pack.datapack.DataPack; @@ -43,6 +42,7 @@ import de.bluecolored.bluemap.core.world.mca.data.LevelData; import de.bluecolored.bluemap.core.world.mca.region.RegionType; import de.bluecolored.bluenbt.BlueNBT; +import de.bluecolored.bluenbt.TypeToken; import lombok.Getter; import lombok.ToString; @@ -286,7 +286,7 @@ public static Path resolveDimensionFolder(Path worldFolder, Key dimension) { private static BlueNBT createBlueNBTForDataPack(DataPack dataPack) { BlueNBT blueNBT = MCAUtil.addCommonNbtAdapters(new BlueNBT()); - blueNBT.register(TypeToken.get(DimensionType.class), new DimensionTypeDeserializer(blueNBT, dataPack)); + blueNBT.register(TypeToken.of(DimensionType.class), new DimensionTypeDeserializer(blueNBT, dataPack)); return blueNBT; } diff --git a/core/src/main/java/de/bluecolored/bluemap/core/world/mca/chunk/Chunk_1_13.java b/core/src/main/java/de/bluecolored/bluemap/core/world/mca/chunk/Chunk_1_13.java index 55e5cc48..9a238e76 100644 --- a/core/src/main/java/de/bluecolored/bluemap/core/world/mca/chunk/Chunk_1_13.java +++ b/core/src/main/java/de/bluecolored/bluemap/core/world/mca/chunk/Chunk_1_13.java @@ -292,38 +292,68 @@ public int getSectionY() { @Getter @SuppressWarnings("FieldMayBeFinal") public static class Data extends MCAChunk.Data { + + @NBTName("Level") private Level level = new Level(); + } @Getter @SuppressWarnings("FieldMayBeFinal") public static class Level { + + @NBTName("Status") private Key status = STATUS_EMPTY; + + @NBTName("InhabitedTime") private long inhabitedTime = 0; + + @NBTName("Heightmaps") private HeightmapsData heightmaps = new HeightmapsData(); + + @NBTName("Sections") private SectionData @Nullable [] sections = null; + + @NBTName("Biomes") private int[] biomes = EMPTY_INT_ARRAY; @NBTName("TileEntities") @NBTDeserializer(LenientBlockEntityArrayDeserializer.class) private @Nullable BlockEntity [] blockEntities = EMPTY_BLOCK_ENTITIES_ARRAY; + } @Getter @SuppressWarnings("FieldMayBeFinal") public static class HeightmapsData { - @NBTName("WORLD_SURFACE") private long[] worldSurface = EMPTY_LONG_ARRAY; - @NBTName("OCEAN_FLOOR") private long[] oceanFloor = EMPTY_LONG_ARRAY; + + @NBTName("WORLD_SURFACE") + private long[] worldSurface = EMPTY_LONG_ARRAY; + + @NBTName("OCEAN_FLOOR") + private long[] oceanFloor = EMPTY_LONG_ARRAY; + } @Getter @SuppressWarnings("FieldMayBeFinal") public static class SectionData { + + @NBTName("Y") private int y = 0; + + @NBTName("BlockLight") private byte[] blockLight = EMPTY_BYTE_ARRAY; + + @NBTName("SkyLight") private byte[] skyLight = EMPTY_BYTE_ARRAY; + + @NBTName("Palette") private BlockState[] palette = EMPTY_BLOCKSTATE_ARRAY; + + @NBTName("BlockStates") private long[] blockStates = EMPTY_LONG_ARRAY; + } } diff --git a/core/src/main/java/de/bluecolored/bluemap/core/world/mca/chunk/Chunk_1_16.java b/core/src/main/java/de/bluecolored/bluemap/core/world/mca/chunk/Chunk_1_16.java index 6d8a0004..1d98a9f8 100644 --- a/core/src/main/java/de/bluecolored/bluemap/core/world/mca/chunk/Chunk_1_16.java +++ b/core/src/main/java/de/bluecolored/bluemap/core/world/mca/chunk/Chunk_1_16.java @@ -279,38 +279,68 @@ public int getSectionY() { @Getter @SuppressWarnings("FieldMayBeFinal") public static class Data extends MCAChunk.Data { + + @NBTName("Level") private Level level = new Level(); + } @Getter @SuppressWarnings("FieldMayBeFinal") public static class Level { + + @NBTName("Status") private Key status = STATUS_EMPTY; + + @NBTName("InhabitedTime") private long inhabitedTime = 0; + + @NBTName("Heightmaps") private HeightmapsData heightmaps = new HeightmapsData(); + + @NBTName("Sections") private SectionData @Nullable [] sections = null; + + @NBTName("Biomes") private int[] biomes = EMPTY_INT_ARRAY; @NBTName("TileEntities") @NBTDeserializer(LenientBlockEntityArrayDeserializer.class) private @Nullable BlockEntity [] blockEntities = EMPTY_BLOCK_ENTITIES_ARRAY; + } @Getter @SuppressWarnings("FieldMayBeFinal") public static class HeightmapsData { - @NBTName("WORLD_SURFACE") private long[] worldSurface = EMPTY_LONG_ARRAY; - @NBTName("OCEAN_FLOOR") private long[] oceanFloor = EMPTY_LONG_ARRAY; + + @NBTName("WORLD_SURFACE") + private long[] worldSurface = EMPTY_LONG_ARRAY; + + @NBTName("OCEAN_FLOOR") + private long[] oceanFloor = EMPTY_LONG_ARRAY; + } @Getter @SuppressWarnings("FieldMayBeFinal") public static class SectionData { + + @NBTName("Y") private int y = 0; + + @NBTName("BlockLight") private byte[] blockLight = EMPTY_BYTE_ARRAY; + + @NBTName("SkyLight") private byte[] skyLight = EMPTY_BYTE_ARRAY; + + @NBTName("Palette") private BlockState[] palette = EMPTY_BLOCKSTATE_ARRAY; + + @NBTName("BlockStates") private long[] blockStates = EMPTY_LONG_ARRAY; + } } diff --git a/core/src/main/java/de/bluecolored/bluemap/core/world/mca/chunk/Chunk_1_18.java b/core/src/main/java/de/bluecolored/bluemap/core/world/mca/chunk/Chunk_1_18.java index 7c4eea39..26b22f8a 100644 --- a/core/src/main/java/de/bluecolored/bluemap/core/world/mca/chunk/Chunk_1_18.java +++ b/core/src/main/java/de/bluecolored/bluemap/core/world/mca/chunk/Chunk_1_18.java @@ -294,45 +294,72 @@ public int getSectionY() { @Getter @SuppressWarnings("FieldMayBeFinal") public static class Data extends MCAChunk.Data { + + @NBTName("Status") private Key status = STATUS_EMPTY; + + @NBTName("InhabitedTime") private long inhabitedTime = 0; + + @NBTName("Heightmaps") private HeightmapsData heightmaps = new HeightmapsData(); + private SectionData @Nullable [] sections = null; - @NBTName("block_entities") @NBTDeserializer(LenientBlockEntityArrayDeserializer.class) private @Nullable BlockEntity [] blockEntities = EMPTY_BLOCK_ENTITIES_ARRAY; + } @Getter @SuppressWarnings("FieldMayBeFinal") public static class HeightmapsData { - @NBTName("WORLD_SURFACE") private long[] worldSurface = EMPTY_LONG_ARRAY; - @NBTName("OCEAN_FLOOR") private long[] oceanFloor = EMPTY_LONG_ARRAY; + + @NBTName("WORLD_SURFACE") + private long[] worldSurface = EMPTY_LONG_ARRAY; + + @NBTName("OCEAN_FLOOR") + private long[] oceanFloor = EMPTY_LONG_ARRAY; + } @Getter @SuppressWarnings("FieldMayBeFinal") public static class SectionData { + + @NBTName("Y") private int y = 0; + + @NBTName("BlockLight") private byte[] blockLight = EMPTY_BYTE_ARRAY; + + @NBTName("SkyLight") private byte[] skyLight = EMPTY_BYTE_ARRAY; - @NBTName("block_states") private BlockStatesData blockStates = new BlockStatesData(); + + private BlockStatesData blockStates = new BlockStatesData(); + private BiomesData biomes = new BiomesData(); + } @Getter @SuppressWarnings("FieldMayBeFinal") public static class BlockStatesData { + private BlockState[] palette = EMPTY_BLOCKSTATE_ARRAY; + private long[] data = EMPTY_LONG_ARRAY; + } @Getter @SuppressWarnings("FieldMayBeFinal") public static class BiomesData { + private Key[] palette = EMPTY_KEY_ARRAY; + private long[] data = EMPTY_LONG_ARRAY; + } } diff --git a/core/src/main/java/de/bluecolored/bluemap/core/world/mca/chunk/MCAChunk.java b/core/src/main/java/de/bluecolored/bluemap/core/world/mca/chunk/MCAChunk.java index 627b0b4c..0954484c 100644 --- a/core/src/main/java/de/bluecolored/bluemap/core/world/mca/chunk/MCAChunk.java +++ b/core/src/main/java/de/bluecolored/bluemap/core/world/mca/chunk/MCAChunk.java @@ -29,6 +29,7 @@ import de.bluecolored.bluemap.core.world.Chunk; import de.bluecolored.bluemap.core.world.block.entity.BlockEntity; import de.bluecolored.bluemap.core.world.mca.MCAWorld; +import de.bluecolored.bluenbt.NBTName; import lombok.Getter; import lombok.ToString; @@ -58,7 +59,10 @@ public MCAChunk(MCAWorld world, Data chunkData) { @SuppressWarnings("FieldMayBeFinal") @Getter public static class Data { + + @NBTName("DataVersion") private int dataVersion = 0; + } } diff --git a/core/src/main/java/de/bluecolored/bluemap/core/world/mca/data/DimensionTypeDeserializer.java b/core/src/main/java/de/bluecolored/bluemap/core/world/mca/data/DimensionTypeDeserializer.java index f41c4414..b5fffb96 100644 --- a/core/src/main/java/de/bluecolored/bluemap/core/world/mca/data/DimensionTypeDeserializer.java +++ b/core/src/main/java/de/bluecolored/bluemap/core/world/mca/data/DimensionTypeDeserializer.java @@ -24,16 +24,12 @@ */ package de.bluecolored.bluemap.core.world.mca.data; -import com.google.gson.reflect.TypeToken; import de.bluecolored.bluemap.core.logger.Logger; import de.bluecolored.bluemap.core.resources.pack.datapack.DataPack; import de.bluecolored.bluemap.core.resources.pack.datapack.dimension.DimensionTypeData; import de.bluecolored.bluemap.core.util.Key; import de.bluecolored.bluemap.core.world.DimensionType; -import de.bluecolored.bluenbt.BlueNBT; -import de.bluecolored.bluenbt.NBTReader; -import de.bluecolored.bluenbt.TagType; -import de.bluecolored.bluenbt.TypeDeserializer; +import de.bluecolored.bluenbt.*; import java.io.IOException; @@ -43,7 +39,7 @@ public class DimensionTypeDeserializer implements TypeDeserializer