mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-05 20:36:42 +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];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,10 +25,12 @@ import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import com.sk89q.worldedit.extension.platform.Platform;
|
||||
import com.sk89q.worldedit.internal.Constants;
|
||||
import com.sk89q.worldedit.world.DataException;
|
||||
import com.sk89q.worldedit.world.DataFixer;
|
||||
import com.sk89q.worldedit.world.chunk.AnvilChunk;
|
||||
import com.sk89q.worldedit.world.chunk.AnvilChunk13;
|
||||
import com.sk89q.worldedit.world.chunk.AnvilChunk16;
|
||||
import com.sk89q.worldedit.world.chunk.Chunk;
|
||||
import com.sk89q.worldedit.world.chunk.OldChunk;
|
||||
|
||||
@ -58,11 +60,6 @@ public class ChunkStoreHelper {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The DataVersion for Minecraft 1.13
|
||||
*/
|
||||
private static final int DATA_VERSION_MC_1_13 = 1519;
|
||||
|
||||
/**
|
||||
* Convert a chunk NBT tag into a {@link Chunk} implementation.
|
||||
*
|
||||
@ -94,13 +91,17 @@ public class ChunkStoreHelper {
|
||||
if (dataVersion == 0) dataVersion = -1;
|
||||
final Platform platform = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING);
|
||||
final int currentDataVersion = platform.getDataVersion();
|
||||
if (tag.getValue().containsKey("Sections") && dataVersion < currentDataVersion) { // only fix up MCA format, DFU doesn't support MCR chunks
|
||||
if (tag.getValue().containsKey("Sections") && dataVersion < currentDataVersion) { // only fix up MCA format, DFU doesn't support MCR chunks
|
||||
final DataFixer dataFixer = platform.getDataFixer();
|
||||
if (dataFixer != null) {
|
||||
return new AnvilChunk13((CompoundTag) dataFixer.fixUp(DataFixer.FixTypes.CHUNK, rootTag, dataVersion).getValue().get("Level"));
|
||||
tag = (CompoundTag) dataFixer.fixUp(DataFixer.FixTypes.CHUNK, rootTag, dataVersion).getValue().get("Level");
|
||||
dataVersion = currentDataVersion;
|
||||
}
|
||||
}
|
||||
if (dataVersion >= DATA_VERSION_MC_1_13) {
|
||||
if (dataVersion >= Constants.DATA_VERSION_MC_1_16) {
|
||||
return new AnvilChunk16(tag);
|
||||
}
|
||||
if (dataVersion >= Constants.DATA_VERSION_MC_1_13) {
|
||||
return new AnvilChunk13(tag);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user