Search in sources :

Example 1 with BlockRedstoneEvent

use of cn.nukkit.event.block.BlockRedstoneEvent in project Nukkit by Nukkit.

the class BlockDoor method onUpdate.

@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_NORMAL) {
        if (this.down().getId() == AIR) {
            Block up = this.up();
            if (up instanceof BlockDoor) {
                this.getLevel().setBlock(up, new BlockAir(), false);
                this.getLevel().useBreakOn(this);
            }
            return Level.BLOCK_UPDATE_NORMAL;
        }
    }
    if (type == Level.BLOCK_UPDATE_REDSTONE) {
        if ((!isOpen() && this.level.isBlockPowered(this)) || (isOpen() && !this.level.isBlockPowered(this))) {
            this.level.getServer().getPluginManager().callEvent(new BlockRedstoneEvent(this, isOpen() ? 15 : 0, isOpen() ? 0 : 15));
            this.toggle(null);
        }
    }
    return 0;
}
Also used : BlockRedstoneEvent(cn.nukkit.event.block.BlockRedstoneEvent)

Example 2 with BlockRedstoneEvent

use of cn.nukkit.event.block.BlockRedstoneEvent in project Nukkit by Nukkit.

the class BlockLever method onActivate.

@Override
public boolean onActivate(Item item, Player player) {
    this.level.getServer().getPluginManager().callEvent(new BlockRedstoneEvent(this, isPowerOn() ? 15 : 0, isPowerOn() ? 0 : 15));
    this.setDamage(this.getDamage() ^ 0x08);
    this.getLevel().setBlock(this, this, false, true);
    // TODO: coorect pitcj
    this.getLevel().addSound(this, Sound.RANDOM_CLICK);
    LeverOrientation orientation = LeverOrientation.byMetadata(this.isPowerOn() ? this.getDamage() ^ 0x08 : this.getDamage());
    BlockFace face = orientation.getFacing();
    // this.level.updateAroundRedstone(this, null);
    this.level.updateAroundRedstone(this.getLocation().getSide(face.getOpposite()), isPowerOn() ? face : null);
    return true;
}
Also used : BlockFace(cn.nukkit.math.BlockFace) BlockRedstoneEvent(cn.nukkit.event.block.BlockRedstoneEvent)

Example 3 with BlockRedstoneEvent

use of cn.nukkit.event.block.BlockRedstoneEvent in project Nukkit by Nukkit.

the class BlockPressurePlateBase method updateState.

protected void updateState(int oldStrength) {
    int strength = this.computeRedstoneStrength();
    boolean wasPowered = oldStrength > 0;
    boolean isPowered = strength > 0;
    if (oldStrength != strength) {
        this.setRedstonePower(strength);
        this.level.setBlock(this, this, false, false);
        this.level.updateAroundRedstone(this, null);
        this.level.updateAroundRedstone(this.getLocation().down(), null);
        if (!isPowered && wasPowered) {
            this.playOffSound();
            this.level.getServer().getPluginManager().callEvent(new BlockRedstoneEvent(this, 15, 0));
        } else if (isPowered && !wasPowered) {
            this.playOnSound();
            this.level.getServer().getPluginManager().callEvent(new BlockRedstoneEvent(this, 0, 15));
        }
    }
    if (isPowered) {
        this.level.scheduleUpdate(this, 20);
    }
}
Also used : BlockRedstoneEvent(cn.nukkit.event.block.BlockRedstoneEvent)

Example 4 with BlockRedstoneEvent

use of cn.nukkit.event.block.BlockRedstoneEvent in project Nukkit by Nukkit.

the class BlockTripWireHook method addSound.

private void addSound(Vector3 pos, boolean canConnect, boolean nextPowered, boolean attached, boolean powered) {
    if (nextPowered && !powered) {
        this.level.addLevelSoundEvent(pos, LevelSoundEventPacket.SOUND_POWER_ON, 1, -1);
        this.level.getServer().getPluginManager().callEvent(new BlockRedstoneEvent(this, 0, 15));
    } else if (!nextPowered && powered) {
        this.level.addLevelSoundEvent(pos, LevelSoundEventPacket.SOUND_POWER_OFF, 1, -1);
        this.level.getServer().getPluginManager().callEvent(new BlockRedstoneEvent(this, 15, 0));
    } else if (canConnect && !attached) {
        this.level.addLevelSoundEvent(pos, LevelSoundEventPacket.SOUND_ATTACH, 1, -1);
    } else if (!canConnect && attached) {
        this.level.addLevelSoundEvent(pos, LevelSoundEventPacket.SOUND_DETACH, 1, -1);
    }
}
Also used : BlockRedstoneEvent(cn.nukkit.event.block.BlockRedstoneEvent)

Example 5 with BlockRedstoneEvent

use of cn.nukkit.event.block.BlockRedstoneEvent in project Nukkit by Nukkit.

the class BlockTrapdoor method onUpdate.

@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_REDSTONE || type == Level.BLOCK_UPDATE_NORMAL) {
        if ((!isOpen() && this.level.isBlockPowered(this)) || (isOpen() && !this.level.isBlockPowered(this))) {
            this.level.getServer().getPluginManager().callEvent(new BlockRedstoneEvent(this, isOpen() ? 15 : 0, isOpen() ? 0 : 15));
            this.toggle(null);
            return type;
        }
    }
    return 0;
}
Also used : BlockRedstoneEvent(cn.nukkit.event.block.BlockRedstoneEvent)

Aggregations

BlockRedstoneEvent (cn.nukkit.event.block.BlockRedstoneEvent)7 BlockFace (cn.nukkit.math.BlockFace)2 Vector3 (cn.nukkit.math.Vector3)2