Made the world floor change work with different lower world limits by using World#getMinHeight()

This commit is contained in:
zorua162 2022-10-27 18:42:55 +01:00
parent 092d106277
commit 4b9012bbb2
2 changed files with 9 additions and 9 deletions

View File

@ -69,7 +69,7 @@ public class Walls extends MinMaxXZ {
// The player is under the roof
// Assume the player is inside the greenhouse they are trying to create
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
WallFinder wf = new WallFinder();
minX = loc.getBlockX();
@ -85,7 +85,7 @@ public class Walls extends MinMaxXZ {
minZ--;
maxZ++;
// 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
Bukkit.getScheduler().runTask(BentoBox.getInstance(), () -> r.complete(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
int wallBlockCount;
do {
@ -172,7 +172,7 @@ public class Walls extends MinMaxXZ {
}
}
} while( y-- > -64 && wallBlockCount > 0);
} while( y-- > minY && wallBlockCount > 0);
return y + 1;
}

View File

@ -91,7 +91,7 @@ public class WallsTest {
@Test
public void testFindWalls() {
walls.findWalls(r, roof);
assertEquals("Walls [minX=9, maxX=11, minZ=9, maxZ=11, floor=-64]", walls.toString());
assertEquals("Walls [minX=-2, maxX=11, minZ=-2, maxZ=11, floor=0]", walls.toString());
}
/**
@ -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
public void testGetFloorYZeroY() {
assertEquals(-64, 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
public void testGetFloorY() {
@ -193,7 +193,7 @@ public class WallsTest {
Material.GLASS, Material.GLASS,
Material.GLASS, Material.GLASS,
Material.AIR);
assertEquals(8, walls.getFloorY(10, 0, 1, 0, 1));
assertEquals(8, walls.getFloorY(10, 0, 1, 0, 1, -64));
}
/**