Skip to content

Commit

Permalink
handle empty sections
Browse files Browse the repository at this point in the history
  • Loading branch information
Querz committed Jun 24, 2019
1 parent 8cedf1e commit ff5ccab
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/main/java/net/querz/nbt/mca/Chunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/net/querz/nbt/mca/Section.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@ 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);
}
blockLight = sectionRoot.getByteArray("BlockLight");
blockStates = sectionRoot.getLongArray("BlockStates");
skyLight = sectionRoot.getByteArray("SkyLight");
data = sectionRoot;
}

Section() {}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ff5ccab

Please sign in to comment.