Search in sources :

Example 6 with BlockRedstoneEvent

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

the class BlockRedstoneWire method calculateCurrentChanges.

private void calculateCurrentChanges(boolean force) {
    Vector3 pos = this.getLocation();
    int meta = this.getDamage();
    int maxStrength = meta;
    this.canProvidePower = false;
    int power = this.getIndirectPower();
    this.canProvidePower = true;
    if (power > 0 && power > maxStrength - 1) {
        maxStrength = power;
    }
    int strength = 0;
    for (BlockFace face : Plane.HORIZONTAL) {
        Vector3 v = pos.getSide(face);
        boolean flag = v.getX() != this.getX() || v.getZ() != this.getZ();
        if (flag) {
            strength = this.getMaxCurrentStrength(v, strength);
        }
        if (this.level.getBlock(v).isNormalBlock() && !this.level.getBlock(pos.up()).isNormalBlock()) {
            if (flag) {
                strength = this.getMaxCurrentStrength(v.up(), strength);
            }
        } else if (flag && !this.level.getBlock(v).isNormalBlock()) {
            strength = this.getMaxCurrentStrength(v.down(), strength);
        }
    }
    if (strength > maxStrength) {
        maxStrength = strength - 1;
    } else if (maxStrength > 0) {
        --maxStrength;
    } else {
        maxStrength = 0;
    }
    if (power > maxStrength - 1) {
        maxStrength = power;
    }
    if (meta != maxStrength) {
        this.level.getServer().getPluginManager().callEvent(new BlockRedstoneEvent(this, meta, maxStrength));
        this.setDamage(maxStrength);
        this.level.setBlock(this, this, false, false);
        this.level.updateAroundRedstone(this, null);
        for (BlockFace face : BlockFace.values()) {
            this.level.updateAroundRedstone(pos.getSide(face), face.getOpposite());
        }
    } else if (force) {
        for (BlockFace face : BlockFace.values()) {
            this.level.updateAroundRedstone(pos.getSide(face), face.getOpposite());
        }
    }
}
Also used : BlockFace(cn.nukkit.math.BlockFace) Vector3(cn.nukkit.math.Vector3) BlockRedstoneEvent(cn.nukkit.event.block.BlockRedstoneEvent)

Example 7 with BlockRedstoneEvent

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

the class BlockButton method onActivate.

@Override
public boolean onActivate(Item item, Player player) {
    if (this.isActivated()) {
        return false;
    }
    this.level.getServer().getPluginManager().callEvent(new BlockRedstoneEvent(this, 0, 15));
    this.setDamage(this.getDamage() ^ 0x08);
    this.level.setBlock(this, this, true, false);
    this.level.addSound(this.add(0.5, 0.5, 0.5), Sound.RANDOM_CLICK);
    this.level.scheduleUpdate(this, 30);
    Vector3 pos = getLocation();
    level.updateAroundRedstone(pos, null);
    level.updateAroundRedstone(pos.getSide(getFacing().getOpposite()), null);
    return true;
}
Also used : BlockRedstoneEvent(cn.nukkit.event.block.BlockRedstoneEvent) Vector3(cn.nukkit.math.Vector3)

Aggregations

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