Fixed issue where greenhouses could not be created below y=0 (#95)

* Fixed issue where greenhouses could not be greated below y=0

* Made the world floor change work with different lower world limits by using World#getMinHeight()
This commit is contained in:
Zorua162 2022-10-30 16:50:40 +00:00 committed by GitHub
parent 8af2b2057d
commit 61478ff4d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 8 deletions

View File

@ -69,7 +69,7 @@ public class Walls extends MinMaxXZ {
// The player is under the roof // The player is under the roof
// Assume the player is inside the greenhouse they are trying to create // Assume the player is inside the greenhouse they are trying to create
final Location loc = roof.getLocation(); final Location loc = roof.getLocation();
floor = getFloorY(roof.getHeight(), roof.getMinX(), roof.getMaxX(), roof.getMinZ(), roof.getMaxZ()); floor = getFloorY(roof.getHeight(), roof.getMinX(), roof.getMaxX(), roof.getMinZ(), roof.getMaxZ(), loc.getWorld().getMinHeight());
// Now start with the player's x and z location // Now start with the player's x and z location
WallFinder wf = new WallFinder(); WallFinder wf = new WallFinder();
minX = loc.getBlockX(); minX = loc.getBlockX();
@ -85,7 +85,7 @@ public class Walls extends MinMaxXZ {
minZ--; minZ--;
maxZ++; maxZ++;
// Find the floor again, only looking within the walls // Find the floor again, only looking within the walls
floor = getFloorY(roof.getHeight(), minX, maxX, minZ,maxZ); floor = getFloorY(roof.getHeight(), minX, maxX, minZ,maxZ,loc.getWorld().getMinHeight());
// Complete on main thread // Complete on main thread
Bukkit.getScheduler().runTask(BentoBox.getInstance(), () -> r.complete(this)); Bukkit.getScheduler().runTask(BentoBox.getInstance(), () -> r.complete(this));
return this; return this;
@ -159,7 +159,7 @@ public class Walls extends MinMaxXZ {
} }
} }
int getFloorY(int y, int minX, int maxX, int minZ, int maxZ) { int getFloorY(int y, int minX, int maxX, int minZ, int maxZ, int minY) {
// Find the floor - defined as the last y under the roof where there are no wall blocks // Find the floor - defined as the last y under the roof where there are no wall blocks
int wallBlockCount; int wallBlockCount;
do { do {
@ -172,7 +172,7 @@ public class Walls extends MinMaxXZ {
} }
} }
} while( y-- > 0 && wallBlockCount > 0); } while( y-- > minY && wallBlockCount > 0);
return y + 1; return y + 1;
} }

View File

@ -177,15 +177,15 @@ public class WallsTest {
} }
/** /**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Walls#getFloorY(int, int, int, int, int)}. * Test method for {@link world.bentobox.greenhouses.greenhouse.Walls#getFloorY(int, int, int, int, int, int)}.
*/ */
@Test @Test
public void testGetFloorYZeroY() { public void testGetFloorYZeroY() {
assertEquals(0, walls.getFloorY(10, 0, 1, 0, 1)); assertEquals(-64, walls.getFloorY(10, 0, 1, 0, 1, -64));
} }
/** /**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Walls#getFloorY(int, int, int, int, int)}. * Test method for {@link world.bentobox.greenhouses.greenhouse.Walls#getFloorY(int, int, int, int, int, int)}.
*/ */
@Test @Test
public void testGetFloorY() { public void testGetFloorY() {
@ -193,7 +193,7 @@ public class WallsTest {
Material.GLASS, Material.GLASS, Material.GLASS, Material.GLASS,
Material.GLASS, Material.GLASS, Material.GLASS, Material.GLASS,
Material.AIR); Material.AIR);
assertEquals(8, walls.getFloorY(10, 0, 1, 0, 1)); assertEquals(8, walls.getFloorY(10, 0, 1, 0, 1, -64));
} }
/** /**