Search in sources :

Example 1 with BlockWater

use of cn.nukkit.block.BlockWater in project Nukkit by Nukkit.

the class ItemBucket method onActivate.

@Override
public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
    Block targetBlock = Block.get(this.meta);
    if (targetBlock instanceof BlockAir) {
        if (target instanceof BlockLiquid && target.getDamage() == 0) {
            Item result = Item.get(BUCKET, this.getDamageByTarget(target.getId()), 1);
            PlayerBucketFillEvent ev;
            player.getServer().getPluginManager().callEvent(ev = new PlayerBucketFillEvent(player, block, face, this, result));
            if (!ev.isCancelled()) {
                player.getLevel().setBlock(target, new BlockAir(), true, true);
                // replaced with water that can flow.
                for (BlockFace side : Plane.HORIZONTAL) {
                    Block b = target.getSide(side);
                    if (b.getId() == STILL_WATER) {
                        level.setBlock(b, new BlockWater());
                    }
                }
                if (player.isSurvival()) {
                    Item clone = this.clone();
                    clone.setCount(this.getCount() - 1);
                    player.getInventory().setItemInHand(clone);
                    player.getInventory().addItem(ev.getItem());
                }
                return true;
            } else {
                player.getInventory().sendContents(player);
            }
        }
    } else if (targetBlock instanceof BlockLiquid) {
        Item result = Item.get(BUCKET, 0, 1);
        PlayerBucketEmptyEvent ev;
        player.getServer().getPluginManager().callEvent(ev = new PlayerBucketEmptyEvent(player, block, face, this, result));
        if (!ev.isCancelled()) {
            player.getLevel().setBlock(block, targetBlock, true, true);
            if (player.isSurvival()) {
                Item clone = this.clone();
                clone.setCount(this.getCount() - 1);
                player.getInventory().setItemInHand(clone);
                player.getInventory().addItem(ev.getItem());
            }
            return true;
        } else {
            player.getInventory().sendContents(player);
        }
    }
    return false;
}
Also used : BlockAir(cn.nukkit.block.BlockAir) PlayerBucketFillEvent(cn.nukkit.event.player.PlayerBucketFillEvent) BlockLiquid(cn.nukkit.block.BlockLiquid) BlockFace(cn.nukkit.math.BlockFace) Block(cn.nukkit.block.Block) BlockWater(cn.nukkit.block.BlockWater) PlayerBucketEmptyEvent(cn.nukkit.event.player.PlayerBucketEmptyEvent)

Example 2 with BlockWater

use of cn.nukkit.block.BlockWater in project Nukkit by Nukkit.

the class Entity method isInsideOfWater.

public boolean isInsideOfWater() {
    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)));
    if (block instanceof BlockWater) {
        double f = (block.y + 1) - (((BlockWater) block).getFluidHeightPercent() - 0.1111111);
        return y < f;
    }
    return false;
}
Also used : Block(cn.nukkit.block.Block) BlockWater(cn.nukkit.block.BlockWater)

Aggregations

Block (cn.nukkit.block.Block)2 BlockWater (cn.nukkit.block.BlockWater)2 BlockAir (cn.nukkit.block.BlockAir)1 BlockLiquid (cn.nukkit.block.BlockLiquid)1 PlayerBucketEmptyEvent (cn.nukkit.event.player.PlayerBucketEmptyEvent)1 PlayerBucketFillEvent (cn.nukkit.event.player.PlayerBucketFillEvent)1 BlockFace (cn.nukkit.math.BlockFace)1