mirror of
https://github.com/BentoBoxWorld/Greenhouses.git
synced 2025-03-02 10:41:39 +01:00
Limits roof glass search to a radius of 3 instead of 100
Search was taking too long if there was no glass and timing out the server. https://github.com/BentoBoxWorld/Greenhouses/issues/31
This commit is contained in:
parent
084570660a
commit
c8008e34e2
@ -17,7 +17,7 @@ import org.bukkit.util.Vector;
|
|||||||
*/
|
*/
|
||||||
public class Roof extends MinMaxXZ {
|
public class Roof extends MinMaxXZ {
|
||||||
private final Location location;
|
private final Location location;
|
||||||
private final int height;
|
private int height;
|
||||||
private boolean roofFound;
|
private boolean roofFound;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,6 +40,11 @@ public class Roof extends MinMaxXZ {
|
|||||||
*/
|
*/
|
||||||
public Roof(Location loc) {
|
public Roof(Location loc) {
|
||||||
this.location = loc;
|
this.location = loc;
|
||||||
|
roofFound = findRoof(loc);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private boolean findRoof(Location loc) {
|
||||||
World world = loc.getWorld();
|
World world = loc.getWorld();
|
||||||
// This section tries to find a roof block
|
// This section tries to find a roof block
|
||||||
// Try just going up - this covers every case except if the player is standing under a hole
|
// Try just going up - this covers every case except if the player is standing under a hole
|
||||||
@ -49,7 +54,7 @@ public class Roof extends MinMaxXZ {
|
|||||||
int roofY = loc.getBlockY();
|
int roofY = loc.getBlockY();
|
||||||
// If the roof was not found start going around in circles until something is found
|
// If the roof was not found start going around in circles until something is found
|
||||||
// Expand in ever increasing squares around location until a wall block is found
|
// Expand in ever increasing squares around location until a wall block is found
|
||||||
for (int radius = 0; radius < 100; radius++) {
|
for (int radius = 0; radius < 3; radius++) {
|
||||||
for (int x = loc.getBlockX() - radius; x <= loc.getBlockX() + radius; x++) {
|
for (int x = loc.getBlockX() - radius; x <= loc.getBlockX() + radius; x++) {
|
||||||
for (int z = loc.getBlockZ() - radius; z <= loc.getBlockZ() + radius; z++) {
|
for (int z = loc.getBlockZ() - radius; z <= loc.getBlockZ() + radius; z++) {
|
||||||
if (!((x > loc.getBlockX() - radius && x < loc.getBlockX() + radius)
|
if (!((x > loc.getBlockX() - radius && x < loc.getBlockX() + radius)
|
||||||
@ -78,7 +83,7 @@ public class Roof extends MinMaxXZ {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!roofFound) return false;
|
||||||
// Record the height
|
// Record the height
|
||||||
this.height = loc.getBlockY();
|
this.height = loc.getBlockY();
|
||||||
// Now we have a roof block, find how far we can go NSWE
|
// Now we have a roof block, find how far we can go NSWE
|
||||||
@ -106,9 +111,9 @@ public class Roof extends MinMaxXZ {
|
|||||||
// Repeat until nothing changes
|
// Repeat until nothing changes
|
||||||
} while (minx != minX || maxx != maxX || minz != minZ || maxz != maxZ);
|
} while (minx != minX || maxx != maxX || minz != minZ || maxz != maxZ);
|
||||||
// That's as much as we can do!
|
// That's as much as we can do!
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This takes any location and tries to go as far as possible in NWSE directions finding contiguous roof blocks
|
* This takes any location and tries to go as far as possible in NWSE directions finding contiguous roof blocks
|
||||||
* up to 100 in any direction
|
* up to 100 in any direction
|
||||||
|
@ -76,6 +76,13 @@ public class RoofTest {
|
|||||||
// Test
|
// Test
|
||||||
roof = new Roof(location);
|
roof = new Roof(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNoGlass() {
|
||||||
|
when(block.getType()).thenReturn(Material.AIR);
|
||||||
|
roof = new Roof(location);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#getMinX()}.
|
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#getMinX()}.
|
||||||
|
Loading…
Reference in New Issue
Block a user