Java Code Examples for cn.nukkit.block.Block#isSolid()

The following examples show how to use cn.nukkit.block.Block#isSolid() . 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: Entity.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public boolean isInsideOfSolid() {
    double y = this.y + this.getEyeHeight();
    Block block = this.level.getBlock(
            this.temporalVector.setComponents(
                    NukkitMath.floorDouble(this.x),
                    NukkitMath.floorDouble(y),
                    NukkitMath.floorDouble(this.z))
    );

    AxisAlignedBB bb = block.getBoundingBox();

    return bb != null && block.isSolid() && !block.isTransparent() && bb.intersectsWith(this.getBoundingBox());

}
 
Example 2
Source File: PopulatorGroundCover.java    From Jupiter 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 = level.getChunk(chunkX, chunkZ);
    for (int x = 0; x < 16; ++x) {
        for (int z = 0; z < 16; ++z) {
            Biome biome = Biome.getBiome(chunk.getBiomeId(x, z));
            Block[] cover = biome.getGroundCover();
            if (cover != null && cover.length > 0) {
                int diffY = 0;
                if (!cover[0].isSolid()) {
                    diffY = 1;
                }

                byte[] column = chunk.getBlockIdColumn(x, z);
                int y;
                for (y = 127; y > 0; --y) {
                    if (column[y] != 0x00 && !Block.get(column[y] & 0xff).isTransparent()) {
                        break;
                    }
                }
                int startY = Math.min(127, y + diffY);
                int endY = startY - cover.length;
                for (y = startY; y > endY && y >= 0; --y) {
                    Block b = cover[startY - y];
                    if (column[y] == 0x00 && b.isSolid()) {
                        break;
                    }
                    if (b.getDamage() == 0) {
                        chunk.setBlockId(x, y, z, b.getId());
                    } else {
                        chunk.setBlock(x, y, z, b.getId(), b.getDamage());
                    }
                }
            }
        }
    }
}
 
Example 3
Source File: Entity.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public boolean isInsideOfSolid() {
    double y = this.y + this.getEyeHeight();
    Block block = this.level.getBlock(
            this.temporalVector.setComponents(
                    NukkitMath.floorDouble(this.x),
                    NukkitMath.floorDouble(y),
                    NukkitMath.floorDouble(this.z))
    );

    AxisAlignedBB bb = block.getBoundingBox();

    return bb != null && block.isSolid() && !block.isTransparent() && bb.intersectsWith(this.getBoundingBox());

}
 
Example 4
Source File: ItemPainting.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
    FullChunk chunk = level.getChunk((int) block.getX() >> 4, (int) block.getZ() >> 4);

    if (chunk == null) {
        return false;
    }

    if (!target.isTransparent() && face.getIndex() > 1 && !block.isSolid()) {
        int[] direction = {2, 0, 1, 3};
        int[] right = {4, 5, 3, 2};

        List<EntityPainting.Motive> validMotives = new ArrayList<>();
        for (EntityPainting.Motive motive : EntityPainting.motives) {
            boolean valid = true;
            for (int x = 0; x < motive.width && valid; x++) {
                for (int z = 0; z < motive.height && valid; z++) {
                    if (target.getSide(BlockFace.fromIndex(right[face.getIndex() - 2]), x).isTransparent() ||
                            target.up(z).isTransparent() ||
                            block.getSide(BlockFace.fromIndex(right[face.getIndex() - 2]), x).isSolid() ||
                            block.up(z).isSolid()) {
                        valid = false;
                    }
                }
            }

            if (valid) {
                validMotives.add(motive);
            }
        }

        CompoundTag nbt = new CompoundTag()
                .putByte("Direction", direction[face.getIndex() - 2])
                .putString("Motive", validMotives.get(ThreadLocalRandom.current().nextInt(validMotives.size())).title)
                .putList(new ListTag<DoubleTag>("Pos")
                        .add(new DoubleTag("0", target.x))
                        .add(new DoubleTag("1", target.y))
                        .add(new DoubleTag("2", target.z)))
                .putList(new ListTag<DoubleTag>("Motion")
                        .add(new DoubleTag("0", 0))
                        .add(new DoubleTag("1", 0))
                        .add(new DoubleTag("2", 0)))
                .putList(new ListTag<FloatTag>("Rotation")
                        .add(new FloatTag("0", direction[face.getIndex() - 2] * 90))
                        .add(new FloatTag("1", 0)));

        EntityPainting entity = new EntityPainting(chunk, nbt);

        if (player.isSurvival()) {
            Item item = player.getInventory().getItemInHand();
            item.setCount(item.getCount() - 1);
            player.getInventory().setItemInHand(item);
        }
        entity.spawnToAll();

        return true;
    }

    return false;
}
 
Example 5
Source File: BlockEntityMobSpawner.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onUpdate() {
    if (this.closed) {
        return false;
    }

    this.timing.startTiming();

    if (!(this.chunk instanceof Chunk)) {
        return false;
    }

    if (!(this.canUpdate())) {
        return false;
    }

    if (this.namedTag.getInt("Delay") <= 0) {
        int success = 0;
        NukkitRandom random = new NukkitRandom();
        for (int i = 0; i < this.namedTag.getInt("SpawnCount"); ++i) {
            Vector3 pos = this.add(
                    this.getRandomSpawn(), 
                    NukkitMath.randomRange(random, -1, 1), 
                    this.getRandomSpawn());
            Block target = this.getLevel().getBlock(pos);
            Block ground = target.down();
            if (target.getId() == Block.AIR && ground.isSolid()) {
                ++success;
                CompoundTag nbt = new CompoundTag()
                        .putList(new ListTag<DoubleTag>("Pos")
                                .add(new DoubleTag("", pos.x))
                                .add(new DoubleTag("", pos.y))
                                .add(new DoubleTag("", pos.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("", (float) Math.random() * 360))
                                .add(new FloatTag("", (float) 0)));

                Entity entity = Entity.createEntity(this.getNetworkId(), this.chunk, nbt);
                entity.spawnToAll();
            }
        }

        if (success > 0) {
            this.namedTag.putInt("Delay", NukkitMath.randomRange(random, this.namedTag.getInt("MinSpawnDelay"), this.namedTag.getInt("MaxSpawnDelay")));
        }

    } else {
        this.namedTag.putInt("Delay", this.namedTag.getInt("Delay") - 1);
    }

    this.timing.stopTiming();

    return true;
}
 
Example 6
Source File: FoodChorusFruit.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected boolean onEatenBy(Player player) {
    super.onEatenBy(player);
    // Teleportation
    int minX = player.getFloorX() - 8;
    int minY = player.getFloorY() - 8;
    int minZ = player.getFloorZ() - 8;
    int maxX = minX + 16;
    int maxY = minY + 16;
    int maxZ = minZ + 16;

    Level level = player.getLevel();
    if (level == null) return false;

    NukkitRandom random = new NukkitRandom();
    for (int attempts = 0; attempts < 128; attempts++) {
        int x = random.nextRange(minX, maxX);
        int y = random.nextRange(minY, maxY);
        int z = random.nextRange(minZ, maxZ);

        if (y < 0) continue;

        while (y >= 0 && !level.getBlock(new Vector3(x, y + 1, z)).isSolid()) {
            y--;
        }
        y++; // Back up to non solid

        Block blockUp = level.getBlock(new Vector3(x, y + 1, z));
        Block blockUp2 = level.getBlock(new Vector3(x, y + 2, z));

        if (blockUp.isSolid() || blockUp instanceof BlockLiquid ||
                blockUp2.isSolid() || blockUp2 instanceof BlockLiquid) {
            continue;
        }

        // Sounds are broadcast at both source and destination
        level.addSound(player.asBlockVector3().asVector3(), Sound.MOB_ENDERMEN_PORTAL);
        player.teleport(new Vector3(x + 0.5, y + 1, z + 0.5), PlayerTeleportEvent.TeleportCause.CHORUS_FRUIT);
        level.addSound(player.asBlockVector3().asVector3(), Sound.MOB_ENDERMEN_PORTAL);

        break;
    }

    return true;
}
 
Example 7
Source File: ItemPainting.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
    FullChunk chunk = level.getChunk((int) block.getX() >> 4, (int) block.getZ() >> 4);

    if (chunk == null) {
        return false;
    }

    if (!target.isTransparent() && face.getIndex() > 1 && !block.isSolid()) {
        int[] direction = {2, 0, 1, 3};
        int[] right = {4, 5, 3, 2};

        List<EntityPainting.Motive> validMotives = new ArrayList<>();
        for (EntityPainting.Motive motive : EntityPainting.motives) {
            boolean valid = true;
            for (int x = 0; x < motive.width && valid; x++) {
                for (int z = 0; z < motive.height && valid; z++) {
                    if (target.getSide(BlockFace.fromIndex(right[face.getIndex() - 2]), x).isTransparent() ||
                            target.up(z).isTransparent() ||
                            block.getSide(BlockFace.fromIndex(right[face.getIndex() - 2]), x).isSolid() ||
                            block.up(z).isSolid()) {
                        valid = false;
                    }
                }
            }

            if (valid) {
                validMotives.add(motive);
            }
        }

        CompoundTag nbt = new CompoundTag()
                .putByte("Direction", direction[face.getIndex() - 2])
                .putString("Motive", validMotives.get(ThreadLocalRandom.current().nextInt(validMotives.size())).title)
                .putList(new ListTag<DoubleTag>("Pos")
                        .add(new DoubleTag("0", target.x))
                        .add(new DoubleTag("1", target.y))
                        .add(new DoubleTag("2", target.z)))
                .putList(new ListTag<DoubleTag>("Motion")
                        .add(new DoubleTag("0", 0))
                        .add(new DoubleTag("1", 0))
                        .add(new DoubleTag("2", 0)))
                .putList(new ListTag<FloatTag>("Rotation")
                        .add(new FloatTag("0", direction[face.getIndex() - 2] * 90))
                        .add(new FloatTag("1", 0)));

        EntityPainting entity = new EntityPainting(chunk, nbt);

        if (player.isSurvival()) {
            Item item = player.getInventory().getItemInHand();
            item.setCount(item.getCount() - 1);
            player.getInventory().setItemInHand(item);
        }
        entity.spawnToAll();

        return true;
    }

    return false;
}
 
Example 8
Source File: PopulatorGroundCover.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random) {
    FullChunk chunk = level.getChunk(chunkX, chunkZ);
    for (int x = 0; x < 16; ++x) {
        for (int z = 0; z < 16; ++z) {
            Biome biome = Biome.getBiome(chunk.getBiomeId(x, z));
            Block[] cover = biome.getGroundCover();
            if (cover != null && cover.length > 0) {
                int diffY = 0;
                if (!cover[0].isSolid()) {
                    diffY = 1;
                }

                int height = chunk.getHeightMap(x, z);
                if (height == 0 || height == 255) height = 126;

                int y;
                for (y = height + 1; y > 0; --y) {
                    int fullId = chunk.getFullBlock(x, y, z);
                    if (fullId != 0 && !Block.get(fullId >> 4).isTransparent()) {
                        break;
                    }
                }
                int startY = Math.min(127, y + diffY);
                int endY = startY - cover.length;
                for (y = startY; y > endY && y >= 0; --y) {
                    Block b = cover[startY - y];
                    int blockId = chunk.getBlockId(x, y, z);
                    if (blockId == 0 && b.isSolid()) {
                        break;
                    }
                    if (b.getDamage() == 0) {
                        chunk.setBlockId(x, y, z, b.getId());
                    } else {
                        chunk.setBlock(x, y, z, b.getId(), b.getDamage());
                    }
                }
            }
        }
    }
}