cn.nukkit.level.format.anvil.Chunk Java Examples

The following examples show how to use cn.nukkit.level.format.anvil.Chunk. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChunkConverter.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public ChunkConverter from(BaseFullChunk chunk) {
    if (!(chunk instanceof cn.nukkit.level.format.mcregion.Chunk) && !(chunk instanceof cn.nukkit.level.format.leveldb.Chunk)) {
        throw new IllegalArgumentException("From type can be only McRegion or LevelDB");
    }
    this.chunk = chunk;
    return this;
}
 
Example #2
Source File: ChunkConverter.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public ChunkConverter to(Class<? extends FullChunk> toClass) {
    if (toClass != Chunk.class) {
        throw new IllegalArgumentException("To type can be only Anvil");
    }
    this.toClass = toClass;
    return this;
}
 
Example #3
Source File: ChunkConverter.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public ChunkConverter from(BaseFullChunk chunk) {
    if (!(chunk instanceof cn.nukkit.level.format.mcregion.Chunk) && !(chunk instanceof cn.nukkit.level.format.leveldb.Chunk)) {
        throw new IllegalArgumentException("From type can be only McRegion or LevelDB");
    }
    this.chunk = chunk;
    return this;
}
 
Example #4
Source File: ChunkConverter.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public ChunkConverter to(Class<? extends FullChunk> toClass) {
    if (toClass != Chunk.class) {
        throw new IllegalArgumentException("To type can be only Anvil");
    }
    this.toClass = toClass;
    return this;
}
 
Example #5
Source File: ChunkConverter.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public ChunkConverter from(BaseFullChunk chunk) {
    if (!(chunk instanceof cn.nukkit.level.format.mcregion.Chunk) && !(chunk instanceof cn.nukkit.level.format.leveldb.Chunk)) {
        throw new IllegalArgumentException("From type can be only McRegion or LevelDB");
    }
    this.chunk = chunk;
    return this;
}
 
Example #6
Source File: ChunkConverter.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public ChunkConverter to(Class<? extends FullChunk> toClass) {
    if (toClass != Chunk.class) {
        throw new IllegalArgumentException("To type can be only Anvil");
    }
    this.toClass = toClass;
    return this;
}
 
Example #7
Source File: ChunkConverter.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public FullChunk perform() {
    BaseFullChunk result;
    try {
        result = (BaseFullChunk) toClass.getMethod("getEmptyChunk", int.class, int.class, LevelProvider.class).invoke(null, chunk.getX(), chunk.getZ(), provider);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    if (toClass == Chunk.class) {
        for (int Y = 0; Y < 8; Y++) {
            boolean empty = true;
            for (int x = 0; x < 16; x++) {
                for (int y = 0; y < 16; y++) {
                    for (int z = 0; z < 16; z++) {
                        if (chunk.getBlockId(x, (Y << 4) | y, z) != 0) {
                            empty = false;
                            break;
                        }
                    }
                    if (!empty) break;
                }
                if (!empty) break;
            }
            if (!empty) {
                ChunkSection section = new ChunkSection(Y);
                for (int x = 0; x < 16; x++) {
                    for (int y = 0; y < 16; y++) {
                        for (int z = 0; z < 16; z++) {
                            section.setBlockId(x, y, z, chunk.getBlockId(x, (Y << 4) | y, z));
                            section.setBlockData(x, y, z, chunk.getBlockData(x, (Y << 4) | y, z));
                            section.setBlockLight(x, y, z, chunk.getBlockLight(x, (Y << 4) | y, z));
                            section.setBlockSkyLight(x, y, z, chunk.getBlockSkyLight(x, (Y << 4) | y, z));
                        }
                    }
                }
                ((BaseChunk) result).sections[Y] = section;
            }
        }
    }
    System.arraycopy(chunk.getBiomeColorArray(), 0, result.biomeColors, 0, 256);
    System.arraycopy(chunk.getHeightMapArray(), 0, result.heightMap, 0, 256);
    result.NBTentities = new ArrayList<>();
    chunk.NBTentities.forEach((nbt) -> result.NBTentities.add(nbt.copy()));
    result.NBTtiles = new ArrayList<>();
    chunk.NBTtiles.forEach((nbt) -> result.NBTtiles.add(nbt.copy()));
    result.setGenerated();
    result.setPopulated();
    result.setLightPopulated();
    result.initChunk();
    return result;
}
 
Example #8
Source File: ChunkConverter.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public FullChunk perform() {
    BaseFullChunk result;
    try {
        result = (BaseFullChunk) toClass.getMethod("getEmptyChunk", int.class, int.class, LevelProvider.class).invoke(null, chunk.getX(), chunk.getZ(), provider);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    if (toClass == Chunk.class) {
        for (int Y = 0; Y < 8; Y++) {
            boolean empty = true;
            for (int x = 0; x < 16; x++) {
                for (int y = 0; y < 16; y++) {
                    for (int z = 0; z < 16; z++) {
                        if (chunk.getBlockId(x, (Y << 4) | y, z) != 0) {
                            empty = false;
                            break;
                        }
                    }
                    if (!empty) break;
                }
                if (!empty) break;
            }
            if (!empty) {
                ChunkSection section = new ChunkSection(Y);
                for (int x = 0; x < 16; x++) {
                    for (int y = 0; y < 16; y++) {
                        for (int z = 0; z < 16; z++) {
                            section.setBlockId(x, y, z, chunk.getBlockId(x, (Y << 4) | y, z));
                            section.setBlockData(x, y, z, chunk.getBlockData(x, (Y << 4) | y, z));
                            section.setBlockLight(x, y, z, chunk.getBlockLight(x, (Y << 4) | y, z));
                            section.setBlockSkyLight(x, y, z, chunk.getBlockSkyLight(x, (Y << 4) | y, z));
                        }
                    }
                }
                ((BaseChunk) result).sections[Y] = section;
            }
        }
    }
    System.arraycopy(chunk.biomes, 0, result.biomes, 0, 256);
    System.arraycopy(chunk.getHeightMapArray(), 0, result.heightMap, 0, 256);
    if (chunk.NBTentities != null && !chunk.NBTentities.isEmpty()) {
        result.NBTentities = new ArrayList<>(chunk.NBTentities.size());
        chunk.NBTentities.forEach((nbt) -> result.NBTentities.add(nbt.copy()));
    }

    if (chunk.NBTtiles != null && !chunk.NBTtiles.isEmpty()) {
        result.NBTtiles = new ArrayList<>(chunk.NBTtiles.size());
        chunk.NBTtiles.forEach((nbt) -> result.NBTtiles.add(nbt.copy()));
    }
    result.setGenerated();
    result.setPopulated();
    result.setLightPopulated();
    result.initChunk();
    return result;
}
 
Example #9
Source File: ChunkConverter.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public FullChunk perform() {
    BaseFullChunk result;
    try {
        result = (BaseFullChunk) toClass.getMethod("getEmptyChunk", int.class, int.class, LevelProvider.class).invoke(null, chunk.getX(), chunk.getZ(), provider);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    if (toClass == Chunk.class) {
        for (int Y = 0; Y < 8; Y++) {
            boolean empty = true;
            for (int x = 0; x < 16; x++) {
                for (int y = 0; y < 16; y++) {
                    for (int z = 0; z < 16; z++) {
                        if (chunk.getBlockId(x, (Y << 4) | y, z) != 0) {
                            empty = false;
                            break;
                        }
                    }
                    if (!empty) break;
                }
                if (!empty) break;
            }
            if (!empty) {
                ChunkSection section = new ChunkSection(Y);
                for (int x = 0; x < 16; x++) {
                    for (int y = 0; y < 16; y++) {
                        for (int z = 0; z < 16; z++) {
                            section.setBlockId(x, y, z, chunk.getBlockId(x, (Y << 4) | y, z));
                            section.setBlockData(x, y, z, chunk.getBlockData(x, (Y << 4) | y, z));
                            section.setBlockLight(x, y, z, chunk.getBlockLight(x, (Y << 4) | y, z));
                            section.setBlockSkyLight(x, y, z, chunk.getBlockSkyLight(x, (Y << 4) | y, z));
                        }
                    }
                }
                ((BaseChunk) result).sections[Y] = section;
            }
        }
    }
    System.arraycopy(chunk.getBiomeColorArray(), 0, result.biomeColors, 0, 256);
    System.arraycopy(chunk.getHeightMapArray(), 0, result.heightMap, 0, 256);
    result.NBTentities = new ArrayList<>();
    chunk.NBTentities.forEach((nbt) -> result.NBTentities.add(nbt.copy()));
    result.NBTtiles = new ArrayList<>();
    chunk.NBTtiles.forEach((nbt) -> result.NBTtiles.add(nbt.copy()));
    result.setGenerated();
    result.setPopulated();
    result.setLightPopulated();
    result.initChunk();
    return result;
}