Search in sources :

Example 1 with Generator

use of cn.nukkit.level.generator.Generator 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 2 with Generator

use of cn.nukkit.level.generator.Generator in project Nukkit by Nukkit.

the class GeneratorRegisterTask method onRun.

@Override
public void onRun() {
    Block.init();
    Biome.init();
    SimpleChunkManager manager = new SimpleChunkManager(this.seed);
    try {
        Generator generator = this.generator.getConstructor(Map.class).newInstance(this.settings);
        generator.init(manager, new NukkitRandom(manager.getSeed()));
        GeneratorPool.put(this.levelId, generator);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : SimpleChunkManager(cn.nukkit.level.SimpleChunkManager) Map(java.util.Map) NukkitRandom(cn.nukkit.math.NukkitRandom) Generator(cn.nukkit.level.generator.Generator)

Example 3 with Generator

use of cn.nukkit.level.generator.Generator 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)

Aggregations

SimpleChunkManager (cn.nukkit.level.SimpleChunkManager)3 Generator (cn.nukkit.level.generator.Generator)3 BaseFullChunk (cn.nukkit.level.format.generic.BaseFullChunk)2 NukkitRandom (cn.nukkit.math.NukkitRandom)1 Map (java.util.Map)1