Use loops to loop through all the blocks in the selection. Always store 2 positions, opposite corners, and the world the selections are in.
@Vynlar I just tried to sit down and sketch up a rough function to do this, and I've run into a small problem: How to identify which point to start at. If you have 2 points...lets say -1, -1 and 1, 1 It's easy to tell which direction to loop in. However, when given -1, 2 and 1, 1 It becomes more difficult. I can't seem to write the loops without several if statements (to decide which point ot start at) I'm assuming that I'm missing an important concept here, because I shouldnt have 4 slightly different blocks of code just to handle each 'point possibility'
Just use Math.min and Math.max, to loop from the point with the to smallest componets to the point with the to biggest. -1,2 and 1,1 is the same cuboid as -1,1 and 1,2
Code:java private void loopThrough(Location loc1, Location loc2){ int minx = Math.min(loc1.getBlockX(), loc2.getBlockX()), miny = Math.min(loc1.getBlockY(), loc2.getBlockY()), minz = Math.min(loc1.getBlockZ(), loc2.getBlockZ()), maxx = Math.max(loc1.getBlockX(), loc2.getBlockX()), maxy = Math.max(loc1.getBlockY(), loc2.getBlockY()), maxz = Math.max(loc1.getBlockZ(), loc2.getBlockZ()); for(int x = minx; x<=maxx;x++) { for(int y = miny; y<=maxy;y++) { for(int z = minz; z<=maxz;z++) { //do stuff } } }}
@Shamebot, The code you gave I cannot get to work. Also, I want it to look for blocks all the way from bedrocks to sky limit not the heights between the two locations.
Code:java private void loopThrough(Location loc1, Location loc2){ int minx = Math.min(loc1.getBlockX(), loc2.getBlockX()), minz = Math.min(loc1.getBlockZ(), loc2.getBlockZ()), maxx = Math.max(loc1.getBlockX(), loc2.getBlockX()), maxz = Math.max(loc1.getBlockZ(), loc2.getBlockZ()); for(int x = minx; x<=maxx;x++) { for(int y = 0; y<128;y++) { for(int z = minz; z<=maxz;z++) { //do stuff } } }}