Package com.sk89q.craftbook.util

Examples of com.sk89q.craftbook.util.Vector


        if (up) {
            // Need to traverse up to find the next sign to teleport to
            for (int y1 = y + 1; y1 <= 127; y1++) {
                if (w.getId(x, y1, z) == BlockType.WALL_SIGN
                        && getSign(w, new Vector(x, y1, z), up) != null) {
                    return true;
                }
            }
        } else {
            // Need to traverse downwards to find a sign below
            for (int y1 = y - 1; y1 >= 1; y1--) {
                if (w.getId(x, y1, z) == BlockType.WALL_SIGN
                        && getSign(w, new Vector(x, y1, z), up) != null) {
                    return true;
                }
            }
        }
View Full Code Here


        if (up) {
            // Need to traverse up to find the next sign to teleport to
            for (int y1 = y + 1; y1 <= 127; y1++) {
                if (w.getId(x, y1, z) == BlockType.WALL_SIGN
                        && checkLift(player, w, new Vector(x, y1, z), up)) {
                    return;
                }
            }
        } else {
            // Need to traverse downwards to find a sign below
            for (int y1 = y - 1; y1 >= 1; y1--) {
                if (w.getId(x, y1, z) == BlockType.WALL_SIGN
                        && checkLift(player, w, new Vector(x, y1, z), up)) {
                    return;
                }
            }
        }
    }
View Full Code Here

                player.sendMessage(Colors.GOLD + "Uh oh! You would have nothing to stand on!");
                return false;
            }

            // Teleport!
            player.setPosition(new Vector(player.getPosition().getX(), y2 + 1, player.getPosition().getZ()),
                    (float) player.getYaw(), (float) player.getPitch());


            // Now, we want to read the sign so we can tell the player
            // his or her floor, but as that may not be avilable, we can
View Full Code Here

            UnacceptableTypeException, InvalidConstructionException {

        Direction direction = getDirection();
        boolean upwards = isUpwards();

        Vector sideDir = null;
        Vector vertDir = upwards ? new Vector(0, 1, 0) : new Vector(0, -1, 0);

        if (direction == Direction.NORTH_SOUTH) {
            sideDir = new Vector(1, 0, 0);
        } else if (direction == Direction.WEST_EAST) {
            sideDir = new Vector(0, 0, 1);
        }

        int type = world.getId(pt.add(vertDir));

        // Check construction
        if (!canUseBlock(type)) {
            throw new UnacceptableTypeException();
        }

        // Check sides
        if (world.getId(pt.add(vertDir).add(sideDir)) != type
                || world.getId(pt.add(vertDir).subtract(sideDir)) != type) {
            throw new InvalidConstructionException(
                    "The blocks for the door to the sides have to be the same.");
        }

        // Detect whether the door needs to be opened
        if (toOpen == null) {
            toOpen = !canPassThrough(world.getId(pt.add(vertDir.multiply(2))));
        }

        Vector cur = pt.add(vertDir.multiply(2));
        boolean found = false;
        int dist = 0;

        // Find the other side
        for (int i = 0; i < maxLength + 2; i++) {
            int id = world.getId(cur);

            if (id == BlockType.SIGN_POST) {
                SignInterface otherSignText = (SignInterface) world.getBlockEntity(cur);

                if (otherSignText != null) {
                    String line2 = otherSignText.getLine2();

                    if (line2.equalsIgnoreCase("[Door Up]")
                            || line2.equalsIgnoreCase("[Door Down]")
                            || line2.equalsIgnoreCase("[Door End]")) {
                        found = true;
                        dist = i - 1;
                        break;
                    }
                }
            }

            cur = cur.add(vertDir);
        }

        // Failed to find the other side!
        if (!found) {
            throw new InvalidConstructionException(
                    "[Door] sign required on other side (or it was too far away).");
        }

        Vector otherSideBlockPt = pt.add(vertDir.multiply(dist + 2));

        // Check the other side to see if it's built correctly
        if (world.getId(otherSideBlockPt) != type
                || world.getId(otherSideBlockPt.add(sideDir)) != type
                || world.getId(otherSideBlockPt.subtract(sideDir)) != type) {
            throw new InvalidConstructionException(
                    "The other side must be made with the same blocks.");
        }

        if (toOpen) {
View Full Code Here

     */
    private void clearColumn(Vector origin, Vector change, int type, int dist, BlockBag bag)
            throws BlockBagException {

        for (int i = 0; i < dist; i++) {
            Vector p = origin.add(change.multiply(i));
            int t = world.getId(p);
            if (t == type) {
                bag.setBlockID(world, p, 0);
            } else if (t != 0) {
                break;
View Full Code Here

     */
    private void setColumn(Vector origin, Vector change, int type, int dist, BlockBag bag)
            throws BlockBagException {

        for (int i = 0; i < dist; i++) {
            Vector p = origin.add(change.multiply(i));
            int t = world.getId(p);
            if (canPassThrough(t)) {
                bag.setBlockID(world, p, type);
            } else if (t != type) {
                break;
View Full Code Here

        if (smallSearchSize) {
            // Toggle nearby gates
            for (int x1 = x - 1; x1 <= x + 1; x1++) {
                for (int y1 = y - 2; y1 <= y + 1; y1++) {
                    for (int z1 = z - 1; z1 <= z + 1; z1++) {
                        if (recurseColumn(w, new Vector(x1, y1, z1), visitedColumns,
                                null, bag)) {
                            foundGate = true;
                        }
                    }
                }
            }
        } else {
            // Toggle nearby gates
            for (int x1 = x - 3; x1 <= x + 3; x1++) {
                for (int y1 = y - 3; y1 <= y + 6; y1++) {
                    for (int z1 = z - 3; z1 <= z + 3; z1++) {
                        if (recurseColumn(w, new Vector(x1, y1, z1), visitedColumns,
                                null, bag)) {
                            foundGate = true;
                        }
                    }
                }
View Full Code Here

        if (smallSearchSize) {
            // Toggle nearby gates
            for (int x1 = x - 1; x1 <= x + 1; x1++) {
                for (int y1 = y - 2; y1 <= y + 1; y1++) {
                    for (int z1 = z - 1; z1 <= z + 1; z1++) {
                        if (recurseColumn(w, new Vector(x1, y1, z1), visitedColumns,
                                close, bag)) {
                            foundGate = true;
                        }
                    }
                }
            }
        } else {
            // Toggle nearby gates
            for (int x1 = x - 3; x1 <= x + 3; x1++) {
                for (int y1 = y - 3; y1 <= y + 6; y1++) {
                    for (int z1 = z - 3; z1 <= z + 3; z1++) {
                        if (recurseColumn(w, new Vector(x1, y1, z1), visitedColumns,
                                close, bag)) {
                            foundGate = true;
                        }
                    }
                }
View Full Code Here

                break;
            }

            bag.setBlockID(w, x, y1, z, close ? BlockType.FENCE : 0);

            Vector pt = new Vector(x, y1, z);
            recurseColumn(w, pt.add(1, 0, 0), visitedColumns, close, bag);
            recurseColumn(w, pt.add(-1, 0, 0), visitedColumns, close, bag);
            recurseColumn(w, pt.add(0, 0, 1), visitedColumns, close, bag);
            recurseColumn(w, pt.add(0, 0, -1), visitedColumns, close, bag);
        }

        recurseColumn(w, topPoint.add(1, 0, 0), visitedColumns, close, bag);
        recurseColumn(w, topPoint.add(-1, 0, 0), visitedColumns, close, bag);
        recurseColumn(w, topPoint.add(0, 0, 1), visitedColumns, close, bag);
View Full Code Here

            throws BlockBagException, InvalidDirectionException,
            UnacceptableTypeException, InvalidConstructionException {

        Direction direction = getDirection();

        Vector change = null;
        Vector leftSide = null;
        Vector rightSide = null;
        int centerShift = 1;

        if (direction == Direction.NORTH) {
            change = new Vector(-1, 0, 0);
            leftSide = pt.add(0, 1, -1);
            rightSide = pt.add(0, 1, 1);
        } else if (direction == Direction.SOUTH) {
            change = new Vector(1, 0, 0);
            leftSide = pt.add(0, 1, -1);
            rightSide = pt.add(0, 1, 1);
        } else if (direction == Direction.WEST) {
            change = new Vector(0, 0, 1);
            leftSide = pt.add(1, 1, 0);
            rightSide = pt.add(-1, 1, 0);
        } else if (direction == Direction.EAST) {
            change = new Vector(0, 0, -1);
            leftSide = pt.add(1, 1, 0);
            rightSide = pt.add(-1, 1, 0);
        }

        // Block above the sign
        int type = world.getId(x, y + 1, z);

        // Attempt to detect whether the bridge is above or below the sign,
        // first assuming that the bridge is above

        if (type == 0
                || !canUseBlock(type)
                || world.getId(leftSide) != type
                || world.getId(rightSide) != type) {

            // The bridge is not above, so let's try below
            leftSide = leftSide.add(0, -2, 0);
            rightSide = rightSide.add(0, -2, 0);
            centerShift = -1;

            // Block below the sign
            type = world.getId(x, y - 1, z);

            if (!canUseBlock(type)) {
                throw new UnacceptableTypeException();
            }

            // Guess not
            if (world.getId(leftSide) != type
                    || world.getId(leftSide) != type) {
                throw new InvalidConstructionException(
                        "Blocks adjacent to the bridge block must be of the same type.");
            }
        }

        Vector current = pt;
        boolean found = false;
        int dist = 0;

        // Find the other side
        for (int i = 0; i < maxLength + 2; i++) {
            int id = world.getId(current);

            if (id == BlockType.SIGN_POST) {
                SignInterface otherSignText =
                        (SignInterface) world.getBlockEntity(current);

                if (otherSignText != null) {
                    String line2 = otherSignText.getLine2();

                    if (line2.equalsIgnoreCase("[Bridge]")
                            || line2.equalsIgnoreCase("[Bridge End]")) {
                        found = true;
                        dist = i;
                        break;
                    }
                }
            }

            current = current.add(change);
        }

        // Failed to find the other side!
        if (!found) {
            throw new InvalidConstructionException(
                    "[Bridge] sign required on other side (or it was too far away).");
        }

        Vector shift = change.multiply(dist + 1);

        // Check the other side to see if it's built correctly
        if (world.getId(pt.add(shift).add(0, centerShift, 0)) != type
                || world.getId(leftSide.add(shift)) != type
                || world.getId(rightSide.add(shift)) != type) {
View Full Code Here

TOP

Related Classes of com.sk89q.craftbook.util.Vector

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.