Examples of NearbyChestBlockBag


Examples of com.sk89q.craftbook.blockbag.NearbyChestBlockBag

            /*if (CraftBook.getBlockID(depositPt) != BlockType.MINECART_TRACKS) {
                return;
            }*/

            NearbyChestBlockBag blockBag = new NearbyChestBlockBag(pt);
            blockBag.addSingleSourcePosition(world, pt);
            blockBag.addSingleSourcePosition(world, pt.add(1, 0, 0));
            blockBag.addSingleSourcePosition(world, pt.add(-1, 0, 0));
            blockBag.addSingleSourcePosition(world, pt.add(0, 0, 1));
            blockBag.addSingleSourcePosition(world, pt.add(0, 0, -1));

            try {
                MinecartInterface minecart;

                if (collectType.equalsIgnoreCase("Storage")) {
                    try {
                        blockBag.fetchBlock(ItemType.STORAGE_MINECART);
                    } catch (BlockBagException e) {
                        // Okay, no storage minecarts... but perhaps we can
                        // craft a minecart + chest!
                        if (blockBag.peekBlock(BlockType.CHEST)) {
                            blockBag.fetchBlock(ItemType.MINECART);
                            blockBag.fetchBlock(BlockType.CHEST);
                        } else {
                            throw new BlockBagException();
                        }
                    }

                    minecart = world.spawnMinecart(
                            depositPt.getX(),
                            depositPt.getY(),
                            depositPt.getZ(),
                            MinecartInterface.Type.STORAGE);
                } else if (collectType.equalsIgnoreCase("Powered")) {
                    try {
                        blockBag.fetchBlock(ItemType.POWERED_MINECART);
                    } catch (BlockBagException e) {
                        // Okay, no storage minecarts... but perhaps we can
                        // craft a minecart + chest!
                        if (blockBag.peekBlock(BlockType.FURNACE)) {
                            blockBag.fetchBlock(ItemType.MINECART);
                            blockBag.fetchBlock(BlockType.FURNACE);
                        } else {
                            throw new BlockBagException();
                        }
                    }

                    minecart = world.spawnMinecart(
                            depositPt.getX(),
                            depositPt.getY(),
                            depositPt.getZ(),
                            MinecartInterface.Type.POWERED);
                } else {
                    blockBag.fetchBlock(ItemType.MINECART);
                    minecart = world.spawnMinecart(
                            depositPt.getX(),
                            depositPt.getY(),
                            depositPt.getZ(),
                            MinecartInterface.Type.REGULAR);
View Full Code Here

Examples of com.sk89q.craftbook.blockbag.NearbyChestBlockBag

                Boolean test = RedstoneUtil.testAnyInput(world, underPt);

                if (test == null || test) {
                    if (minecart.getType() == MinecartInterface.Type.STORAGE) {
                        Vector pt = new Vector(blockX, blockY, blockZ);
                        NearbyChestBlockBag bag = new NearbyChestBlockBag(pt);

                        for (int y = -1; y <= 0; y++) {
                            bag.addSingleSourcePosition(world, pt.add(1, y, 0));
                            bag.addSingleSourcePosition(world, pt.add(2, y, 0));
                            bag.addSingleSourcePosition(world, pt.add(-1, y, 0));
                            bag.addSingleSourcePosition(world, pt.add(-2, y, 0));
                            bag.addSingleSourcePosition(world, pt.add(0, y, 1));
                            bag.addSingleSourcePosition(world, pt.add(0, y, 2));
                            bag.addSingleSourcePosition(world, pt.add(0, y, -1));
                            bag.addSingleSourcePosition(world, pt.add(0, y, -2));
                        }

                        if (bag.getChestBlockCount() > 0) {
                            if (getControllerSign(world, pt.add(0, -1, 0), "[Deposit]") != null) {
                                InventoryUtil.moveChestBagToItemArray(
                                        (StorageMinecartInterface) minecart, bag);
                            } else {
                                InventoryUtil.moveItemArrayToChestBag(
                                        (StorageMinecartInterface) minecart, bag);
                            }
                        }
                    }
                }

                return;
            } else if (under == minecartEjectBlock) {
                Boolean test = RedstoneUtil.testAnyInput(world, underPt);

                if (test == null || test) {
                    PlayerInterface player = minecart.getPlayer();
                    if (player != null) {
                        // Let's find a place to put the player
                        Tuple3<Integer, Integer, Integer> loc =
                                new Tuple3<Integer, Integer, Integer>(blockX, blockY, blockZ);
                        Vector signPos = new Vector(blockX, blockY - 2, blockZ);

                        if (world.getId(signPos) == BlockType.SIGN_POST
                                && MinecraftUtil.doesSignSay(world, signPos, 1, "[Eject]")) {
                            Vector pos = MinecraftUtil.getSignPostOrthogonalBack(world, signPos, 1);

                            // Acceptable sign direction
                            if (pos != null) {
                                pos = pos.setY(blockY);

                                // Is the spot free?
                                if (BlockType.canPassThrough(world.getId(pos.add(0, 1, 0)))
                                        && BlockType.canPassThrough(world.getId(pos))) {
                                    loc = new Tuple3<Integer, Integer, Integer>(
                                            pos.getBlockX(),
                                            pos.getBlockY(),
                                            pos.getBlockZ());

                                    BlockEntity cBlock = world.getBlockEntity(
                                            blockX, blockY - 2, blockZ);

                                    if (cBlock instanceof SignInterface) {
                                        SignInterface sign = (SignInterface) cBlock;
                                        String text = sign.getLine1();
                                        if (text.length() > 0) {
                                            player.sendMessage(Colors.GOLD + "You've arrived at: "
                                                    + text);
                                        }
                                    }
                                }
                            }
                        }

                        player.setX(loc.a + 0.5);
                        player.setY(loc.b + 0.1);
                        player.setX(loc.c + 0.5);
                    }
                }

                return;
            } else if (under == minecartSortBlock) {
                Boolean test = RedstoneUtil.testAnyInput(world, underPt);

                if (test == null || test) {
                    SignInterface sign =
                            getControllerSign(world, blockX, blockY - 1, blockZ, "[Sort]");

                    if (sign != null) {
                        SortDir dir = SortDir.FORWARD;

                        if (satisfiesCartSort(sign.getLine3(), minecart,
                                new Vector(blockX, blockY, blockZ))) {
                            dir = SortDir.LEFT;
                        } else if (satisfiesCartSort(sign.getLine4(), minecart,
                                new Vector(blockX, blockY, blockZ))) {
                            dir = SortDir.RIGHT;
                        }

                        int signData = world.getData(
                                sign.getX(), sign.getY(), sign.getZ());
                        int newData = 0;
                        Vector targetTrack = null;

                        if (signData == 0x8) { // West
                            if (dir == SortDir.LEFT) {
                                newData = 9;
                            } else if (dir == SortDir.RIGHT) {
                                newData = 8;
                            } else {
                                newData = 0;
                            }
                            targetTrack = new Vector(blockX, blockY, blockZ + 1);
                        } else if (signData == 0x0) { // East
                            if (dir == SortDir.LEFT) {
                                newData = 7;
                            } else if (dir == SortDir.RIGHT) {
                                newData = 6;
                            } else {
                                newData = 0;
                            }
                            targetTrack = new Vector(blockX, blockY, blockZ - 1);
                        } else if (signData == 0xC) { // North
                            if (dir == SortDir.LEFT) {
                                newData = 6;
                            } else if (dir == SortDir.RIGHT) {
                                newData = 9;
                            } else {
                                newData = 1;
                            }
                            targetTrack = new Vector(blockX - 1, blockY, blockZ);
                        } else if (signData == 0x4) { // South
                            if (dir == SortDir.LEFT) {
                                newData = 8;
                            } else if (dir == SortDir.RIGHT) {
                                newData = 7;
                            } else {
                                newData = 1;
                            }
                            targetTrack = new Vector(blockX + 1, blockY, blockZ);
                        }

                        if (targetTrack != null
                                && world.getId(targetTrack) == BlockType.MINECART_TRACKS) {
                            world.setData(targetTrack, newData);
                        }
                    }
                }

                return;
            }
        }

        if (minecartTrackMessages
                && world.getId(underPt.add(0, -1, 0)) == BlockType.SIGN_POST) {
            Vector signPos = underPt.add(0, -1, 0);

            Boolean test = RedstoneUtil.testAnyInput(world, signPos);

            if (test == null || test) {
                BlockEntity cblock = world.getBlockEntity(
                        signPos.getBlockX(), signPos.getBlockY(), signPos.getBlockZ());

                if (!(cblock instanceof SignInterface)) {
                    return;
                }

                SignInterface sign = (SignInterface) cblock;
                String line1 = sign.getLine1();

                if (line1.equalsIgnoreCase("[Print]")) {
                    if (!minecart.hasPlayer()) {
                        return;
                    }
                    PlayerInterface player = minecart.getPlayer();

                    String name = player.getName();
                    String msg = sign.getLine2() + sign.getLine3() + sign.getLine4();
                    long now = System.currentTimeMillis();

                    if (lastMinecartMsg.containsKey(name)) {
                        String lastMessage = lastMinecartMsg.get(name);
                        if (lastMessage.equals(msg)
                                && now < lastMinecartMsgTime.get(name) + 3000) {
                            return;
                        }
                    }

                    lastMinecartMsg.put(name, msg);
                    lastMinecartMsgTime.put(name, now);
                    player.sendMessage("> " + msg);
                }
            }
        }

        if (minecartDispensers) {
            Vector pt = new Vector(blockX, blockY, blockZ);
            Vector depositPt = null;

            if (world.getId(pt.add(1, 0, 0)) == BlockType.CHEST
                    && (world.getId(pt.add(-1, 0, 0)) == BlockType.MINECART_TRACKS
                    || world.getId(pt.add(-1, -1, 0)) == BlockType.MINECART_TRACKS
                    || world.getId(pt.add(-1, 1, 0)) == BlockType.MINECART_TRACKS)) {
                depositPt = pt.add(1, 0, 0);
            } else if (world.getId(pt.add(-1, 0, 0)) == BlockType.CHEST
                    && (world.getId(pt.add(1, 0, 0)) == BlockType.MINECART_TRACKS
                    || world.getId(pt.add(1, -1, 0)) == BlockType.MINECART_TRACKS
                    || world.getId(pt.add(1, 1, 0)) == BlockType.MINECART_TRACKS)) {
                depositPt = pt.add(-1, 0, 0);
            } else if (world.getId(pt.add(0, 0, 1)) == BlockType.CHEST
                    && (world.getId(pt.add(0, 0, -1)) == BlockType.MINECART_TRACKS
                    || world.getId(pt.add(0, -1, -1)) == BlockType.MINECART_TRACKS
                    || world.getId(pt.add(0, 1, -1)) == BlockType.MINECART_TRACKS)) {
                depositPt = pt.add(0, 0, 1);
            } else if (world.getId(pt.add(0, 0, -1)) == BlockType.CHEST
                    && (world.getId(pt.add(0, 0, 1)) == BlockType.MINECART_TRACKS
                    || world.getId(pt.add(0, -1, 1)) == BlockType.MINECART_TRACKS
                    || world.getId(pt.add(0, 1, 1)) == BlockType.MINECART_TRACKS)) {
                depositPt = pt.add(0, 0, -1);
            }

            if (depositPt != null) {
                SignInterface sign =
                        getControllerSign(world, depositPt.add(0, -1, 0), "[Dispenser]");
                String collectType = sign != null ? sign.getLine2() : "";

                NearbyChestBlockBag blockBag = new NearbyChestBlockBag(depositPt);
                blockBag.addSingleSourcePosition(world, depositPt);
                blockBag.addSingleSourcePosition(world, depositPt.add(1, 0, 0));
                blockBag.addSingleSourcePosition(world, depositPt.add(-1, 0, 0));
                blockBag.addSingleSourcePosition(world, depositPt.add(0, 0, 1));
                blockBag.addSingleSourcePosition(world, depositPt.add(0, 0, -1));

                MinecartInterface.Type type = minecart.getType();

                if (type == MinecartInterface.Type.REGULAR) {
                    try {
                        blockBag.storeBlock(ItemType.MINECART);
                        minecart.remove();
                    } catch (BlockBagException e) {
                    }
                } else if (type == MinecartInterface.Type.STORAGE) {
                    try {
                        InventoryUtil.moveItemArrayToChestBag(
                                (StorageMinecartInterface) minecart, blockBag);

                        if (collectType.equalsIgnoreCase("Storage")) {
                            blockBag.storeBlock(ItemType.STORAGE_MINECART);
                        } else {
                            blockBag.storeBlock(ItemType.MINECART);
                            blockBag.storeBlock(BlockType.CHEST);
                        }

                        minecart.remove();
                    } catch (BlockBagException e) {
                        // Ran out of space
                    }
                } else if (type == MinecartInterface.Type.POWERED) {
                    try {
                        if (collectType.equalsIgnoreCase("Powered")) {
                            blockBag.storeBlock(ItemType.POWERED_MINECART);
                        } else {
                            blockBag.storeBlock(ItemType.MINECART);
                            blockBag.storeBlock(BlockType.FURNACE);
                        }
                        minecart.remove();
                    } catch (BlockBagException e) {
                        // Ran out of space
                    }
                }

                blockBag.flushChanges();
            }
        }
    }
View Full Code Here

Examples of com.sk89q.craftbook.blockbag.NearbyChestBlockBag

        if (!chip.getIn(1).is()) {
            return;
        }

        NearbyChestBlockBag source = new NearbyChestBlockBag(chip.getPosition());
        source.addSourcePosition(chip.getWorld(), chip.getPosition());

        String id = chip.getText().getLine3();
        int quantity = 1;

        try {
            quantity = Math.min(64,
                    Math.max(1, Integer.parseInt(chip.getText().getLine4())));
        } catch (NumberFormatException e) {
        }

        int item = CraftBookUtil.getItem(chip.getServer().getConfiguration(), id);

        if (item > 0 && !(item >= 21 && item <= 34) && item != 36) {
            Vector pos = chip.getBlockPosition();
            int maxY = Math.min(128, pos.getBlockY() + 10);
            int x = pos.getBlockX();
            int z = pos.getBlockZ();

            for (int y = pos.getBlockY() + 1; y <= maxY; y++) {
                if (BlockType.canPassThrough(chip.getWorld().getId(x, y, z))) {
                    int n = 0;
                    for (n = 0; n < quantity; n++) {
                        try {
                            source.fetchBlock(item);
                        } catch (BlockBagException e) {
                            break;
                        }
                    }
                    if (n != 0) chip.getWorld().dropItem(x, y, z, item, quantity);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.