title: Iterate through 3 dimensional radius in world from center position
body: <p>I am trying to get all positions in a radius from a 3 dimensional world(In this case the game Minecraft) this is the current code I use.</p>
  
  <pre class="lang-java prettyprint-override"><code>    public static List&lt;BlockPos&gt; getBlocksInRadius(double radius) {
          List&lt;BlockPos&gt; circleblocks = new ArrayList&lt;&gt;();
          int centralx = mc.player.posX;
          int centraly = mc.player.posY;
          int centralz = mc.player.posZ;
          for (int x = centralx - radius; x &lt;= centralx + radius; x++) {
              for (int z = centralz - radius; z &lt;= centralz + radius; z++) {
                  for (int y = centraly - radius; y &lt; centraly + radius; y++) {
                      double dist = mc.player.getDistance(x, y, z);
                      if (dist &lt; radius) {
                          BlockPos l = new BlockPos(x, y, z);
                          circleblocks.add(l);
                      }
                  }
              }
          }
          return circleblocks;
      }
  </code></pre>
  
  <p>This method goes from the x coord farthest away and keeps coming closer to the player. I want it to iterate it by starting at central x,y,z and then increase distance from the player. This is to make it easier to find block x closest to player. Any help would be apreciated!</p>