Search in sources :

Example 1 with BlockPistonChangeEvent

use of cn.nukkit.event.block.BlockPistonChangeEvent 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)

Aggregations

BlockEntity (cn.nukkit.blockentity.BlockEntity)1 BlockEntityPistonArm (cn.nukkit.blockentity.BlockEntityPistonArm)1 BlockPistonChangeEvent (cn.nukkit.event.block.BlockPistonChangeEvent)1