Java Code Examples for cn.nukkit.level.format.generic.BaseFullChunk#isPopulated()

The following examples show how to use cn.nukkit.level.format.generic.BaseFullChunk#isPopulated() . 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: Anvil.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void doGarbageCollection(long time) {
    long start = System.currentTimeMillis();
    int maxIterations = size();
    if (lastPosition > maxIterations) lastPosition = 0;
    int i;
    synchronized (chunks) {
        ObjectIterator<BaseFullChunk> iter = chunks.values().iterator();
        if (lastPosition != 0) iter.skip(lastPosition);
        for (i = 0; i < maxIterations; i++) {
            if (!iter.hasNext()) {
                iter = chunks.values().iterator();
            }
            if (!iter.hasNext()) break;
            BaseFullChunk chunk = iter.next();
            if (chunk == null) continue;
            if (chunk.isGenerated() && chunk.isPopulated() && chunk instanceof Chunk) {
                Chunk anvilChunk = (Chunk) chunk;
                chunk.compress();
                if (System.currentTimeMillis() - start >= time) break;
            }
        }
    }
    lastPosition += i;
}
 
Example 2
Source File: Level.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public void generateChunkCallback(int x, int z, BaseFullChunk chunk) {
    Timings.generationCallbackTimer.startTiming();
    Long index = Level.chunkHash(x, z);
    if (this.chunkPopulationQueue.containsKey(index)) {
        FullChunk oldChunk = this.getChunk(x, z, false);
        for (int xx = -1; xx <= 1; ++xx) {
            for (int zz = -1; zz <= 1; ++zz) {
                this.chunkPopulationLock.remove(Level.chunkHash(x + xx, z + zz));
            }
        }
        this.chunkPopulationQueue.remove(index);
        chunk.setProvider(this.provider);
        this.setChunk(x, z, chunk, false);
        chunk = this.getChunk(x, z, false);
        if (chunk != null && (oldChunk == null || !oldChunk.isPopulated()) && chunk.isPopulated()
                && chunk.getProvider() != null) {
            this.server.getPluginManager().callEvent(new ChunkPopulateEvent(chunk));

            for (ChunkLoader loader : this.getChunkLoaders(x, z)) {
                loader.onChunkPopulated(chunk);
            }
        }
    } else if (this.chunkGenerationQueue.containsKey(index) || this.chunkPopulationLock.containsKey(index)) {
        this.chunkGenerationQueue.remove(index);
        this.chunkPopulationLock.remove(index);
        chunk.setProvider(this.provider);
        this.setChunk(x, z, chunk, false);
    } else {
        chunk.setProvider(this.provider);
        this.setChunk(x, z, chunk, false);
    }
    Timings.generationCallbackTimer.stopTiming();
}
 
Example 3
Source File: Level.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public boolean populateChunk(int x, int z, boolean force) {
    Long index = Level.chunkHash(x, z);
    if (this.chunkPopulationQueue.containsKey(index) || this.chunkPopulationQueue.size() >= this.chunkPopulationQueueSize && !force) {
        return false;
    }

    BaseFullChunk chunk = this.getChunk(x, z, true);
    boolean populate;
    if (!chunk.isPopulated()) {
        Timings.populationTimer.startTiming();
        populate = true;
        for (int xx = -1; xx <= 1; ++xx) {
            for (int zz = -1; zz <= 1; ++zz) {
                if (this.chunkPopulationLock.containsKey(Level.chunkHash(x + xx, z + zz))) {

                    populate = false;
                    break;
                }
            }
        }

        if (populate) {
            if (!this.chunkPopulationQueue.containsKey(index)) {
                this.chunkPopulationQueue.put(index, true);
                for (int xx = -1; xx <= 1; ++xx) {
                    for (int zz = -1; zz <= 1; ++zz) {
                        this.chunkPopulationLock.put(Level.chunkHash(x + xx, z + zz), true);
                    }
                }

                PopulationTask task = new PopulationTask(this, chunk);
                this.server.getScheduler().scheduleAsyncTask(task);
            }
        }
        Timings.populationTimer.stopTiming();
        return false;
    }

    return true;
}
 
Example 4
Source File: Level.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void generateChunkCallback(int x, int z, BaseFullChunk chunk, boolean isPopulated) {
    Timings.generationCallbackTimer.startTiming();
    long index = Level.chunkHash(x, z);
    if (this.chunkPopulationQueue.containsKey(index)) {
        FullChunk oldChunk = this.getChunk(x, z, false);
        for (int xx = -1; xx <= 1; ++xx) {
            for (int zz = -1; zz <= 1; ++zz) {
                this.chunkPopulationLock.remove(Level.chunkHash(x + xx, z + zz));
            }
        }
        this.chunkPopulationQueue.remove(index);
        chunk.setProvider(this.provider);
        this.setChunk(x, z, chunk, false);
        chunk = this.getChunk(x, z, false);
        if (chunk != null && (oldChunk == null || !isPopulated) && chunk.isPopulated()
                && chunk.getProvider() != null) {
            this.server.getPluginManager().callEvent(new ChunkPopulateEvent(chunk));

            for (ChunkLoader loader : this.getChunkLoaders(x, z)) {
                loader.onChunkPopulated(chunk);
            }
        }
    } else if (this.chunkGenerationQueue.containsKey(index) || this.chunkPopulationLock.containsKey(index)) {
        this.chunkGenerationQueue.remove(index);
        this.chunkPopulationLock.remove(index);
        chunk.setProvider(this.provider);
        this.setChunk(x, z, chunk, false);
    } else {
        chunk.setProvider(this.provider);
        this.setChunk(x, z, chunk, false);
    }
    Timings.generationCallbackTimer.stopTiming();
}
 
Example 5
Source File: Level.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
private synchronized BaseFullChunk forceLoadChunk(long index, int x, int z, boolean generate) {
    this.timings.syncChunkLoadTimer.startTiming();
    BaseFullChunk chunk = this.provider.getChunk(x, z, generate);
    if (chunk == null) {
        if (generate) {
            throw new IllegalStateException("Could not create new Chunk");
        }
        this.timings.syncChunkLoadTimer.stopTiming();
        return chunk;
    }

    if (chunk.getProvider() != null) {
        this.server.getPluginManager().callEvent(new ChunkLoadEvent(chunk, !chunk.isGenerated()));
    } else {
        this.unloadChunk(x, z, false);
        this.timings.syncChunkLoadTimer.stopTiming();
        return chunk;
    }

    chunk.initChunk();

    if (!chunk.isLightPopulated() && chunk.isPopulated()
            && this.getServer().getConfig("chunk-ticking.light-updates", false)) {
        this.getServer().getScheduler().scheduleAsyncTask(new LightPopulationTask(this, chunk));
    }

    if (this.isChunkInUse(index)) {
        this.unloadQueue.remove(index);
        for (ChunkLoader loader : this.getChunkLoaders(x, z)) {
            loader.onChunkLoaded(chunk);
        }
    } else {
        this.unloadQueue.put(index, System.currentTimeMillis());
    }
    this.timings.syncChunkLoadTimer.stopTiming();
    return chunk;
}
 
Example 6
Source File: Level.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public boolean populateChunk(int x, int z, boolean force) {
    long index = Level.chunkHash(x, z);
    if (this.chunkPopulationQueue.containsKey(index) || this.chunkPopulationQueue.size() >= this.chunkPopulationQueueSize && !force) {
        return false;
    }

    BaseFullChunk chunk = this.getChunk(x, z, true);
    boolean populate;
    if (!chunk.isPopulated()) {
        Timings.populationTimer.startTiming();
        populate = true;
        for (int xx = -1; xx <= 1; ++xx) {
            for (int zz = -1; zz <= 1; ++zz) {
                if (this.chunkPopulationLock.containsKey(Level.chunkHash(x + xx, z + zz))) {

                    populate = false;
                    break;
                }
            }
        }

        if (populate) {
            if (!this.chunkPopulationQueue.containsKey(index)) {
                this.chunkPopulationQueue.put(index, Boolean.TRUE);
                for (int xx = -1; xx <= 1; ++xx) {
                    for (int zz = -1; zz <= 1; ++zz) {
                        this.chunkPopulationLock.put(Level.chunkHash(x + xx, z + zz), Boolean.TRUE);
                    }
                }

                PopulationTask task = new PopulationTask(this, chunk);
                this.server.getScheduler().scheduleAsyncTask(task);
            }
        }
        Timings.populationTimer.stopTiming();
        return false;
    }

    return true;
}
 
Example 7
Source File: Anvil.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void doGarbageCollection(long time) {
    long start = System.currentTimeMillis();
    int maxIterations = size();
    if (lastPosition > maxIterations) lastPosition = 0;
    ObjectIterator<BaseFullChunk> iter = getChunks();
    if (lastPosition != 0) iter.skip(lastPosition);
    int i;
    for (i = 0; i < maxIterations; i++) {
        if (!iter.hasNext()) {
            iter = getChunks();
        }
        BaseFullChunk chunk = iter.next();
        if (chunk == null) continue;
        if (chunk.isGenerated() && chunk.isPopulated() && chunk instanceof Chunk) {
            Chunk anvilChunk = (Chunk) chunk;
            for (cn.nukkit.level.format.ChunkSection section : anvilChunk.getSections()) {
                if (section instanceof ChunkSection) {
                    ChunkSection anvilSection = (ChunkSection) section;
                    if (!anvilSection.isEmpty()) {
                        anvilSection.compress();
                    }
                }
            }
            if (System.currentTimeMillis() - start >= time) break;
        }
    }
    lastPosition += i;
}
 
Example 8
Source File: Level.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void generateChunkCallback(int x, int z, BaseFullChunk chunk) {
    Timings.generationCallbackTimer.startTiming();
    long index = Level.chunkHash(x, z);
    if (this.chunkPopulationQueue.containsKey(index)) {
        FullChunk oldChunk = this.getChunk(x, z, false);
        for (int xx = -1; xx <= 1; ++xx) {
            for (int zz = -1; zz <= 1; ++zz) {
                this.chunkPopulationLock.remove(Level.chunkHash(x + xx, z + zz));
            }
        }
        this.chunkPopulationQueue.remove(index);
        chunk.setProvider(this.provider);
        this.setChunk(x, z, chunk, false);
        chunk = this.getChunk(x, z, false);
        if (chunk != null && (oldChunk == null || !oldChunk.isPopulated()) && chunk.isPopulated()
                && chunk.getProvider() != null) {
            this.server.getPluginManager().callEvent(new ChunkPopulateEvent(chunk));

            for (ChunkLoader loader : this.getChunkLoaders(x, z)) {
                loader.onChunkPopulated(chunk);
            }
        }
    } else if (this.chunkGenerationQueue.containsKey(index) || this.chunkPopulationLock.containsKey(index)) {
        this.chunkGenerationQueue.remove(index);
        this.chunkPopulationLock.remove(index);
        chunk.setProvider(this.provider);
        this.setChunk(x, z, chunk, false);
    } else {
        chunk.setProvider(this.provider);
        this.setChunk(x, z, chunk, false);
    }
    Timings.generationCallbackTimer.stopTiming();
}
 
Example 9
Source File: Level.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
private BaseFullChunk forceLoadChunk(long index, int x, int z, boolean generate) {
    this.timings.syncChunkLoadTimer.startTiming();
    BaseFullChunk chunk = this.provider.getChunk(x, z, generate);
    if (chunk == null) {
        if (generate) {
            throw new IllegalStateException("Could not create new Chunk");
        }
        this.timings.syncChunkLoadTimer.stopTiming();
        return chunk;
    }

    if (chunk.getProvider() != null) {
        this.server.getPluginManager().callEvent(new ChunkLoadEvent(chunk, !chunk.isGenerated()));
    } else {
        this.unloadChunk(x, z, false);
        this.timings.syncChunkLoadTimer.stopTiming();
        return chunk;
    }

    chunk.initChunk();

    if (!chunk.isLightPopulated() && chunk.isPopulated()
            && (boolean) this.getServer().getConfig("chunk-ticking.light-updates", false)) {
        this.getServer().getScheduler().scheduleAsyncTask(new LightPopulationTask(this, chunk));
    }

    if (this.isChunkInUse(index)) {
        this.unloadQueue.remove(index);
        for (ChunkLoader loader : this.getChunkLoaders(x, z)) {
            loader.onChunkLoaded(chunk);
        }
    } else {
        this.unloadQueue.put(index, (Long) System.currentTimeMillis());
    }
    this.timings.syncChunkLoadTimer.stopTiming();
    return chunk;
}
 
Example 10
Source File: Level.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public boolean populateChunk(int x, int z, boolean force) {
    long index = Level.chunkHash(x, z);
    if (this.chunkPopulationQueue.containsKey(index) || this.chunkPopulationQueue.size() >= this.chunkPopulationQueueSize && !force) {
        return false;
    }

    BaseFullChunk chunk = this.getChunk(x, z, true);
    boolean populate;
    if (!chunk.isPopulated()) {
        Timings.populationTimer.startTiming();
        populate = true;
        for (int xx = -1; xx <= 1; ++xx) {
            for (int zz = -1; zz <= 1; ++zz) {
                if (this.chunkPopulationLock.containsKey(Level.chunkHash(x + xx, z + zz))) {

                    populate = false;
                    break;
                }
            }
        }

        if (populate) {
            if (!this.chunkPopulationQueue.containsKey(index)) {
                this.chunkPopulationQueue.put(index, Boolean.TRUE);
                for (int xx = -1; xx <= 1; ++xx) {
                    for (int zz = -1; zz <= 1; ++zz) {
                        this.chunkPopulationLock.put(Level.chunkHash(x + xx, z + zz), Boolean.TRUE);
                    }
                }

                PopulationTask task = new PopulationTask(this, chunk);
                this.server.getScheduler().scheduleAsyncTask(task);
            }
        }
        Timings.populationTimer.stopTiming();
        return false;
    }

    return true;
}
 
Example 11
Source File: Level.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public boolean loadChunk(int x, int z, boolean generate) {
    Long index = Level.chunkHash(x, z);
    if (this.chunks.containsKey(index)) {
        return true;
    }

    this.timings.syncChunkLoadTimer.startTiming();

    this.cancelUnloadChunkRequest(x, z);

    BaseFullChunk chunk = this.provider.getChunk(x, z, generate);

    if (chunk == null) {
        if (generate) {
            throw new IllegalStateException("Could not create new Chunk");
        }
        return false;
    }

    this.chunks.put(index, chunk);
    chunk.initChunk();

    if (chunk.getProvider() != null) {
        this.server.getPluginManager().callEvent(new ChunkLoadEvent(chunk, !chunk.isGenerated()));
    } else {
        this.unloadChunk(x, z, false);
        this.timings.syncChunkLoadTimer.stopTiming();
        return false;
    }

    if (!chunk.isLightPopulated() && chunk.isPopulated()
            && (boolean) this.getServer().getConfig("chunk-ticking.light-updates", false)) {
        this.getServer().getScheduler().scheduleAsyncTask(new LightPopulationTask(this, chunk));
    }

    if (this.isChunkInUse(x, z)) {
        for (ChunkLoader loader : this.getChunkLoaders(x, z)) {
            loader.onChunkLoaded(chunk);
        }
    } else {
        this.unloadChunkRequest(x, z);
    }
    this.timings.syncChunkLoadTimer.stopTiming();
    return true;
}