Solved Find sphere of blocks and replace

Discussion in 'Plugin Development' started by VortexGmer, Apr 26, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    VortexGmer

    How do I find the blocks inside a sphere with a radius of say, 3 and if the block is air replace it?
    Must be easy but I cannot figure it out without alot of unnecessary code
     
  2. @VortexGmer Using the sphere generation method:
    Code:
    /** Creates a sphere */
    public ArrayList<Block> sphere(final Location center, final int radius) {
        ArrayList<Block> sphere = new ArrayList<Block>();
        for (int Y = -radius; Y < radius; Y++)
          for (int X = -radius; X < radius; X++)
             for (int Z = -radius; Z < radius; Z++)
                if (Math.sqrt((X * X) + (Y * Y) + (Z * Z)) <= radius) {
                   final Block block = center.getWorld().getBlockAt(X + center.getBlockX(), Y + center.getBlockY(), Z + center.getBlockZ());
                   sphere.add(block);
                }
    return sphere;
    }
    From there, you can loop through all of the blocks, check if it's air or not then replace it.
     
  3. Offline

    VortexGmer

    cool thanks!
     
Thread Status:
Not open for further replies.

Share This Page