Search in sources :

Example 1 with BlockEntityPistonArm

use of cn.nukkit.blockentity.BlockEntityPistonArm in project Nukkit by Nukkit.

the class BlockPistonBase method onUpdate.

@Override
public int onUpdate(int type) {
    if (type != 6 && type != 1) {
        return 0;
    } else {
        BlockEntity blockEntity = this.level.getBlockEntity(this);
        if (blockEntity instanceof BlockEntityPistonArm) {
            BlockEntityPistonArm arm = (BlockEntityPistonArm) blockEntity;
            boolean powered = this.isPowered();
            if (arm.powered != powered) {
                this.level.getServer().getPluginManager().callEvent(new BlockPistonChangeEvent(this, powered ? 0 : 15, powered ? 15 : 0));
                arm.powered = !arm.powered;
                if (arm.chunk != null) {
                    arm.chunk.setChanged();
                }
            }
        }
        return type;
    }
}
Also used : BlockEntityPistonArm(cn.nukkit.blockentity.BlockEntityPistonArm) BlockPistonChangeEvent(cn.nukkit.event.block.BlockPistonChangeEvent) BlockEntity(cn.nukkit.blockentity.BlockEntity)

Example 2 with BlockEntityPistonArm

use of cn.nukkit.blockentity.BlockEntityPistonArm in project Nukkit by Nukkit.

the class BlockPistonBase method place.

@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
    if (Math.abs(player.x - this.x) < 2 && Math.abs(player.z - this.z) < 2) {
        double y = player.y + player.getEyeHeight();
        if (y - this.y > 2) {
            this.setDamage(BlockFace.UP.getIndex());
        } else if (this.y - y > 0) {
            this.setDamage(BlockFace.DOWN.getIndex());
        } else {
            this.setDamage(player.getHorizontalFacing().getIndex());
        }
    } else {
        this.setDamage(player.getHorizontalFacing().getIndex());
    }
    this.level.setBlock(block, this, true, false);
    CompoundTag nbt = new CompoundTag("").putString("id", BlockEntity.PISTON_ARM).putInt("x", (int) this.x).putInt("y", (int) this.y).putInt("z", (int) this.z).putBoolean("Sticky", this.sticky);
    BlockEntityPistonArm be = new BlockEntityPistonArm(this.level.getChunk((int) this.x >> 4, (int) this.z >> 4), nbt);
    // this.checkState();
    return true;
}
Also used : BlockEntityPistonArm(cn.nukkit.blockentity.BlockEntityPistonArm) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Aggregations

BlockEntityPistonArm (cn.nukkit.blockentity.BlockEntityPistonArm)2 BlockEntity (cn.nukkit.blockentity.BlockEntity)1 BlockPistonChangeEvent (cn.nukkit.event.block.BlockPistonChangeEvent)1 CompoundTag (cn.nukkit.nbt.tag.CompoundTag)1