Java Code Examples for cn.nukkit.math.Vector3#getSide()

The following examples show how to use cn.nukkit.math.Vector3#getSide() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Level.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public void updateComparatorOutputLevel(Vector3 v) {
    for (BlockFace face : Plane.HORIZONTAL) {
        Vector3 pos = v.getSide(face);

        if (this.isChunkLoaded((int) pos.x >> 4, (int) pos.z >> 4)) {
            Block block1 = this.getBlock(pos);

            if (BlockRedstoneDiode.isDiode(block1)) {
                block1.onUpdate(BLOCK_UPDATE_REDSTONE);
            } else if (block1.isNormalBlock()) {
                pos = pos.getSide(face);
                block1 = this.getBlock(pos);

                if (BlockRedstoneDiode.isDiode(block1)) {
                    block1.onUpdate(BLOCK_UPDATE_REDSTONE);
                }
            }
        }
    }
}
 
Example 2
Source File: BlockRedstoneWire.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
private boolean isPowerSourceAt(BlockFace side) {
    Vector3 pos = getLocation();
    Vector3 v = pos.getSide(side);
    Block block = this.level.getBlock(v);
    boolean flag = block.isNormalBlock();
    boolean flag1 = this.level.getBlock(pos.up()).isNormalBlock();
    return !flag1 && flag && canConnectUpwardsTo(this.level, v.up()) || (canConnectTo(block, side) || !flag && canConnectUpwardsTo(this.level, block.down()));
}
 
Example 3
Source File: BlockRedstoneWire.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
private boolean isPowerSourceAt(BlockFace side) {
    Vector3 pos = getLocation();
    Vector3 v = pos.getSide(side);
    Block block = this.level.getBlock(v);
    boolean flag = block.isNormalBlock();
    boolean flag1 = this.level.getBlock(pos.up()).isNormalBlock();
    return !flag1 && flag && canConnectUpwardsTo(this.level, v.up()) || (canConnectTo(block, side) || !flag && canConnectUpwardsTo(this.level, block.down()));
}
 
Example 4
Source File: BlockRedstoneWire.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
private boolean isPowerSourceAt(BlockFace side) {
    Vector3 pos = getLocation();
    Vector3 v = pos.getSide(side);
    Block block = this.level.getBlock(v);
    boolean flag = block.isNormalBlock();
    boolean flag1 = this.level.getBlock(pos.up()).isNormalBlock();
    return !flag1 && flag && canConnectUpwardsTo(this.level, v.up()) || (canConnectTo(block, side) || !flag && canConnectUpwardsTo(this.level, block.down()));
}
 
Example 5
Source File: BlockTripWireHook.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public void calculateState(boolean onBreak, boolean updateAround, int pos, Block block) {
    BlockFace facing = getFacing();
    Vector3 v = this.getLocation();
    boolean attached = isAttached();
    boolean powered = isPowered();
    boolean canConnect = !onBreak;
    boolean nextPowered = false;
    int distance = 0;
    Block[] blocks = new Block[42];

    for (int i = 1; i < 42; ++i) {
        Vector3 vector = v.getSide(facing, i);
        Block b = this.level.getBlock(vector);

        if (b instanceof BlockTripWireHook) {
            if (((BlockTripWireHook) b).getFacing() == facing.getOpposite()) {
                distance = i;
            }
            break;
        }

        if (b.getId() != Block.TRIPWIRE && i != pos) {
            blocks[i] = null;
            canConnect = false;
        } else {
            if (i == pos) {
                b = block != null ? block : b;
            }

            if (b instanceof BlockTripWire) {
                boolean disarmed = !((BlockTripWire) b).isDisarmed();
                boolean wirePowered = ((BlockTripWire) b).isPowered();
                nextPowered |= disarmed && wirePowered;

                if (i == pos) {
                    this.level.scheduleUpdate(this, 10);
                    canConnect &= disarmed;
                }
            }
            blocks[i] = b;
        }
    }

    canConnect = canConnect & distance > 1;
    nextPowered = nextPowered & canConnect;
    BlockTripWireHook hook = new BlockTripWireHook();
    hook.setAttached(canConnect);
    hook.setPowered(nextPowered);


    if (distance > 0) {
        Vector3 vec = v.getSide(facing, distance);
        BlockFace face = facing.getOpposite();
        hook.setFace(face);
        this.level.setBlock(vec, hook, true, false);
        this.level.updateAroundRedstone(vec, null);
        this.level.updateAroundRedstone(vec.getSide(face.getOpposite()), null);
        this.addSound(vec, canConnect, nextPowered, attached, powered);
    }

    this.addSound(v, canConnect, nextPowered, attached, powered);

    if (!onBreak) {
        hook.setFace(facing);
        this.level.setBlock(v, hook, true, false);

        if (updateAround) {
            this.level.updateAroundRedstone(v, null);
            this.level.updateAroundRedstone(v.getSide(facing.getOpposite()), null);
        }
    }

    if (attached != canConnect) {
        for (int i = 1; i < distance; i++) {
            Vector3 vc = v.getSide(facing, i);
            block = blocks[i];

            if (block != null && this.level.getBlockIdAt(vc.getFloorX(), vc.getFloorY(), vc.getFloorZ()) != Block.AIR) {
                if (canConnect ^ ((block.meta & 0x04) > 0)) {
                    block.meta ^= 0x04;
                }

                this.level.setBlock(vc, block, true, false);
            }
        }
    }
}
 
Example 6
Source File: BlockTripWireHook.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public void calculateState(boolean onBreak, boolean updateAround, int pos, Block block) {
    BlockFace facing = getFacing();
    Vector3 v = this.getLocation();
    boolean attached = isAttached();
    boolean powered = isPowered();
    boolean canConnect = !onBreak;
    boolean nextPowered = false;
    int distance = 0;
    Block[] blocks = new Block[42];

    for (int i = 1; i < 42; ++i) {
        Vector3 vector = v.getSide(facing, i);
        Block b = this.level.getBlock(vector);

        if (b instanceof BlockTripWireHook) {
            if (((BlockTripWireHook) b).getFacing() == facing.getOpposite()) {
                distance = i;
            }
            break;
        }

        if (b.getId() != Block.TRIPWIRE && i != pos) {
            blocks[i] = null;
            canConnect = false;
        } else {
            if (i == pos) {
                b = block != null ? block : b;
            }

            if (b instanceof BlockTripWire) {
                boolean disarmed = !((BlockTripWire) b).isDisarmed();
                boolean wirePowered = ((BlockTripWire) b).isPowered();
                nextPowered |= disarmed && wirePowered;

                if (i == pos) {
                    this.level.scheduleUpdate(this, 10);
                    canConnect &= disarmed;
                }
            }
            blocks[i] = b;
        }
    }

    canConnect = canConnect & distance > 1;
    nextPowered = nextPowered & canConnect;
    BlockTripWireHook hook = (BlockTripWireHook) Block.get(BlockID.TRIPWIRE_HOOK);
    hook.setAttached(canConnect);
    hook.setPowered(nextPowered);


    if (distance > 0) {
        Vector3 vec = v.getSide(facing, distance);
        BlockFace face = facing.getOpposite();
        hook.setFace(face);
        this.level.setBlock(vec, hook, true, false);
        this.level.updateAroundRedstone(vec, null);
        this.level.updateAroundRedstone(vec.getSide(face.getOpposite()), null);
        this.addSound(vec, canConnect, nextPowered, attached, powered);
    }

    this.addSound(v, canConnect, nextPowered, attached, powered);

    if (!onBreak) {
        hook.setFace(facing);
        this.level.setBlock(v, hook, true, false);

        if (updateAround) {
            this.level.updateAroundRedstone(v, null);
            this.level.updateAroundRedstone(v.getSide(facing.getOpposite()), null);
        }
    }

    if (attached != canConnect) {
        for (int i = 1; i < distance; i++) {
            Vector3 vc = v.getSide(facing, i);
            block = blocks[i];

            if (block != null && this.level.getBlockIdAt(vc.getFloorX(), vc.getFloorY(), vc.getFloorZ()) != Block.AIR) {
                if (canConnect ^ ((block.getDamage() & 0x04) > 0)) {
                    block.setDamage(block.getDamage() ^ 0x04);
                }

                this.level.setBlock(vc, block, true, false);
            }
        }
    }
}
 
Example 7
Source File: BlockTripWireHook.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public void calculateState(boolean onBreak, boolean updateAround, int pos, Block block) {
    BlockFace facing = getFacing();
    Vector3 v = this.getLocation();
    boolean attached = isAttached();
    boolean powered = isPowered();
    boolean canConnect = !onBreak;
    boolean nextPowered = false;
    int distance = 0;
    Block[] blocks = new Block[42];

    for (int i = 1; i < 42; ++i) {
        Vector3 vector = v.getSide(facing, i);
        Block b = this.level.getBlock(vector);

        if (b instanceof BlockTripWireHook) {
            if (((BlockTripWireHook) b).getFacing() == facing.getOpposite()) {
                distance = i;
            }
            break;
        }

        if (b.getId() != Block.TRIPWIRE && i != pos) {
            blocks[i] = null;
            canConnect = false;
        } else {
            if (i == pos) {
                b = block != null ? block : b;
            }

            if (b instanceof BlockTripWire) {
                boolean disarmed = !((BlockTripWire) b).isDisarmed();
                boolean wirePowered = ((BlockTripWire) b).isPowered();
                nextPowered |= disarmed && wirePowered;

                if (i == pos) {
                    this.level.scheduleUpdate(this, 10);
                    canConnect &= disarmed;
                }
            }
            blocks[i] = b;
        }
    }

    canConnect = canConnect & distance > 1;
    nextPowered = nextPowered & canConnect;
    BlockTripWireHook hook = new BlockTripWireHook();
    hook.setAttached(canConnect);
    hook.setPowered(nextPowered);


    if (distance > 0) {
        Vector3 vec = v.getSide(facing, distance);
        BlockFace face = facing.getOpposite();
        hook.setFace(face);
        this.level.setBlock(vec, hook, true, false);
        this.level.updateAroundRedstone(vec, null);
        this.level.updateAroundRedstone(vec.getSide(face.getOpposite()), null);
        this.addSound(vec, canConnect, nextPowered, attached, powered);
    }

    this.addSound(v, canConnect, nextPowered, attached, powered);

    if (!onBreak) {
        hook.setFace(facing);
        this.level.setBlock(v, hook, true, false);

        if (updateAround) {
            this.level.updateAroundRedstone(v, null);
            this.level.updateAroundRedstone(v.getSide(facing.getOpposite()), null);
        }
    }

    if (attached != canConnect) {
        for (int i = 1; i < distance; i++) {
            Vector3 vc = v.getSide(facing, i);
            block = blocks[i];

            if (block != null && this.level.getBlockIdAt(vc.getFloorX(), vc.getFloorY(), vc.getFloorZ()) != Block.AIR) {
                if (canConnect ^ ((block.getDamage() & 0x04) > 0)) {
                    block.setDamage(block.getDamage() ^ 0x04);
                }

                this.level.setBlock(vc, block, true, false);
            }
        }
    }
}