Search in sources :

Example 1 with AnvilChunk

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);
}
Also used : AnvilChunk18(com.sk89q.worldedit.world.chunk.AnvilChunk18) Platform(com.sk89q.worldedit.extension.platform.Platform) OldChunk(com.sk89q.worldedit.world.chunk.OldChunk) AnvilChunk13(com.sk89q.worldedit.world.chunk.AnvilChunk13) AnvilChunk15(com.sk89q.worldedit.world.chunk.AnvilChunk15) AnvilChunk16(com.sk89q.worldedit.world.chunk.AnvilChunk16) AnvilChunk17(com.sk89q.worldedit.world.chunk.AnvilChunk17) AnvilChunk(com.sk89q.worldedit.world.chunk.AnvilChunk) CompoundTag(com.sk89q.jnbt.CompoundTag) Tag(com.sk89q.jnbt.Tag) DataFixer(com.sk89q.worldedit.world.DataFixer) Map(java.util.Map) CompoundTag(com.sk89q.jnbt.CompoundTag)

Aggregations

CompoundTag (com.sk89q.jnbt.CompoundTag)1 Tag (com.sk89q.jnbt.Tag)1 Platform (com.sk89q.worldedit.extension.platform.Platform)1 DataFixer (com.sk89q.worldedit.world.DataFixer)1 AnvilChunk (com.sk89q.worldedit.world.chunk.AnvilChunk)1 AnvilChunk13 (com.sk89q.worldedit.world.chunk.AnvilChunk13)1 AnvilChunk15 (com.sk89q.worldedit.world.chunk.AnvilChunk15)1 AnvilChunk16 (com.sk89q.worldedit.world.chunk.AnvilChunk16)1 AnvilChunk17 (com.sk89q.worldedit.world.chunk.AnvilChunk17)1 AnvilChunk18 (com.sk89q.worldedit.world.chunk.AnvilChunk18)1 OldChunk (com.sk89q.worldedit.world.chunk.OldChunk)1 Map (java.util.Map)1