array of blocks within a radius

Discussion in 'Plugin Development' started by boardinggamer, Nov 9, 2012.

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

    boardinggamer

    How would I get an array of blocks within a radius of another block? I tried to figure it out but couldn't find anything =/

    can anyone help with this?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  2. Offline

    md_5

    Some pseudo code:
    Code:
    // world, centerX,centerY, centerZ are variables.
    List<Block> blocks = ArrayList;
    int radius = 5;
    for (int x = -centerX; x < centerX; x++)
    for (int y = -centerY; x < centerY; y++)
    for (int z = -centerZ; x < centerZ; z++)
    block.add(world.getBlockAt(x,y,z)
    Hope that helps.
     
  3. Offline

    boardinggamer

    md_5
    I thought I got it and tried this
    Code:
    List<Block> blocks = new ArrayList<Block>();
                int radius = getConfig().getInt("Protection_Radius");
                for (int x = term.getX() - radius; x < term.getX(); x++)
                {
                    for (int y = term.getY() - radius; y < term.getY(); y++)
                    {
                        for (int z = term.getZ() - radius; z < term.getZ(); z++)
                        {
                            blocks.add(term.getWorld().getBlockAt(x,y,z));
                        }
                    }
                }
    and it didn't work.
    What am I doing wrong?
     
  4. Offline

    md_5

    ....... < term.get...() + radius
     
  5. Offline

    boardinggamer

    oh my bad. Thank you it worked!
     
Thread Status:
Not open for further replies.

Share This Page