From 3a6b3dc75ca7dcb4273053c3ea817807464c9546 Mon Sep 17 00:00:00 2001 From: wizjany Date: Sun, 2 Jun 2019 21:50:07 -0400 Subject: [PATCH] Fix restore for 1.14 chunk format. Top-most chunk can now have lighting without have a palette or blocks. --- .../worldedit/world/chunk/AnvilChunk13.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk13.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk13.java index 832fbf020..5cf07bd91 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk13.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk13.java @@ -83,18 +83,17 @@ public class AnvilChunk13 implements Chunk { continue; } - int blocksPerChunkSection = 16 * 16 * 16; - BlockState[] chunkSectionBlocks = new BlockState[blocksPerChunkSection]; - blocks[y] = chunkSectionBlocks; - // parse palette List paletteEntries = sectionTag.getList("Palette", CompoundTag.class); int paletteSize = paletteEntries.size(); + if (paletteSize == 0) { + continue; + } BlockState[] palette = new BlockState[paletteSize]; for (int paletteEntryId = 0; paletteEntryId < paletteSize; paletteEntryId++) { CompoundTag paletteEntry = paletteEntries.get(paletteEntryId); BlockType type = BlockTypes.get(paletteEntry.getString("Name")); - if(type == null) { + if (type == null) { throw new InvalidFormatException("Invalid block type: " + paletteEntry.getString("Name")); } BlockState blockState = type.getDefaultState(); @@ -121,11 +120,16 @@ public class AnvilChunk13 implements Chunk { // parse block states long[] blockStatesSerialized = NBTUtils.getChildTag(sectionTag.getValue(), "BlockStates", LongArrayTag.class).getValue(); + + int blocksPerChunkSection = 16 * 16 * 16; + BlockState[] chunkSectionBlocks = new BlockState[blocksPerChunkSection]; + blocks[y] = chunkSectionBlocks; + long currentSerializedValue = 0; int nextSerializedItem = 0; int remainingBits = 0; for (int blockPos = 0; blockPos < blocksPerChunkSection; blockPos++) { - int localBlockId = 0; + int localBlockId; if (remainingBits < paletteBits) { int bitsNextLong = paletteBits - remainingBits; localBlockId = (int) currentSerializedValue;