use of cn.nukkit.math.BlockFace 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.math.BlockFace in project Nukkit by Nukkit.
the class BlockLever method onUpdate.
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_NORMAL) {
int face = this.isPowerOn() ? this.getDamage() ^ 0x08 : this.getDamage();
BlockFace faces = LeverOrientation.byMetadata(face).getFacing().getOpposite();
if (!this.getSide(faces).isSolid()) {
this.level.useBreakOn(this);
}
}
return 0;
}
use of cn.nukkit.math.BlockFace in project Nukkit by Nukkit.
the class BlockLiquid method checkForHarden.
private void checkForHarden() {
if (this instanceof BlockLava) {
boolean colliding = false;
for (BlockFace face : BlockFace.values()) {
if (colliding = this.getSide(face) instanceof BlockWater) {
break;
}
}
if (colliding) {
Block to;
if (this.getDamage() == 0) {
to = new BlockObsidian();
} else if (this.getDamage() <= 4) {
to = new BlockCobblestone();
} else {
return;
}
to.setComponents(this.getX(), this.getY(), this.getZ());
to.setLevel(this.getLevel());
BlockFromToEvent ev = new BlockFromToEvent(this, to);
this.getLevel().getServer().getPluginManager().callEvent(ev);
if (!ev.isCancelled()) {
this.getLevel().setBlock(this, ev.getTo(), true);
this.triggerLavaMixEffects(this);
}
}
}
}
use of cn.nukkit.math.BlockFace in project Nukkit by Nukkit.
the class BlockPistonBase method doMove.
private boolean doMove(boolean extending) {
Vector3 pos = this.getLocation();
BlockFace direction = getFacing();
if (!extending) {
this.level.setBlock(pos.getSide(direction), new BlockAir(), true, false);
}
BlocksCalculator calculator = new BlocksCalculator(this.level, this, direction, extending);
if (!calculator.canMove()) {
return false;
} else {
List<Block> blocks = calculator.getBlocksToMove();
List<Block> newBlocks = new ArrayList<>();
for (int i = 0; i < blocks.size(); ++i) {
Block block = blocks.get(i);
newBlocks.add(block);
}
List<Block> destroyBlocks = calculator.getBlocksToDestroy();
BlockFace side = extending ? direction : direction.getOpposite();
for (int i = destroyBlocks.size() - 1; i >= 0; --i) {
Block block = destroyBlocks.get(i);
this.level.useBreakOn(block);
}
for (int i = blocks.size() - 1; i >= 0; --i) {
Block block = blocks.get(i);
this.level.setBlock(block, new BlockAir());
Vector3 newPos = block.getLocation().getSide(side);
// TODO: change this to block entity
this.level.setBlock(newPos, newBlocks.get(i));
}
Vector3 pistonHead = pos.getSide(direction);
if (extending) {
// extension block entity
this.level.setBlock(pistonHead, new BlockPistonHead(this.getDamage()));
}
return true;
}
}
use of cn.nukkit.math.BlockFace in project Nukkit by Nukkit.
the class BlockPistonBase method checkState.
private void checkState() {
BlockFace facing = getFacing();
boolean isPowered = this.isPowered();
if (isPowered && !isExtended()) {
if ((new BlocksCalculator(this.level, this, facing, true)).canMove()) {
if (!this.doMove(true)) {
return;
}
this.level.addSound(this, Sound.TILE_PISTON_OUT);
} else {
}
} else if (!isPowered && isExtended()) {
if (this.sticky) {
Vector3 pos = this.add(facing.getXOffset() * 2, facing.getYOffset() * 2, facing.getZOffset() * 2);
Block block = this.level.getBlock(pos);
if (block.getId() == AIR) {
this.level.setBlock(this.getLocation().getSide(facing), new BlockAir(), true, true);
}
if (canPush(block, facing.getOpposite(), false) && (!(block instanceof BlockFlowable) || block.getId() == PISTON || block.getId() == STICKY_PISTON)) {
this.doMove(false);
}
} else {
this.level.setBlock(getLocation().getSide(facing), new BlockAir(), true, false);
}
this.level.addSound(this, Sound.TILE_PISTON_IN);
}
}
Aggregations