diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil112.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil112.java index 9ddf7119..df592317 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil112.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil112.java @@ -24,6 +24,8 @@ */ package de.bluecolored.bluemap.core.mca; +import java.util.Arrays; + import com.flowpowered.math.vector.Vector3i; import de.bluecolored.bluemap.core.mca.mapping.BiomeMapper; @@ -60,15 +62,21 @@ public ChunkAnvil112(MCAWorld world, CompoundTag chunkTag, boolean ignoreMissing levelData.getBoolean("TerrainPopulated"); sections = new Section[32]; //32 supports a max world-height of 512 which is the max that the hightmaps of Minecraft V1.13+ can store with 9 bits, i believe? - for (CompoundTag sectionTag : ((ListTag) levelData.getListTag("Sections"))) { - Section section = new Section(sectionTag); - sections[section.getSectionY()] = section; + if (levelData.containsKey("Sections")) { + for (CompoundTag sectionTag : ((ListTag) levelData.getListTag("Sections"))) { + Section section = new Section(sectionTag); + if (section.getSectionY() >= 0 && section.getSectionY() < sections.length) sections[section.getSectionY()] = section; + } } biomes = levelData.getByteArray("Biomes"); if (biomes == null || biomes.length == 0) { - biomes = new byte[2048]; + biomes = new byte[256]; + } + + if (biomes.length < 256) { + biomes = Arrays.copyOf(biomes, 256); } } @@ -132,6 +140,11 @@ public Section(CompoundTag sectionData) { this.blockLight = sectionData.getByteArray("BlockLight"); this.skyLight = sectionData.getByteArray("SkyLight"); this.data = sectionData.getByteArray("Data"); + + if (blocks.length < 4096) blocks = Arrays.copyOf(biomes, 4096); + if (blockLight.length < 2048) blockLight = Arrays.copyOf(blockLight, 2048); + if (skyLight.length < 2048) skyLight = Arrays.copyOf(skyLight, 2048); + if (data.length < 2048) data = Arrays.copyOf(data, 2048); } public int getSectionY() { @@ -148,7 +161,7 @@ public BlockState getBlockState(Vector3i pos) { int blockId = this.blocks[blockByteIndex] & 0xFF; - if (this.add.length > 0) { + if (this.add.length > blockHalfByteIndex) { blockId = blockId | (getByteHalf(this.add[blockHalfByteIndex], largeHalf) << 8); } @@ -172,7 +185,7 @@ public String getBlockIdMeta(Vector3i pos) { int blockId = this.blocks[blockByteIndex] & 0xFF; - if (this.add.length > 0) { + if (this.add.length > blockHalfByteIndex) { blockId = blockId | (getByteHalf(this.add[blockHalfByteIndex], largeHalf) << 8); } diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil113.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil113.java index 0a67022e..b5eda8d0 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil113.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil113.java @@ -24,6 +24,7 @@ */ package de.bluecolored.bluemap.core.mca; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; @@ -71,7 +72,7 @@ public ChunkAnvil113(MCAWorld world, CompoundTag chunkTag, boolean ignoreMissing if (levelData.containsKey("Sections")) { for (CompoundTag sectionTag : ((ListTag) levelData.getListTag("Sections"))) { Section section = new Section(sectionTag); - if (section.getSectionY() >= 0) sections[section.getSectionY()] = section; + if (section.getSectionY() >= 0 && section.getSectionY() < sections.length) sections[section.getSectionY()] = section; } } @@ -89,7 +90,11 @@ else if (tag instanceof IntArrayTag) { } if (biomes == null || biomes.length == 0) { - biomes = new int[2048]; + biomes = new int[256]; + } + + if (biomes.length < 256) { + biomes = Arrays.copyOf(biomes, 256); } } diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil115.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil115.java index 9ecede17..df2a26ef 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil115.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil115.java @@ -24,6 +24,7 @@ */ package de.bluecolored.bluemap.core.mca; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; @@ -71,7 +72,7 @@ public ChunkAnvil115(MCAWorld world, CompoundTag chunkTag, boolean ignoreMissing if (levelData.containsKey("Sections")) { for (CompoundTag sectionTag : ((ListTag) levelData.getListTag("Sections"))) { Section section = new Section(sectionTag); - if (section.getSectionY() >= 0) sections[section.getSectionY()] = section; + if (section.getSectionY() >= 0 && section.getSectionY() < sections.length) sections[section.getSectionY()] = section; } } @@ -89,7 +90,11 @@ else if (tag instanceof IntArrayTag) { } if (biomes == null || biomes.length == 0) { - biomes = new int[2048]; + biomes = new int[1024]; + } + + if (biomes.length < 1024) { + biomes = Arrays.copyOf(biomes, 1024); } } diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil116.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil116.java index bcc0868c..5bd83b7a 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil116.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil116.java @@ -24,6 +24,7 @@ */ package de.bluecolored.bluemap.core.mca; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; @@ -71,7 +72,7 @@ public ChunkAnvil116(MCAWorld world, CompoundTag chunkTag, boolean ignoreMissing if (levelData.containsKey("Sections")) { for (CompoundTag sectionTag : ((ListTag) levelData.getListTag("Sections"))) { Section section = new Section(sectionTag); - if (section.getSectionY() >= 0) sections[section.getSectionY()] = section; + if (section.getSectionY() >= 0 && section.getSectionY() < sections.length) sections[section.getSectionY()] = section; } } @@ -89,7 +90,11 @@ else if (tag instanceof IntArrayTag) { } if (biomes == null || biomes.length == 0) { - biomes = new int[2048]; + biomes = new int[1024]; + } + + if (biomes.length < 1024) { + biomes = Arrays.copyOf(biomes, 1024); } }