for (int ix = x - r; ix < x + r + 1; ix++) {
for (int iz = z - r; iz < z + r + 1; iz++) {
for (int iy = y - r; iy < y + r + 1; iy++) {
// if ix,iy,iz = something blah blah (this part isn't needed)
}
}
}
Ok, now here’s the issue. The current code above gets an x,y,z and r (range). It’s job is to reference through the “cube” until meets a certain condition I’ve set. The problem lies in the fact that it starts on the outside of the cube and progresses from 1 corner to another corner basically.
I’m looking for a way (my math/java is not liking me atm) to start at a pos and loop outwards from that pos (including the pos itself) until it reaches the outermost bounds of the cube.
So if we gave everything fake values, lets use x = 5, y = 5, z = 5, r = 2
the code should check 5,5,5 – 4,5,5 6,5,5 5,6,5 5,4,5 etc etc basically iterating through every thing to outwards from the center.
The command is called FindNearest, but technically it’s acting like FindFurthest atm.
I hope I gave enough detail and would love if someone could toss some snippets or working code at me as this is frustrating for the last hour or so. I don’t wanna have 10 if checks in the middle of the for loops or random stuff like that, I’m looking for a clean way of doing this.
You can iterate out from the center by doing something like this:
So
ixfor your example will go from 5 to 6 to 4 to 7, etc. You can just nest loops like these and you’ll get what you’re looking for, at least if I’m understanding the question correctly.