cn.nukkit.level.format.FullChunk Java Examples

The following examples show how to use cn.nukkit.level.format.FullChunk. 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: EssentialsAPI.java    From EssentialsNK with GNU General Public License v3.0 6 votes vote down vote up
public void strikeLighting(Position pos) {
    FullChunk chunk = pos.getLevel().getChunk((int) pos.getX() >> 4, (int) pos.getZ() >> 4);
    CompoundTag nbt = new CompoundTag()
            .putList(new ListTag<DoubleTag>("Pos")
                    .add(new DoubleTag("", pos.getX()))
                    .add(new DoubleTag("", pos.getY()))
                    .add(new DoubleTag("", pos.getZ())))
            .putList(new ListTag<DoubleTag>("Motion")
                    .add(new DoubleTag("", 0))
                    .add(new DoubleTag("", 0))
                    .add(new DoubleTag("", 0)))
            .putList(new ListTag<FloatTag>("Rotation")
                    .add(new FloatTag("", 0))
                    .add(new FloatTag("", 0)));
    EntityLightning lightning = new EntityLightning(chunk, nbt);
    lightning.spawnToAll();
}
 
Example #2
Source File: EntityThrownTrident.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public Entity create(Object type, Position source, Object... args) {
    FullChunk chunk = source.getLevel().getChunk((int) source.x >> 4, (int) source.z >> 4);
    if (chunk == null) return null;

    CompoundTag nbt = new CompoundTag()
            .putList(new ListTag<DoubleTag>("Pos")
                    .add(new DoubleTag("", source.x + 0.5))
                    .add(new DoubleTag("", source.y))
                    .add(new DoubleTag("", source.z + 0.5)))
            .putList(new ListTag<DoubleTag>("Motion")
                    .add(new DoubleTag("", 0))
                    .add(new DoubleTag("", 0))
                    .add(new DoubleTag("", 0)))
            .putList(new ListTag<FloatTag>("Rotation")
                    .add(new FloatTag("", new Random().nextFloat() * 360))
                    .add(new FloatTag("", 0)));

    return Entity.createEntity(type.toString(), chunk, nbt, args);
}
 
Example #3
Source File: PopulatorRavines.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
protected void generateChunk(int chunkX, int chunkZ, FullChunk generatingChunkBuffer) {
    if (this.random.nextInt(300) >= this.ravineRarity)
        return;
    double d1 = (chunkX * 16) + this.random.nextInt(16);
    double d2 = numberInRange(random, this.ravineMinAltitude, this.ravineMaxAltitude);
    double d3 = (chunkZ * 16) + this.random.nextInt(16);

    int i = 1;

    for (int j = 0; j < i; j++) {
        float f1 = this.random.nextFloat() * 3.141593F * 2.0F;
        float f2 = (this.random.nextFloat() - 0.5F) * 2.0F / 8.0F;
        float f3 = (this.random.nextFloat() * 2.0F + this.random.nextFloat()) * 2.0F;

        int size = numberInRange(random, this.ravineMinLength, this.ravineMaxLength);

        createRavine(this.random.nextLong(), generatingChunkBuffer, d1, d2, d3, f3, f1, f2, size, this.ravineDepth);
    }
}
 
Example #4
Source File: WaterIcePopulator.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random, FullChunk chunk) {
    for (int x = 0; x < 16; x++) {
        for (int z = 0; z < 16; z++) {
            Biome biome = EnumBiome.getBiome(chunk.getBiomeId(x, z));
            if (biome.isFreezing()) {
                int topBlock = chunk.getHighestBlockAt(x, z);
                if (chunk.getBlockId(x, topBlock, z) == STILL_WATER)     {
                    chunk.setBlockId(x, topBlock, z, ICE);
                }
            }
        }
    }
}
 
Example #5
Source File: Level.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public void doChunkGarbageCollection() {
    this.timings.doChunkGC.startTiming();
    // remove all invaild block entities.
    List<BlockEntity> toClose = new ArrayList<>();
    for (BlockEntity anBlockEntity : blockEntities.values()) {
        if (anBlockEntity == null)
            continue;
        if (anBlockEntity.isBlockEntityValid())
            continue;
        toClose.add(anBlockEntity);
    }
    for (BlockEntity be : toClose.toArray(new BlockEntity[toClose.size()])) {
        be.close();
    }

    for (Long index : this.chunks.keySet()) {

        if (!this.unloadQueue.containsKey(index)) {
            int X = getHashX(index);
            int Z = getHashZ(index);
            if (!this.isSpawnChunk(X, Z)) {
                this.unloadChunkRequest(X, Z, true);
            }
        }
    }

    for (FullChunk chunk : new ArrayList<>(this.provider.getLoadedChunks().values())) {
        if (!this.chunks.containsKey(Level.chunkHash(chunk.getX(), chunk.getZ()))) {
            this.provider.unloadChunk(chunk.getX(), chunk.getZ(), false);
        }
    }

    this.provider.doGarbageCollection();
    this.timings.doChunkGC.stopTiming();
}
 
Example #6
Source File: Level.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example #7
Source File: LevelDB.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void saveChunk(int x, int z, FullChunk chunk) {
    if (!(chunk instanceof Chunk)) {
        throw new ChunkException("Invalid Chunk class");
    }
    this.writeChunk((Chunk) chunk);
}
 
Example #8
Source File: Flat.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #9
Source File: SimpleChunkManager.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setBlockIdAt(int x, int y, int z, int id) {
    FullChunk chunk = this.getChunk(x >> 4, z >> 4);
    if (chunk != null) {
        chunk.setBlockId(x & 0xf, y & 0xff, z & 0xf, id);
    }
}
 
Example #10
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 #11
Source File: PopulatorCount.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public final void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random, FullChunk chunk) {
    int count = baseAmount + random.nextBoundedInt(randomAmount);
    for (int i = 0; i < count; i++) {
        populateCount(level, chunkX, chunkZ, random, chunk);
    }
}
 
Example #12
Source File: Nether.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void generateChunk(int chunkX, int chunkZ) {
    this.nukkitRandom.setSeed(chunkX * localSeed1 ^ chunkZ * localSeed2 ^ this.level.getSeed());

    double[][][] noise = Generator.getFastNoise3D(this.noiseBase, 16, 128, 16, 4, 8, 4, chunkX * 16, 0, chunkZ * 16);
    FullChunk chunk = this.level.getChunk(chunkX, chunkZ);

    for (int x = 0; x < 16; ++x) {
        for (int z = 0; z < 16; ++z) {
            Biome biome = Biome.getBiome(Biome.HELL);
            chunk.setBiomeId(x, z, Biome.HELL);
            int biomecolor = biome.getColor();
            chunk.setBiomeColor(x, z, (biomecolor >> 16), (biomecolor >> 8) & 0xff, (biomecolor & 0xff));

            chunk.setBlockId(x, 0, z, Block.BEDROCK);
            chunk.setBlockId(x, 127, z, Block.BEDROCK);

            for (int y = 1; y <= bedrockDepth; y++) {
                if (nukkitRandom.nextRange(1, 5) == 1) {
                    chunk.setBlockId(x, y, z, Block.BEDROCK);
                    chunk.setBlockId(x, 127 - y, z, Block.BEDROCK);
                }
            }
            for (int y = 1; y < 127; ++y) {
                double noiseValue = (Math.abs(this.emptyHeight - y) / this.emptyHeight) * this.emptyAmplitude - noise[x][z][y];
                noiseValue -= 1 - this.density;
                if (noiseValue > 0) {
                    chunk.setBlockId(x, y, z, Block.NETHERRACK);
                } else if (y <= this.waterHeight) {
                    chunk.setBlockId(x, y, z, Block.STILL_LAVA);
                    chunk.setBlockLight(x, y + 1, z, 15);
                }
            }
        }
    }
    for (Populator populator : this.generationPopulators) {
        populator.populate(this.level, chunkX, chunkZ, this.nukkitRandom);
    }
}
 
Example #13
Source File: PopulatorTree.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void populateCount(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random, FullChunk chunk) {
    this.level = level;
    int x = NukkitMath.randomRange(random, chunkX << 4, (chunkX << 4) + 15);
    int z = NukkitMath.randomRange(random, chunkZ << 4, (chunkZ << 4) + 15);
    int y = this.getHighestWorkableBlock(x, z);
    if (y < 3) {
        return;
    }
    ObjectTree.growTree(this.level, x, y, z, random, this.type);
}
 
Example #14
Source File: Level.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
private void performThunder(long index, FullChunk chunk) {
    if (areNeighboringChunksLoaded(index)) return;
    if (ThreadLocalRandom.current().nextInt(10000) == 0) {
        int LCG = this.getUpdateLCG() >> 2;

        int chunkX = chunk.getX() * 16;
        int chunkZ = chunk.getZ() * 16;
        Vector3 vector = this.adjustPosToNearbyEntity(new Vector3(chunkX + (LCG & 0xf), 0, chunkZ + (LCG >> 8 & 0xf)));

        Biome biome = Biome.getBiome(this.getBiomeId(vector.getFloorX(), vector.getFloorZ()));
        if (!biome.canRain()) {
            return;
        }

        int bId = this.getBlockIdAt(vector.getFloorX(), vector.getFloorY(), vector.getFloorZ());
        if (bId != Block.TALL_GRASS && bId != Block.WATER)
            vector.y += 1;
        CompoundTag nbt = new CompoundTag()
                .putList(new ListTag<DoubleTag>("Pos").add(new DoubleTag("", vector.x))
                        .add(new DoubleTag("", vector.y)).add(new DoubleTag("", vector.z)))
                .putList(new ListTag<DoubleTag>("Motion").add(new DoubleTag("", 0))
                        .add(new DoubleTag("", 0)).add(new DoubleTag("", 0)))
                .putList(new ListTag<FloatTag>("Rotation").add(new FloatTag("", 0))
                        .add(new FloatTag("", 0)));

        EntityLightning bolt = (EntityLightning) Entity.createEntity("Lightning", chunk, nbt);
        if(bolt == null) return;
        LightningStrikeEvent ev = new LightningStrikeEvent(this, bolt);
        getServer().getPluginManager().callEvent(ev);
        if (!ev.isCancelled()) {
            bolt.spawnToAll();
        } else {
            bolt.setEffect(false);
        }

        this.addLevelSoundEvent(vector, LevelSoundEventPacket.SOUND_THUNDER, -1, EntityLightning.NETWORK_ID);
        this.addLevelSoundEvent(vector, LevelSoundEventPacket.SOUND_EXPLODE, -1, EntityLightning.NETWORK_ID);
    }
}
 
Example #15
Source File: PopulatorSurfaceBlock.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void populateCount(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random, FullChunk chunk) {
    int x = random.nextBoundedInt(16);
    int z = random.nextBoundedInt(16);
    int y = getHighestWorkableBlock(level, x, z, chunk);
    if (y > 0 && canStay(x, y, z, chunk)) {
        placeBlock(x, y, z, getBlockId(x, z, random, chunk), chunk, random);
    }
}
 
Example #16
Source File: BlockEntitySkull.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public BlockEntitySkull(FullChunk chunk, CompoundTag nbt) {
    super(chunk, nbt);
    if (!nbt.contains("SkullType")) {
        nbt.putByte("SkullType", 0);
    }
    if (!nbt.contains("Rot")) {
        nbt.putByte("Rot", 0);
    }
    this.namedTag = nbt;
}
 
Example #17
Source File: Level.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public BlockEntity getBlockEntity(Vector3 pos) {
    FullChunk chunk = this.getChunk((int) pos.x >> 4, (int) pos.z >> 4, false);

    if (chunk != null) {
        return chunk.getTile((int) pos.x & 0x0f, (int) pos.y & 0xff, (int) pos.z & 0x0f);
    }

    return null;
}
 
Example #18
Source File: Entity.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public Entity(FullChunk chunk, CompoundTag nbt) {
    if (this instanceof Player) {
        return;
    }

    this.init(chunk, nbt);
}
 
Example #19
Source File: Entity.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public Entity(FullChunk chunk, CompoundTag nbt) {
    if (this instanceof Player) {
        return;
    }

    this.init(chunk, nbt);
}
 
Example #20
Source File: EntityElderGuardian.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public EntityElderGuardian(FullChunk chunk, CompoundTag nbt) {
    super(chunk, nbt);
}
 
Example #21
Source File: Entity.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
protected final void init(FullChunk chunk, CompoundTag nbt) {
    if ((chunk == null || chunk.getProvider() == null)) {
        throw new ChunkException("Invalid garbage Chunk given to Entity");
    }

    this.timing = Timings.getEntityTiming(this);

    this.isPlayer = this instanceof Player;
    this.temporalVector = new Vector3();

    this.id = Entity.entityCount++;
    this.justCreated = true;
    this.namedTag = nbt;

    this.chunk = chunk;
    this.setLevel(chunk.getProvider().getLevel());
    this.server = chunk.getProvider().getLevel().getServer();

    this.boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0);

    ListTag<DoubleTag> posList = this.namedTag.getList("Pos", DoubleTag.class);
    ListTag<FloatTag> rotationList = this.namedTag.getList("Rotation", FloatTag.class);
    ListTag<DoubleTag> motionList = this.namedTag.getList("Motion", DoubleTag.class);
    this.setPositionAndRotation(
            this.temporalVector.setComponents(
                    posList.get(0).data,
                    posList.get(1).data,
                    posList.get(2).data
            ),
            rotationList.get(0).data,
            rotationList.get(1).data
    );

    this.setMotion(this.temporalVector.setComponents(
            motionList.get(0).data,
            motionList.get(1).data,
            motionList.get(2).data
    ));

    if (!this.namedTag.contains("FallDistance")) {
        this.namedTag.putFloat("FallDistance", 0);
    }
    this.fallDistance = this.namedTag.getFloat("FallDistance");
    this.highestPosition = this.y + this.namedTag.getFloat("FallDistance");

    if (!this.namedTag.contains("Fire") || this.namedTag.getShort("Fire") > 32767) {
        this.namedTag.putShort("Fire", 0);
    }
    this.fireTicks = this.namedTag.getShort("Fire");

    if (!this.namedTag.contains("Air")) {
        this.namedTag.putShort("Air", 300);
    }
    this.setDataProperty(new ShortEntityData(DATA_AIR, this.namedTag.getShort("Air")), false);

    if (!this.namedTag.contains("OnGround")) {
        this.namedTag.putBoolean("OnGround", false);
    }
    this.onGround = this.namedTag.getBoolean("OnGround");

    if (!this.namedTag.contains("Invulnerable")) {
        this.namedTag.putBoolean("Invulnerable", false);
    }
    this.invulnerable = this.namedTag.getBoolean("Invulnerable");

    if (!this.namedTag.contains("Scale")) {
        this.namedTag.putFloat("Scale", 1);
    }
    this.scale = this.namedTag.getFloat("Scale");
    this.setDataProperty(new FloatEntityData(DATA_SCALE, scale), false);

    this.chunk.addEntity(this);
    this.level.addEntity(this);

    this.initEntity();

    this.lastUpdate = this.server.getTick();
    this.server.getPluginManager().callEvent(new EntitySpawnEvent(this));

    this.scheduleUpdate();
}
 
Example #22
Source File: BlockEntityMovingBlock.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public BlockEntityMovingBlock(FullChunk chunk, CompoundTag nbt) {
    super(chunk, nbt);
}
 
Example #23
Source File: EntityLlama.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public EntityLlama(FullChunk chunk, CompoundTag nbt) {
    super(chunk, nbt);
    this.setMaxHealth(random.nextRange(15, 30));
    this.setHealth(this.getMaxHealth());
}
 
Example #24
Source File: BlockEntityEnchantTable.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public BlockEntityEnchantTable(FullChunk chunk, CompoundTag nbt) {
    super(chunk, nbt);
}
 
Example #25
Source File: EntityStray.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public EntityStray(FullChunk chunk, CompoundTag nbt) {
    super(chunk, nbt);
}
 
Example #26
Source File: PopulatorFlower.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected boolean canStay(int x, int y, int z, FullChunk chunk) {
    return EnsureCover.ensureCover(x, y, z, chunk) && EnsureGrassBelow.ensureGrassBelow(x, y, z, chunk);
}
 
Example #27
Source File: Entity.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
protected final void init(FullChunk chunk, CompoundTag nbt) {
    if ((chunk == null || chunk.getProvider() == null)) {
        throw new ChunkException("Invalid garbage Chunk given to Entity");
    }

    if (this.initialized) {
        // We've already initialized this entity
        return;
    }
    this.initialized = true;

    this.timing = Timings.getEntityTiming(this);

    this.isPlayer = this instanceof Player;
    this.temporalVector = new Vector3();

    this.id = Entity.entityCount++;
    this.justCreated = true;
    this.namedTag = nbt;

    this.chunk = chunk;
    this.setLevel(chunk.getProvider().getLevel());
    this.server = chunk.getProvider().getLevel().getServer();

    this.boundingBox = new SimpleAxisAlignedBB(0, 0, 0, 0, 0, 0);

    ListTag<DoubleTag> posList = this.namedTag.getList("Pos", DoubleTag.class);
    ListTag<FloatTag> rotationList = this.namedTag.getList("Rotation", FloatTag.class);
    ListTag<DoubleTag> motionList = this.namedTag.getList("Motion", DoubleTag.class);
    this.setPositionAndRotation(
            this.temporalVector.setComponents(
                    posList.get(0).data,
                    posList.get(1).data,
                    posList.get(2).data
            ),
            rotationList.get(0).data,
            rotationList.get(1).data
    );

    this.setMotion(this.temporalVector.setComponents(
            motionList.get(0).data,
            motionList.get(1).data,
            motionList.get(2).data
    ));

    if (!this.namedTag.contains("FallDistance")) {
        this.namedTag.putFloat("FallDistance", 0);
    }
    this.fallDistance = this.namedTag.getFloat("FallDistance");
    this.highestPosition = this.y + this.namedTag.getFloat("FallDistance");

    if (!this.namedTag.contains("Fire") || this.namedTag.getShort("Fire") > 32767) {
        this.namedTag.putShort("Fire", 0);
    }
    this.fireTicks = this.namedTag.getShort("Fire");

    if (!this.namedTag.contains("Air")) {
        this.namedTag.putShort("Air", 300);
    }
    this.setDataProperty(new ShortEntityData(DATA_AIR, this.namedTag.getShort("Air")), false);

    if (!this.namedTag.contains("OnGround")) {
        this.namedTag.putBoolean("OnGround", false);
    }
    this.onGround = this.namedTag.getBoolean("OnGround");

    if (!this.namedTag.contains("Invulnerable")) {
        this.namedTag.putBoolean("Invulnerable", false);
    }
    this.invulnerable = this.namedTag.getBoolean("Invulnerable");

    if (!this.namedTag.contains("Scale")) {
        this.namedTag.putFloat("Scale", 1);
    }
    this.scale = this.namedTag.getFloat("Scale");
    this.setDataProperty(new FloatEntityData(DATA_SCALE, scale), false);

    this.chunk.addEntity(this);
    this.level.addEntity(this);

    this.initEntity();

    this.lastUpdate = this.server.getTick();
    this.server.getPluginManager().callEvent(new EntitySpawnEvent(this));

    this.scheduleUpdate();
}
 
Example #28
Source File: EntityRabbit.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public EntityRabbit(FullChunk chunk, CompoundTag nbt) {
    super(chunk, nbt);
}
 
Example #29
Source File: EntityHuman.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public EntityHuman(FullChunk chunk, CompoundTag nbt) {
    super(chunk, nbt);
}
 
Example #30
Source File: BlockEntitySign.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public BlockEntitySign(FullChunk chunk, CompoundTag nbt) {
    super(chunk, nbt);
}