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;
}
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;
}
Aggregations