static boolean getOutput(World world, Vector pos) { if (CraftBook.getBlockID(world, pos) == BlockType.LEVER) { return (CraftBook.getBlockData(world, pos) & 0x8) == 0x8; } else { return false; } }
/** * Recursively expand the search area so we can define the number of blocks that are in the * cauldron. The search will not exceed 24 blocks as no pot will ever use up that many blocks. The * Y are bounded both directions so we don't ever search the lava or anything above, although in * the case of non-wall blocks, we also make sure that there is standing lava underneath. * * @param pt * @param minY * @param maxY * @param visited * @throws Cauldron.NotACauldronException */ public void findCauldronContents( World world, BlockVector pt, int minY, int maxY, Map<BlockVector, CraftBookItem> visited) throws NotACauldronException { // Don't want to go too low or high if (pt.getBlockY() < minY) { return; } if (pt.getBlockY() > maxY) { return; } // There is likely a leak in the cauldron (or this isn't a cauldron) if (visited.size() > 24) { throw new NotACauldronException("Cauldron has a leak"); } // Prevent infinite looping if (visited.containsKey(pt)) { return; } int type = CraftBook.getBlockID(world, pt); int data = CraftBook.getBlockData(world, pt); if (BlockType.isDirectionBlock(type)) data = 0; // Make water work reliably if (type == 9) { type = 8; } // Make lava work reliably if (type == 11) { type = 10; } visited.put(pt, new CraftBookItem(type, data)); // It's a wall -- we only needed to remember that we visited it but // we don't need to recurse if (type == BlockType.STONE) { return; } // Must have a lava floor Vector lavaPos = pt.subtract(0, pt.getBlockY() - minY + 1, 0); if (!BlockType.isLava(CraftBook.getBlockID(world, lavaPos))) { throw new NotACauldronException("Cauldron lacks lava below"); } // Now we recurse! findCauldronContents(world, pt.add(1, 0, 0).toBlockVector(), minY, maxY, visited); findCauldronContents(world, pt.add(-1, 0, 0).toBlockVector(), minY, maxY, visited); findCauldronContents(world, pt.add(0, 0, 1).toBlockVector(), minY, maxY, visited); findCauldronContents(world, pt.add(0, 0, -1).toBlockVector(), minY, maxY, visited); findCauldronContents(world, pt.add(0, 1, 0).toBlockVector(), minY, maxY, visited); findCauldronContents(world, pt.add(0, -1, 0).toBlockVector(), minY, maxY, visited); }
static Boolean isHigh(World world, Vector pt, int type, boolean considerWires) { if (type == BlockType.LEVER) { return (CraftBook.getBlockData(world, pt) & 0x8) == 0x8; } else if (type == BlockType.STONE_PRESSURE_PLATE) { return (CraftBook.getBlockData(world, pt) & 0x1) == 0x1; } else if (type == BlockType.WOODEN_PRESSURE_PLATE) { return (CraftBook.getBlockData(world, pt) & 0x1) == 0x1; } else if (type == BlockType.REDSTONE_TORCH_ON) { return true; } else if (type == BlockType.REDSTONE_TORCH_OFF) { return false; } else if (type == BlockType.STONE_BUTTON) { return (CraftBook.getBlockData(world, pt) & 0x8) == 0x8; } else if (considerWires && type == BlockType.REDSTONE_WIRE) { return CraftBook.getBlockData(world, pt) > 0; } return null; }
/** Make the copy from world. */ public void copy() { for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { for (int z = 0; z < length; z++) { int index = y * width * length + z * width + x; blocks[index] = (byte) CraftBook.getBlockID(origin.add(x, y, z)); data[index] = (byte) CraftBook.getBlockData(origin.add(x, y, z)); } } } findTestOffset(); }
static void setTrackTrigger(World world, Vector pos) { if (CraftBook.getBlockID(world, pos) == BlockType.LEVER) { int data = CraftBook.getBlockData(world, pos); int newData = 0; boolean state = (data & 0x8) == 0x8; if (state) { newData = data & 0x7; } else { newData = data | 0x8; } CraftBook.setBlockData(world, pos, newData); world.updateBlockPhysics(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ(), newData); } }
static void setOutput(World world, Vector pos, boolean state) { if (CraftBook.getBlockID(world, pos) == BlockType.LEVER) { int data = CraftBook.getBlockData(world, pos); int newData = data & 0x7; if (!state) { newData = data & 0x7; } else { newData = data | 0x8; } if (newData != data) { CraftBook.setBlockData(world, pos, newData); world.updateBlockPhysics(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ(), newData); } } }
static Boolean isWireHigh(World world, Vector pt, Vector sidePt1, Vector sidePt2) { int side1 = CraftBook.getBlockID(world, sidePt1); int side1Above = CraftBook.getBlockID(world, sidePt1.add(0, 1, 0)); int side1Below = CraftBook.getBlockID(world, sidePt1.add(0, -1, 0)); int side2 = CraftBook.getBlockID(world, sidePt2); int side2Above = CraftBook.getBlockID(world, sidePt2.add(0, 1, 0)); int side2Below = CraftBook.getBlockID(world, sidePt2.add(0, -1, 0)); if (!BlockType.isRedstoneBlock(side1) && !BlockType.isRedstoneBlock(side1Above) && (!BlockType.isRedstoneBlock(side1Below) || side1 != 0) && !BlockType.isRedstoneBlock(side2) && !BlockType.isRedstoneBlock(side2Above) && (!BlockType.isRedstoneBlock(side2Below) || side2 != 0)) { return CraftBook.getBlockData(world, pt) > 0; } return null; }
static void toggleOutput(World world, Vector pos) { if (CraftBook.getBlockID(world, pos) == BlockType.LEVER) { setOutput(world, pos, (CraftBook.getBlockData(world, pos) & 0x8) != 0x8); } }