Skip to content

Commit

Permalink
Fixed issue where greenhouses could not be created below y=0 (#95)
Browse files Browse the repository at this point in the history
* 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()
  • Loading branch information
Zorua162 committed Oct 30, 2022
1 parent 8af2b20 commit 61478ff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Walls findWalls(CompletableFuture<Walls> r, Roof roof) {
// 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();
Expand All @@ -85,7 +85,7 @@ Walls findWalls(CompletableFuture<Walls> r, Roof roof) {
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;
Expand Down Expand Up @@ -159,7 +159,7 @@ void lookAtBlockFaces(WallFinder wf, int x, int y, int z) {
}
}

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 {
Expand All @@ -172,7 +172,7 @@ int getFloorY(int y, int minX, int maxX, int minZ, int maxZ) {
}
}

} while( y-- > 0 && wallBlockCount > 0);
} while( y-- > minY && wallBlockCount > 0);
return y + 1;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,23 +177,23 @@ public void testLookAtBlockFacesNoGlass() {
}

/**
* 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(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
public void testGetFloorY() {
when(cache.getBlockType(anyInt(), anyInt(), anyInt())).thenReturn(Material.GLASS, Material.GLASS,
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));
}

/**
Expand Down

0 comments on commit 61478ff

Please sign in to comment.