use of cn.nukkit.block.BlockLiquid 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;
}
Aggregations