From 92e89c49bfb88c97c27793e082ef0b3b56f06301 Mon Sep 17 00:00:00 2001 From: David Mayr Date: Sun, 8 Sep 2024 20:56:02 +0200 Subject: [PATCH] fix: biome data not being null when no biomes are set --- build.gradle.kts | 2 +- .../schematics/version/V3SchematicVersion.java | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 264ecd8..0e340ca 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ plugins { } group = "eu.cafestube" -version = "2.0.3-SNAPSHOT" +version = "2.0.4-SNAPSHOT" allprojects { repositories { diff --git a/src/main/java/eu/cafestube/schematics/version/V3SchematicVersion.java b/src/main/java/eu/cafestube/schematics/version/V3SchematicVersion.java index 5090d53..7bcf4b0 100644 --- a/src/main/java/eu/cafestube/schematics/version/V3SchematicVersion.java +++ b/src/main/java/eu/cafestube/schematics/version/V3SchematicVersion.java @@ -42,11 +42,17 @@ public Schematic deserialize(CompoundBinaryTag compound) { Map blockEntityMap = V2SchematicVersion.parseBlockEntities(dataVersion, blocksTag); - CompoundBinaryTag biomesTag = compound.getCompound("Biomes"); - CompoundBinaryTag biomePaletteTag = biomesTag.getCompound("Palette"); - Map biomePalette = StreamSupport.stream(biomePaletteTag.spliterator(), true) - .collect(Collectors.toMap(stringObjectEntry -> ((IntBinaryTag) stringObjectEntry.getValue()).value(), Map.Entry::getKey)); - byte[] biomeData = biomesTag.getByteArray("Data"); + + BiomeData biomeData = null; + if(compound.get("Biomes") != null) { + CompoundBinaryTag biomesTag = compound.getCompound("Biomes"); + CompoundBinaryTag biomePaletteTag = biomesTag.getCompound("Palette"); + Map biomePalette = StreamSupport.stream(biomePaletteTag.spliterator(), true) + .collect(Collectors.toMap(stringObjectEntry -> ((IntBinaryTag) stringObjectEntry.getValue()).value(), Map.Entry::getKey)); + byte[] biomeDataBytes = biomesTag.getByteArray("Data"); + + biomeData = new BiomeData(biomePalette, biomeDataBytes, BiomeDataType.THREE_DIMENSIONAL); + } ListBinaryTag entitiesTag = compound.getList("Entities"); @@ -54,7 +60,7 @@ public Schematic deserialize(CompoundBinaryTag compound) { return new Schematic(dataVersion, width, height, length, metadata, offset, blockPalette, blockData, - blockEntityMap, entities, new BiomeData(biomePalette, biomeData, BiomeDataType.THREE_DIMENSIONAL)); + blockEntityMap, entities, biomeData); } @Override