Search in sources :

Example 16 with BlockFace

use of cn.nukkit.math.BlockFace in project Nukkit by Nukkit.

the class BlockRedstoneDiode method calculateInputStrength.

protected int calculateInputStrength() {
    BlockFace face = getFacing();
    Vector3 pos = this.getLocation().getSide(face);
    int power = this.level.getRedstonePower(pos, face);
    if (power >= 15) {
        return power;
    } else {
        Block block = this.level.getBlock(pos);
        return Math.max(power, block.getId() == Block.REDSTONE_WIRE ? block.getDamage() : 0);
    }
}
Also used : BlockFace(cn.nukkit.math.BlockFace) Vector3(cn.nukkit.math.Vector3)

Example 17 with BlockFace

use of cn.nukkit.math.BlockFace in project Nukkit by Nukkit.

the class BlockRedstoneDiode method isFacingTowardsRepeater.

public boolean isFacingTowardsRepeater() {
    BlockFace side = getFacing().getOpposite();
    Block block = this.getSide(side);
    return block instanceof BlockRedstoneDiode && ((BlockRedstoneDiode) block).getFacing() != side;
}
Also used : BlockFace(cn.nukkit.math.BlockFace)

Example 18 with BlockFace

use of cn.nukkit.math.BlockFace in project Nukkit by Nukkit.

the class BlockRedstoneWire method onBreak.

@Override
public boolean onBreak(Item item) {
    this.getLevel().setBlock(this, new BlockAir(), true, true);
    Vector3 pos = getLocation();
    this.updateSurroundingRedstone(false);
    for (BlockFace blockFace : BlockFace.values()) {
        this.level.updateAroundRedstone(pos.getSide(blockFace), null);
    }
    for (BlockFace blockFace : Plane.HORIZONTAL) {
        Vector3 v = pos.getSide(blockFace);
        if (this.level.getBlock(v).isNormalBlock()) {
            this.updateAround(v.up(), BlockFace.DOWN);
        } else {
            this.updateAround(v.down(), BlockFace.UP);
        }
    }
    return true;
}
Also used : BlockFace(cn.nukkit.math.BlockFace) Vector3(cn.nukkit.math.Vector3)

Example 19 with BlockFace

use of cn.nukkit.math.BlockFace 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 20 with BlockFace

use of cn.nukkit.math.BlockFace in project Nukkit by Nukkit.

the class BlockTrapdoor method place.

@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
    BlockFace facing;
    boolean top;
    if (face.getAxis().isHorizontal() || player == null) {
        facing = face;
        top = fy > 0.5;
    } else {
        facing = player.getDirection().getOpposite();
        top = face != BlockFace.UP;
    }
    int[] faces = { 2, 1, 3, 0 };
    int faceBit = faces[facing.getHorizontalIndex()];
    this.setDamage(this.getDamage() | faceBit);
    if (top) {
        this.setDamage(this.getDamage() | 0x04);
    }
    this.getLevel().setBlock(block, this, true, true);
    return true;
}
Also used : BlockFace(cn.nukkit.math.BlockFace)

Aggregations

BlockFace (cn.nukkit.math.BlockFace)29 Vector3 (cn.nukkit.math.Vector3)16 CompoundTag (cn.nukkit.nbt.tag.CompoundTag)3 BlockRedstoneEvent (cn.nukkit.event.block.BlockRedstoneEvent)2 Player (cn.nukkit.Player)1 Block (cn.nukkit.block.Block)1 BlockAir (cn.nukkit.block.BlockAir)1 BlockLiquid (cn.nukkit.block.BlockLiquid)1 BlockWater (cn.nukkit.block.BlockWater)1 BlockEntity (cn.nukkit.blockentity.BlockEntity)1 BlockEntityChest (cn.nukkit.blockentity.BlockEntityChest)1 BlockEntityHopper (cn.nukkit.blockentity.BlockEntityHopper)1 Entity (cn.nukkit.entity.Entity)1 BlockFromToEvent (cn.nukkit.event.block.BlockFromToEvent)1 PlayerBucketEmptyEvent (cn.nukkit.event.player.PlayerBucketEmptyEvent)1 PlayerBucketFillEvent (cn.nukkit.event.player.PlayerBucketFillEvent)1 Item (cn.nukkit.item.Item)1 ItemTool (cn.nukkit.item.ItemTool)1 Level (cn.nukkit.level.Level)1 Position (cn.nukkit.level.Position)1