Search in sources :

Example 11 with FullChunk

use of cn.nukkit.level.format.FullChunk in project Nukkit by Nukkit.

the class Level method getFullLight.

public int getFullLight(Vector3 pos) {
    FullChunk chunk = this.getChunk((int) pos.x >> 4, (int) pos.z >> 4, false);
    int level = 0;
    if (chunk != null) {
        level = chunk.getBlockSkyLight((int) pos.x & 0x0f, (int) pos.y & 0xff, (int) pos.z & 0x0f);
        level -= this.skyLightSubtracted;
        if (level < 15) {
            level = Math.max(chunk.getBlockLight((int) pos.x & 0x0f, (int) pos.y & 0xff, (int) pos.z & 0x0f), level);
        }
    }
    return level;
}
Also used : BaseFullChunk(cn.nukkit.level.format.generic.BaseFullChunk) FullChunk(cn.nukkit.level.format.FullChunk)

Example 12 with FullChunk

use of cn.nukkit.level.format.FullChunk in project Nukkit by Nukkit.

the class Level method generateChunkCallback.

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();
}
Also used : BaseFullChunk(cn.nukkit.level.format.generic.BaseFullChunk) FullChunk(cn.nukkit.level.format.FullChunk)

Example 13 with FullChunk

use of cn.nukkit.level.format.FullChunk in project Nukkit by Nukkit.

the class Level method tickChunks.

private void tickChunks() {
    if (this.chunksPerTicks <= 0 || this.loaders.isEmpty()) {
        this.chunkTickList.clear();
        return;
    }
    int chunksPerLoader = Math.min(200, Math.max(1, (int) (((double) (this.chunksPerTicks - this.loaders.size()) / this.loaders.size() + 0.5))));
    int randRange = 3 + chunksPerLoader / 30;
    randRange = randRange > this.chunkTickRadius ? this.chunkTickRadius : randRange;
    ThreadLocalRandom random = ThreadLocalRandom.current();
    if (!this.loaders.isEmpty()) {
        for (ChunkLoader loader : this.loaders.values()) {
            int chunkX = (int) loader.getX() >> 4;
            int chunkZ = (int) loader.getZ() >> 4;
            long index = Level.chunkHash(chunkX, chunkZ);
            int existingLoaders = Math.max(0, this.chunkTickList.getOrDefault(index, 0));
            this.chunkTickList.put(index, (Integer) (existingLoaders + 1));
            for (int chunk = 0; chunk < chunksPerLoader; ++chunk) {
                int dx = random.nextInt(2 * randRange) - randRange;
                int dz = random.nextInt(2 * randRange) - randRange;
                long hash = Level.chunkHash(dx + chunkX, dz + chunkZ);
                if (!this.chunkTickList.containsKey(hash) && provider.isChunkLoaded(hash)) {
                    this.chunkTickList.put(hash, (Integer) (-1));
                }
            }
        }
    }
    int blockTest = 0;
    if (!chunkTickList.isEmpty()) {
        ObjectIterator<Long2ObjectMap.Entry<Integer>> iter = chunkTickList.long2ObjectEntrySet().fastIterator();
        while (iter.hasNext()) {
            Long2ObjectMap.Entry<Integer> entry = iter.next();
            long index = entry.getLongKey();
            if (!areNeighboringChunksLoaded(index)) {
                iter.remove();
                continue;
            }
            int loaders = entry.getValue();
            int chunkX = getHashX(index);
            int chunkZ = getHashZ(index);
            FullChunk chunk;
            if ((chunk = this.getChunk(chunkX, chunkZ, false)) == null) {
                iter.remove();
                continue;
            } else if (loaders <= 0) {
                iter.remove();
            }
            for (Entity entity : chunk.getEntities().values()) {
                entity.scheduleUpdate();
            }
            int tickSpeed = 3;
            if (tickSpeed > 0) {
                if (this.useSections) {
                    for (ChunkSection section : ((Chunk) chunk).getSections()) {
                        if (!(section instanceof EmptyChunkSection)) {
                            int Y = section.getY();
                            this.updateLCG = this.updateLCG * 3 + 1013904223;
                            int k = this.updateLCG >> 2;
                            for (int i = 0; i < tickSpeed; ++i, k >>= 10) {
                                int x = k & 0x0f;
                                int y = k >> 8 & 0x0f;
                                int z = k >> 16 & 0x0f;
                                int fullId = section.getFullBlock(x, y, z);
                                int blockId = fullId >> 4;
                                if (randomTickBlocks[blockId]) {
                                    Block block = Block.get(fullId, this, chunkX * 16 + x, (Y << 4) + y, chunkZ * 16 + z);
                                    block.onUpdate(BLOCK_UPDATE_RANDOM);
                                }
                            }
                        }
                    }
                } else {
                    for (int Y = 0; Y < 8 && (Y < 3 || blockTest != 0); ++Y) {
                        blockTest = 0;
                        this.updateLCG = this.updateLCG * 3 + 1013904223;
                        int k = this.updateLCG >> 2;
                        for (int i = 0; i < tickSpeed; ++i, k >>= 10) {
                            int x = k & 0x0f;
                            int y = k >> 8 & 0x0f;
                            int z = k >> 16 & 0x0f;
                            int fullId = chunk.getFullBlock(x, y + (Y << 4), z);
                            int blockId = fullId >> 4;
                            blockTest |= fullId;
                            if (this.randomTickBlocks[blockId]) {
                                Block block = Block.get(fullId, this, x, y + (Y << 4), z);
                                block.onUpdate(BLOCK_UPDATE_RANDOM);
                            }
                        }
                    }
                }
            }
        }
    }
    if (this.clearChunksOnTick) {
        this.chunkTickList.clear();
    }
}
Also used : BlockEntity(cn.nukkit.blockentity.BlockEntity) Entity(cn.nukkit.entity.Entity) Long2ObjectMap(it.unimi.dsi.fastutil.longs.Long2ObjectMap) Chunk(cn.nukkit.level.format.Chunk) BaseFullChunk(cn.nukkit.level.format.generic.BaseFullChunk) FullChunk(cn.nukkit.level.format.FullChunk) EmptyChunkSection(cn.nukkit.level.format.generic.EmptyChunkSection) BaseFullChunk(cn.nukkit.level.format.generic.BaseFullChunk) FullChunk(cn.nukkit.level.format.FullChunk) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) ItemBlock(cn.nukkit.item.ItemBlock) Block(cn.nukkit.block.Block) EmptyChunkSection(cn.nukkit.level.format.generic.EmptyChunkSection) ChunkSection(cn.nukkit.level.format.ChunkSection)

Example 14 with FullChunk

use of cn.nukkit.level.format.FullChunk in project Nukkit by Nukkit.

the class Flat method generateChunk.

@Override
public void generateChunk(int chunkX, int chunkZ) {
    if (!this.init) {
        init = true;
        if (this.options.containsKey("preset") && !"".equals(this.options.get("preset"))) {
            this.parsePreset((String) this.options.get("preset"), chunkX, chunkZ);
        } else {
            this.parsePreset(this.preset, chunkX, chunkZ);
        }
    }
    FullChunk chunk = this.level.getChunk(chunkX, chunkZ);
    this.generateChunk(chunk);
}
Also used : FullChunk(cn.nukkit.level.format.FullChunk)

Example 15 with FullChunk

use of cn.nukkit.level.format.FullChunk in project Nukkit by Nukkit.

the class Nether method populateChunk.

@Override
public void populateChunk(int chunkX, int chunkZ) {
    this.nukkitRandom.setSeed(0xdeadbeef ^ (chunkX << 8) ^ chunkZ ^ this.level.getSeed());
    for (Populator populator : this.populators) {
        populator.populate(this.level, chunkX, chunkZ, this.nukkitRandom);
    }
    FullChunk chunk = this.level.getChunk(chunkX, chunkZ);
    Biome biome = Biome.getBiome(chunk.getBiomeId(7, 7));
    biome.populateChunk(this.level, chunkX, chunkZ, this.nukkitRandom);
}
Also used : FullChunk(cn.nukkit.level.format.FullChunk) Biome(cn.nukkit.level.generator.biome.Biome)

Aggregations

FullChunk (cn.nukkit.level.format.FullChunk)16 BaseFullChunk (cn.nukkit.level.format.generic.BaseFullChunk)8 Biome (cn.nukkit.level.generator.biome.Biome)5 BlockEntity (cn.nukkit.blockentity.BlockEntity)4 Entity (cn.nukkit.entity.Entity)4 Long2ObjectMap (it.unimi.dsi.fastutil.longs.Long2ObjectMap)4 Block (cn.nukkit.block.Block)3 CompoundTag (cn.nukkit.nbt.tag.CompoundTag)3 Int2ObjectOpenHashMap (it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap)3 Long2ObjectOpenHashMap (it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ItemBlock (cn.nukkit.item.ItemBlock)2 DoubleTag (cn.nukkit.nbt.tag.DoubleTag)2 FloatTag (cn.nukkit.nbt.tag.FloatTag)2 ListTag (cn.nukkit.nbt.tag.ListTag)2 Player (cn.nukkit.Player)1 EntityPainting (cn.nukkit.entity.item.EntityPainting)1 Chunk (cn.nukkit.level.format.Chunk)1 ChunkSection (cn.nukkit.level.format.ChunkSection)1 LevelProvider (cn.nukkit.level.format.LevelProvider)1