/** * 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); }