mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-01 00:10:40 +01:00
better safe spot finder
This commit is contained in:
parent
2e6ef59040
commit
6f01310f92
@ -230,17 +230,48 @@ public class SafeSpotTeleport {
|
|||||||
* @return true if a safe spot was found
|
* @return true if a safe spot was found
|
||||||
*/
|
*/
|
||||||
private boolean scanChunk(ChunkSnapshot chunk) {
|
private boolean scanChunk(ChunkSnapshot chunk) {
|
||||||
// Run through the chunk
|
int startY = location.getBlockY();
|
||||||
for (int x = 0; x< 16; x++) {
|
int minY = location.getWorld().getMinHeight() + 1;
|
||||||
|
int maxY = maxHeight;
|
||||||
|
|
||||||
|
// Check the safe spot at the current height
|
||||||
|
for (int x = 0; x < 16; x++) {
|
||||||
for (int z = 0; z < 16; z++) {
|
for (int z = 0; z < 16; z++) {
|
||||||
// Work down from the entry point up
|
if (minY >= startY && startY <= maxY && checkBlock(chunk, x, startY ,z)) {
|
||||||
for (int y = Math.min(chunk.getHighestBlockYAt(x, z), maxHeight); y >= 0; y--) {
|
return true;
|
||||||
if (checkBlock(chunk, x,y,z)) {
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Expand the height up and down until a safe spot is found
|
||||||
|
int upperY = startY + 1;
|
||||||
|
int lowerY = startY - 1;
|
||||||
|
boolean checkUpper = upperY <= maxY;
|
||||||
|
boolean checkLower = lowerY >= minY;
|
||||||
|
while (checkUpper || checkLower) {
|
||||||
|
for (int x = 0; x < 16; x++) {
|
||||||
|
for (int z = 0; z < 16; z++) {
|
||||||
|
if (checkUpper && upperY <= maxY && checkBlock(chunk, x, upperY, z)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} // end y
|
if (checkLower && lowerY >= minY && checkBlock(chunk, x, lowerY, z)) {
|
||||||
} //end z
|
return true;
|
||||||
} // end x
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (upperY > maxY) {
|
||||||
|
checkUpper = false;
|
||||||
|
} else {
|
||||||
|
upperY++;
|
||||||
|
}
|
||||||
|
if (lowerY < minY) {
|
||||||
|
checkLower = false;
|
||||||
|
} else {
|
||||||
|
lowerY--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// We can't find a safe spot
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user