From ff5ccababd1855ad5314d8fda45a4c22a900d942 Mon Sep 17 00:00:00 2001 From: Querz Date: Mon, 24 Jun 2019 19:59:46 +0200 Subject: [PATCH] handle empty sections --- src/main/java/net/querz/nbt/mca/Chunk.java | 10 +++++++++- src/main/java/net/querz/nbt/mca/Section.java | 12 ++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/querz/nbt/mca/Chunk.java b/src/main/java/net/querz/nbt/mca/Chunk.java index 3f0ae94d..cd53152a 100644 --- a/src/main/java/net/querz/nbt/mca/Chunk.java +++ b/src/main/java/net/querz/nbt/mca/Chunk.java @@ -73,7 +73,15 @@ private void initReferences() { this.structures = level.getCompoundTag("Structures"); if (level.containsKey("Sections")) { for (CompoundTag section : level.getListTag("Sections").asCompoundTagList()) { - this.sections[section.getByte("Y")] = new Section(section); + int sectionIndex = section.getByte("Y"); + if (sectionIndex > 15 || sectionIndex < 0) { + continue; + } + Section newSection = new Section(section); + if (newSection.isEmpty()) { + continue; + } + this.sections[sectionIndex] = newSection; } } } diff --git a/src/main/java/net/querz/nbt/mca/Section.java b/src/main/java/net/querz/nbt/mca/Section.java index e94ea164..0ec467f6 100644 --- a/src/main/java/net/querz/nbt/mca/Section.java +++ b/src/main/java/net/querz/nbt/mca/Section.java @@ -17,8 +17,11 @@ public class Section { private byte[] skyLight; public Section(CompoundTag sectionRoot) { - data = sectionRoot; - palette = sectionRoot.getListTag("Palette").asCompoundTagList(); + ListTag rawPalette = sectionRoot.getListTag("Palette"); + if (rawPalette == null) { + return; + } + palette = rawPalette.asCompoundTagList(); for (int i = 0; i < palette.size(); i++) { CompoundTag data = palette.get(i); putValueIndexedPalette(data, i); @@ -26,6 +29,7 @@ public Section(CompoundTag sectionRoot) { blockLight = sectionRoot.getByteArray("BlockLight"); blockStates = sectionRoot.getLongArray("BlockStates"); skyLight = sectionRoot.getByteArray("SkyLight"); + data = sectionRoot; } Section() {} @@ -72,6 +76,10 @@ private class PaletteIndex { } } + public boolean isEmpty() { + return data == null; + } + public CompoundTag getBlockStateAt(int blockX, int blockY, int blockZ) { int index = getBlockIndex(blockX, blockY, blockZ); int paletteIndex = getPaletteIndex(index);