Finding all blocks in an area

Discussion in 'Spigot Plugin Development' started by GameModeX, Jun 11, 2017.

  1. Hey all I'm wondering how one would grab an array of every block in a defined cube's area.

    Something like this: https://pastebin.com/UX7Piz6e

    Please help, thanks
     
  2. This is untested, and I'm tired so please ignore it if it doesn't work:
    Code (Text):

    public List<Block> getBlocksInCube(World world, int minX, int minY, int minZ, int length) {
        List<Block> blocks = new ArrayList<>();
        for (int x = minX; x != (minX + length); x++) {
            for (int y = minY; y != (minY + length); y++) {
                for (int z = minZ; z != (minZ + length); z++) {
                    blocks.add(world.getBlockAt(x, y, z));
                }
            }
        }
        return blocks;
    }
    Hope this helps.