Skip to content

Commit

Permalink
Fix restore for 1.14 chunk format.
Browse files Browse the repository at this point in the history
Top-most chunk can now have lighting without have a palette or blocks.
  • Loading branch information
wizjany committed Jun 3, 2019
1 parent a3afd9d commit 3a6b3dc
Showing 1 changed file with 10 additions and 6 deletions.
Expand Up @@ -83,18 +83,17 @@ public AnvilChunk13(CompoundTag tag) throws DataException {
continue;
}

int blocksPerChunkSection = 16 * 16 * 16;
BlockState[] chunkSectionBlocks = new BlockState[blocksPerChunkSection];
blocks[y] = chunkSectionBlocks;

// parse palette
List<CompoundTag> 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();
Expand All @@ -121,11 +120,16 @@ public AnvilChunk13(CompoundTag tag) throws DataException {

// 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;
Expand Down

0 comments on commit 3a6b3dc

Please sign in to comment.