use of com.sk89q.worldedit.world.chunk.AnvilChunk in project FastAsyncWorldEdit by IntellectualSites.
the class ChunkStoreHelper method getChunk.
/**
* Convert a chunk NBT tag into a {@link Chunk} implementation.
*
* @param rootTag the root tag of the chunk
* @param entitiesTag supplier to provide entities tag. Only required for 1.17+ where entities are stored in a separate
* location
* @return a Chunk implementation
* @throws DataException if the rootTag is not valid chunk data
* @since TODO
*/
public static Chunk getChunk(CompoundTag rootTag, Supplier<CompoundTag> entitiesTag) throws DataException {
// FAWE end
int dataVersion = rootTag.getInt("DataVersion");
if (dataVersion == 0) {
dataVersion = -1;
}
final Platform platform = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING);
final int currentDataVersion = platform.getDataVersion();
if ((dataVersion > 0 || hasLevelSections(rootTag)) && dataVersion < currentDataVersion) {
// only fix up MCA format, DFU doesn't support MCR chunks
final DataFixer dataFixer = platform.getDataFixer();
if (dataFixer != null) {
// FAWE start - CBT
rootTag = (CompoundTag) AdventureNBTConverter.fromAdventure(dataFixer.fixUp(DataFixer.FixTypes.CHUNK, rootTag.asBinaryTag(), dataVersion));
// FAWE end
dataVersion = currentDataVersion;
}
}
if (dataVersion >= Constants.DATA_VERSION_MC_1_18) {
return new AnvilChunk18(rootTag, entitiesTag);
}
Map<String, Tag> children = rootTag.getValue();
CompoundTag tag = null;
// Find Level tag
for (Map.Entry<String, Tag> entry : children.entrySet()) {
if (entry.getKey().equals("Level")) {
if (entry.getValue() instanceof CompoundTag) {
tag = (CompoundTag) entry.getValue();
break;
} else {
throw new ChunkStoreException("CompoundTag expected for 'Level'; got " + entry.getValue().getClass().getName());
}
}
}
if (tag == null) {
throw new ChunkStoreException("Missing root 'Level' tag");
}
// FAWE start - biome and entity restore
if (dataVersion >= Constants.DATA_VERSION_MC_1_17) {
return new AnvilChunk17(tag, entitiesTag);
}
// FAWE end
if (dataVersion >= Constants.DATA_VERSION_MC_1_16) {
return new AnvilChunk16(tag);
}
// FAWE start - biome and entity restore
if (dataVersion >= Constants.DATA_VERSION_MC_1_15) {
return new AnvilChunk15(tag);
}
// FAWE end
if (dataVersion >= Constants.DATA_VERSION_MC_1_13) {
return new AnvilChunk13(tag);
}
Map<String, Tag> tags = tag.getValue();
if (tags.containsKey("Sections")) {
return new AnvilChunk(tag);
}
return new OldChunk(tag);
}
Aggregations