Search in sources :

Example 16 with BaseFullChunk

use of cn.nukkit.level.format.generic.BaseFullChunk in project Nukkit by Nukkit.

the class GenerationTask method onCompletion.

@Override
public void onCompletion(Server server) {
    Level level = server.getLevel(this.levelId);
    if (level != null) {
        if (!this.state) {
            level.registerGenerator();
            return;
        }
        BaseFullChunk chunk = this.chunk.clone();
        if (chunk == null) {
            return;
        }
        level.generateChunkCallback(chunk.getX(), chunk.getZ(), chunk);
    }
}
Also used : BaseFullChunk(cn.nukkit.level.format.generic.BaseFullChunk) Level(cn.nukkit.level.Level)

Example 17 with BaseFullChunk

use of cn.nukkit.level.format.generic.BaseFullChunk in project Nukkit by Nukkit.

the class GenerationTask method onRun.

@Override
public void onRun() {
    Generator generator = GeneratorPool.get(this.levelId);
    if (generator == null) {
        this.state = false;
        return;
    }
    SimpleChunkManager manager = (SimpleChunkManager) generator.getChunkManager();
    if (manager == null) {
        this.state = false;
        return;
    }
    synchronized (manager) {
        BaseFullChunk chunk = this.chunk.clone();
        if (chunk == null) {
            return;
        }
        manager.setChunk(chunk.getX(), chunk.getZ(), chunk);
        generator.generateChunk(chunk.getX(), chunk.getZ());
        chunk = manager.getChunk(chunk.getX(), chunk.getZ());
        chunk.setGenerated();
        this.chunk = chunk.clone();
        manager.setChunk(chunk.getX(), chunk.getZ(), null);
    }
}
Also used : SimpleChunkManager(cn.nukkit.level.SimpleChunkManager) BaseFullChunk(cn.nukkit.level.format.generic.BaseFullChunk) Generator(cn.nukkit.level.generator.Generator)

Example 18 with BaseFullChunk

use of cn.nukkit.level.format.generic.BaseFullChunk in project Nukkit by Nukkit.

the class LightPopulationTask method onCompletion.

@Override
public void onCompletion(Server server) {
    Level level = server.getLevel(this.levelId);
    BaseFullChunk chunk = this.chunk.clone();
    if (level != null) {
        if (chunk == null) {
            return;
        }
        level.generateChunkCallback(chunk.getX(), chunk.getZ(), chunk);
    }
}
Also used : BaseFullChunk(cn.nukkit.level.format.generic.BaseFullChunk) Level(cn.nukkit.level.Level)

Example 19 with BaseFullChunk

use of cn.nukkit.level.format.generic.BaseFullChunk in project Nukkit by Nukkit.

the class PopulationTask method onRun.

@Override
public void onRun() {
    Generator generator = GeneratorPool.get(this.levelId);
    if (generator == null) {
        this.state = false;
        return;
    }
    SimpleChunkManager manager = (SimpleChunkManager) generator.getChunkManager();
    if (manager == null) {
        this.state = false;
        return;
    }
    synchronized (generator.getChunkManager()) {
        BaseFullChunk[] chunks = new BaseFullChunk[9];
        BaseFullChunk chunk = this.chunk.clone();
        if (chunk == null) {
            return;
        }
        for (int i = 0; i < 9; i++) {
            if (i == 4) {
                continue;
            }
            int xx = -1 + i % 3;
            int zz = -1 + (i / 3);
            BaseFullChunk ck = this.chunks[i];
            if (ck == null) {
                try {
                    chunks[i] = (BaseFullChunk) this.chunk.getClass().getMethod("getEmptyChunk", int.class, int.class).invoke(null, chunk.getX() + xx, chunk.getZ() + zz);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            } else {
                chunks[i] = ck.clone();
            }
        }
        manager.setChunk(chunk.getX(), chunk.getZ(), chunk);
        if (!chunk.isGenerated()) {
            generator.generateChunk(chunk.getX(), chunk.getZ());
            chunk.setGenerated();
        }
        for (BaseFullChunk c : chunks) {
            if (c != null) {
                manager.setChunk(c.getX(), c.getZ(), c);
                if (!c.isGenerated()) {
                    generator.generateChunk(c.getX(), c.getZ());
                    c = manager.getChunk(c.getX(), c.getZ());
                    c.setGenerated();
                    manager.setChunk(c.getX(), c.getZ(), c);
                }
            }
        }
        generator.populateChunk(chunk.getX(), chunk.getZ());
        chunk = manager.getChunk(chunk.getX(), chunk.getZ());
        chunk.recalculateHeightMap();
        chunk.populateSkyLight();
        chunk.setLightPopulated();
        chunk.setPopulated();
        this.chunk = chunk.clone();
        manager.setChunk(chunk.getX(), chunk.getZ(), null);
        for (int i = 0; i < chunks.length; i++) {
            if (i == 4) {
                continue;
            }
            BaseFullChunk c = chunks[i];
            if (c != null) {
                c = chunks[i] = manager.getChunk(c.getX(), c.getZ());
                if (!c.hasChanged()) {
                    chunks[i] = null;
                }
            }
        }
        manager.cleanChunks();
        for (int i = 0; i < 9; i++) {
            if (i == 4) {
                continue;
            }
            this.chunks[i] = chunks[i] != null ? chunks[i].clone() : null;
        }
    }
}
Also used : SimpleChunkManager(cn.nukkit.level.SimpleChunkManager) BaseFullChunk(cn.nukkit.level.format.generic.BaseFullChunk) Generator(cn.nukkit.level.generator.Generator)

Example 20 with BaseFullChunk

use of cn.nukkit.level.format.generic.BaseFullChunk in project Nukkit by Nukkit.

the class PopulatorGlowStone method populate.

@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random) {
    this.level = level;
    BaseFullChunk chunk = level.getChunk(chunkX, chunkZ);
    int bx = chunkX << 4;
    int bz = chunkZ << 4;
    int tx = bx + 15;
    int tz = bz + 15;
    ObjectOre ore = new ObjectOre(random, type, Block.AIR);
    for (int i = 0; i < ore.type.clusterCount; ++i) {
        int x = random.nextRange(0, 15);
        int z = random.nextRange(0, 15);
        int y = this.getHighestWorkableBlock(chunk, x, z);
        if (y != -1) {
            ore.placeObject(level, bx + x, y, bz + z);
        }
    }
}
Also used : BaseFullChunk(cn.nukkit.level.format.generic.BaseFullChunk) ObjectOre(cn.nukkit.level.generator.object.ore.ObjectOre)

Aggregations

BaseFullChunk (cn.nukkit.level.format.generic.BaseFullChunk)26 IOException (java.io.IOException)5 BlockEntity (cn.nukkit.blockentity.BlockEntity)4 FullChunk (cn.nukkit.level.format.FullChunk)4 Player (cn.nukkit.Player)3 Entity (cn.nukkit.entity.Entity)3 Level (cn.nukkit.level.Level)3 Block (cn.nukkit.block.Block)2 ItemBlock (cn.nukkit.item.ItemBlock)2 SimpleChunkManager (cn.nukkit.level.SimpleChunkManager)2 BaseRegionLoader (cn.nukkit.level.format.generic.BaseRegionLoader)2 Generator (cn.nukkit.level.generator.Generator)2 CompoundTag (cn.nukkit.nbt.tag.CompoundTag)2 Int2ObjectOpenHashMap (it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap)2 Long2ObjectMap (it.unimi.dsi.fastutil.longs.Long2ObjectMap)2 Long2ObjectOpenHashMap (it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 BlockEntitySpawnable (cn.nukkit.blockentity.BlockEntitySpawnable)1 BlockUpdateEvent (cn.nukkit.event.block.BlockUpdateEvent)1 LevelProvider (cn.nukkit.level.format.LevelProvider)1