Package com.sk89q.craftbook.util.exceptions

Examples of com.sk89q.craftbook.util.exceptions.InvalidMechanismException


            return proximalBaseCenter; // it's below

        proximalBaseCenter = trigger.getRelative(SignUtil.getBack(trigger));
        if (blocks.contains(new ItemInfo(proximalBaseCenter)))
            return proximalBaseCenter; // it's behind
        else throw new InvalidMechanismException("mech.bridge.unusable");
    }
View Full Code Here


        }

        // Expand Left
        for (int i = 0; i < left; i++) {
            if(!BlockUtil.areBlocksIdentical(distalBaseCenter.getRelative(SignUtil.getLeft(trigger), i), proximalBaseCenter.getRelative(SignUtil.getLeft(trigger), i)))
                throw new InvalidMechanismException("mech.bridge.material");
            toggle.expand(BukkitUtil.toVector(SignUtil.getLeft(trigger)), new Vector(0, 0, 0));
        }

        // Expand Right
        for (int i = 0; i < right; i++) {
            if(!BlockUtil.areBlocksIdentical(distalBaseCenter.getRelative(SignUtil.getRight(trigger), i), proximalBaseCenter.getRelative(SignUtil.getRight(trigger), i)))
                throw new InvalidMechanismException("mech.bridge.material");
            toggle.expand(BukkitUtil.toVector(SignUtil.getRight(trigger)), new Vector(0, 0, 0));
        }

        // Don't toggle the end points
        toggle.contract(BukkitUtil.toVector(SignUtil.getBack(trigger)), BukkitUtil.toVector(SignUtil.getFront(trigger)));
View Full Code Here

        return toggle;
    }

    public boolean flipState(Block trigger, LocalPlayer player) throws InvalidMechanismException {

        if (!SignUtil.isCardinal(trigger)) throw new InvalidMechanismException();

        // Attempt to detect whether the bridge is above or below the sign,
        // first assuming that the bridge is above
        Block proximalBaseCenter = getBlockBase(trigger);

        // Find the other side
        Block farSide = getFarSign(trigger);

        if (farSide.getType() != trigger.getType()) throw new InvalidMechanismException("mech.bridge.other-sign");

        // Check the other side's base blocks for matching type
        BlockFace face = trigger.getFace(proximalBaseCenter);
        if(face != BlockFace.UP && face != BlockFace.DOWN) face = face.getOppositeFace();
        Block distalBaseCenter = farSide.getRelative(face);
        if (!BlockUtil.areBlocksIdentical(distalBaseCenter, proximalBaseCenter))
            throw new InvalidMechanismException("mech.bridge.material");

        // Select the togglable region
        CuboidRegion toggle = getCuboidArea(trigger, proximalBaseCenter, distalBaseCenter);

        // this is kinda funky, but we only check one position
View Full Code Here

        }, 2L);
    }

    public boolean flipState(Block trigger, LocalPlayer player) throws InvalidMechanismException {

        if (!SignUtil.isCardinal(trigger)) throw new InvalidMechanismException();

        ChangedSign sign = BukkitUtil.toChangedSign(trigger);

        // Attempt to detect whether the bridge is above or below the sign,
        // first assuming that the bridge is above
        Block proximalBaseCenter = getBlockBase(trigger);

        // Find the other side
        Block farSide = getFarSign(trigger);

        if (farSide.getType() != trigger.getType()) throw new InvalidMechanismException("mech.door.other-sign");

        // Check the other side's base blocks for matching type
        Block distalBaseCenter = null;
        if (sign.getLine(1).equalsIgnoreCase("[Door Up]")) {
            distalBaseCenter = farSide.getRelative(BlockFace.DOWN);
        } else if (sign.getLine(1).equalsIgnoreCase("[Door Down]")) {
            distalBaseCenter = farSide.getRelative(BlockFace.UP);
        }
        if (!BlockUtil.areBlocksIdentical(distalBaseCenter, proximalBaseCenter))
            throw new InvalidMechanismException("mech.door.material");

        // Select the togglable region
        CuboidRegion toggle = getCuboidArea(trigger, proximalBaseCenter, distalBaseCenter);

        // this is kinda funky, but we only check one position
View Full Code Here

        if (s.getLine(1).equalsIgnoreCase("[Door Up]")) {
            proximalBaseCenter = trigger.getRelative(BlockFace.UP);
        } else if (s.getLine(1).equalsIgnoreCase("[Door Down]")) {
            proximalBaseCenter = trigger.getRelative(BlockFace.DOWN);
        } else throw new InvalidMechanismException("Sign is incorrectly made.");

        if (blocks.contains(new ItemInfo(proximalBaseCenter)))
            return proximalBaseCenter;
        else throw new InvalidMechanismException("mech.door.unusable");
    }
View Full Code Here

        }

        // Expand Left
        for (int i = 0; i < left; i++) {
            if(distalBaseCenter.getRelative(SignUtil.getLeft(trigger), i).getType() != proximalBaseCenter.getRelative(SignUtil.getLeft(trigger), i).getType() && distalBaseCenter.getRelative(SignUtil.getLeft(trigger), i).getData() != proximalBaseCenter.getRelative(SignUtil.getLeft(trigger), i).getData())
                throw new InvalidMechanismException("mech.door.material");
            toggle.expand(BukkitUtil.toVector(SignUtil.getLeft(trigger)), new Vector(0, 0, 0));
        }

        // Expand Right
        for (int i = 0; i < right; i++) {
            if(distalBaseCenter.getRelative(SignUtil.getRight(trigger), i).getType() != proximalBaseCenter.getRelative(SignUtil.getRight(trigger), i).getType() && distalBaseCenter.getRelative(SignUtil.getRight(trigger), i).getData() != proximalBaseCenter.getRelative(SignUtil.getRight(trigger), i).getData())
                throw new InvalidMechanismException("mech.door.material");
            toggle.expand(BukkitUtil.toVector(SignUtil.getRight(trigger)), new Vector(0, 0, 0));
        }

        // Don't toggle the end points
        toggle.contract(BukkitUtil.toVector(BlockFace.UP), BukkitUtil.toVector(BlockFace.DOWN));
View Full Code Here

     * @param rail the block containing the rails.
     */
    public static CartMechanismBlocks findByRail(Block rail) throws InvalidMechanismException {

        if (!RailUtil.isTrack(rail.getType()))
            throw new InvalidMechanismException("rail argument must be a rail!");
        BlockFace face = BlockFace.DOWN;

        if (rail.getType() == Material.LADDER)
            face = ((Attachable) rail.getState().getData()).getAttachedFace();
        else if (rail.getType() == Material.VINE) {
View Full Code Here

     * @param base the block on which the rails sit; the type of this block is what determines the mechanism type.
     */
    public static CartMechanismBlocks findByBase(Block base) throws InvalidMechanismException {

        if (!RailUtil.isTrack(base.getRelative(BlockFace.UP, 1).getType()))
            throw new InvalidMechanismException("could not find rails.");
        if (SignUtil.isSign(base.getRelative(BlockFace.DOWN, 1)))
            return new CartMechanismBlocks(base.getRelative(BlockFace.UP, 1), base, base.getRelative(BlockFace.DOWN, 1));
        else if (SignUtil.isSign(base.getRelative(BlockFace.DOWN, 2)))
            return new CartMechanismBlocks(base.getRelative(BlockFace.UP, 1), base, base.getRelative(BlockFace.DOWN, 2));
        else if (SignUtil.isSign(base.getRelative(BlockFace.EAST, 1)))
View Full Code Here

     *
     * @param sign the block containing the sign that gives additional configuration to the mechanism.
     */
    public static CartMechanismBlocks findBySign(Block sign) throws InvalidMechanismException {

        if (!SignUtil.isSign(sign)) throw new InvalidMechanismException("sign argument must be a sign!");
        if (RailUtil.isTrack(sign.getRelative(BlockFace.UP, 2).getType()))
            return new CartMechanismBlocks(sign.getRelative(BlockFace.UP, 2), sign.getRelative(BlockFace.UP, 1), sign);
        else if (RailUtil.isTrack(sign.getRelative(BlockFace.UP, 3).getType()))
            return new CartMechanismBlocks(sign.getRelative(BlockFace.UP, 3), sign.getRelative(BlockFace.UP, 2), sign);
        else if (RailUtil.isTrack(sign.getRelative(SignUtil.getBack(sign), 1).getRelative(BlockFace.UP, 1).getType()))
            return new CartMechanismBlocks(sign.getRelative(SignUtil.getBack(sign), 1).getRelative(BlockFace.UP, 1), sign.getRelative( SignUtil.getBack(sign), 1), sign);
        throw new InvalidMechanismException("could not find rails.");
    }
View Full Code Here

TOP

Related Classes of com.sk89q.craftbook.util.exceptions.InvalidMechanismException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.