mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-04 03:56:41 +00:00
Replace BlockStates reading with new 1.16 logic (#1413)
* Replace BlockStates reading with new 1.16 logic * Account for running on older platforms Splits out the new reading to AnvilChunk16, uses data version to detect the appropriate version. * Move data versions to Constants Also fixes some logic hiccups that become obvious with the new names. * Fix LegacyMapper DFU handling * Fix factor indexing (cherry picked from commit 8c171f0929e8530aab1731d122649adc58c5161f)
This commit is contained in:
@ -41,7 +41,7 @@ import java.util.Map;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* The chunk format for Minecraft 1.13 and newer
|
||||
* The chunk format for Minecraft 1.13 to 1.15
|
||||
*/
|
||||
public class AnvilChunk13 implements Chunk {
|
||||
|
||||
@ -112,44 +112,48 @@ public class AnvilChunk13 implements Chunk {
|
||||
}
|
||||
palette[paletteEntryId] = blockState;
|
||||
}
|
||||
int paletteBits = 4;
|
||||
while ((1 << paletteBits) < paletteSize) {
|
||||
++paletteBits;
|
||||
}
|
||||
int paletteMask = (1 << paletteBits) - 1;
|
||||
|
||||
// parse block states
|
||||
long[] blockStatesSerialized = NBTUtils.getChildTag(sectionTag.getValue(), "BlockStates", LongArrayTag.class).getValue();
|
||||
|
||||
int blocksPerChunkSection = 16 * 16 * 16;
|
||||
BlockState[] chunkSectionBlocks = new BlockState[blocksPerChunkSection];
|
||||
BlockState[] chunkSectionBlocks = new BlockState[16 * 16 * 16];
|
||||
blocks[y] = chunkSectionBlocks;
|
||||
|
||||
long currentSerializedValue = 0;
|
||||
int nextSerializedItem = 0;
|
||||
int remainingBits = 0;
|
||||
for (int blockPos = 0; blockPos < blocksPerChunkSection; blockPos++) {
|
||||
int localBlockId;
|
||||
if (remainingBits < paletteBits) {
|
||||
int bitsNextLong = paletteBits - remainingBits;
|
||||
localBlockId = (int) currentSerializedValue;
|
||||
if (nextSerializedItem >= blockStatesSerialized.length) {
|
||||
throw new InvalidFormatException("Too short block state table");
|
||||
}
|
||||
currentSerializedValue = blockStatesSerialized[nextSerializedItem++];
|
||||
localBlockId |= (currentSerializedValue & ((1 << bitsNextLong) - 1)) << remainingBits;
|
||||
currentSerializedValue >>>= bitsNextLong;
|
||||
remainingBits = 64 - bitsNextLong;
|
||||
} else {
|
||||
localBlockId = (int) (currentSerializedValue & paletteMask);
|
||||
currentSerializedValue >>>= paletteBits;
|
||||
remainingBits -= paletteBits;
|
||||
readBlockStates(palette, blockStatesSerialized, chunkSectionBlocks);
|
||||
}
|
||||
}
|
||||
|
||||
protected void readBlockStates(BlockState[] palette, long[] blockStatesSerialized, BlockState[] chunkSectionBlocks) throws InvalidFormatException {
|
||||
int paletteBits = 4;
|
||||
while ((1 << paletteBits) < palette.length) {
|
||||
++paletteBits;
|
||||
}
|
||||
int paletteMask = (1 << paletteBits) - 1;
|
||||
|
||||
long currentSerializedValue = 0;
|
||||
int nextSerializedItem = 0;
|
||||
int remainingBits = 0;
|
||||
for (int blockPos = 0; blockPos < chunkSectionBlocks.length; blockPos++) {
|
||||
int localBlockId;
|
||||
if (remainingBits < paletteBits) {
|
||||
int bitsNextLong = paletteBits - remainingBits;
|
||||
localBlockId = (int) currentSerializedValue;
|
||||
if (nextSerializedItem >= blockStatesSerialized.length) {
|
||||
throw new InvalidFormatException("Too short block state table");
|
||||
}
|
||||
if (localBlockId >= palette.length) {
|
||||
throw new InvalidFormatException("Invalid block state table entry: " + localBlockId);
|
||||
}
|
||||
chunkSectionBlocks[blockPos] = palette[localBlockId];
|
||||
currentSerializedValue = blockStatesSerialized[nextSerializedItem++];
|
||||
localBlockId |= (currentSerializedValue & ((1 << bitsNextLong) - 1)) << remainingBits;
|
||||
currentSerializedValue >>>= bitsNextLong;
|
||||
remainingBits = 64 - bitsNextLong;
|
||||
} else {
|
||||
localBlockId = (int) (currentSerializedValue & paletteMask);
|
||||
currentSerializedValue >>>= paletteBits;
|
||||
remainingBits -= paletteBits;
|
||||
}
|
||||
if (localBlockId >= palette.length) {
|
||||
throw new InvalidFormatException("Invalid block state table entry: " + localBlockId);
|
||||
}
|
||||
chunkSectionBlocks[blockPos] = palette[localBlockId];
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user