diff --git a/src/main/java/world/bentobox/greenhouses/greenhouse/Roof.java b/src/main/java/world/bentobox/greenhouses/greenhouse/Roof.java index 2f6b053..0e3eb7b 100644 --- a/src/main/java/world/bentobox/greenhouses/greenhouse/Roof.java +++ b/src/main/java/world/bentobox/greenhouses/greenhouse/Roof.java @@ -48,38 +48,35 @@ public class Roof extends MinMaxXZ { // 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 roofFound = false; - // This does a ever-growing check around the player to find a roof block. It is possible for the player + + // This does a ever-growing check around the player to find a wall block. It is possible for the player // to be outside the greenhouse in this situation, so a check is done later to make sure the player is inside int roofY = loc.getBlockY(); + for (int y = roofY; y < world.getMaxHeight(); y++) { + if (ROOF_BLOCKS.contains(world.getBlockAt(loc.getBlockX(),y,loc.getBlockZ()).getType())) { + roofFound = true; + loc = new Location(world,loc.getBlockX(),y,loc.getBlockZ()); + break; + } + } // 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 - for (int radius = 0; radius < 3; radius++) { - for (int x = loc.getBlockX() - radius; x <= loc.getBlockX() + radius; x++) { - for (int z = loc.getBlockZ() - radius; z <= loc.getBlockZ() + radius; z++) { - if (!((x > loc.getBlockX() - radius && x < loc.getBlockX() + radius) - && (z > loc.getBlockZ() - radius && z < loc.getBlockZ() + radius))) { + for (int radius = 0; radius < 3 && !roofFound; radius++) { + for (int x = loc.getBlockX() - radius; x <= loc.getBlockX() + radius && !roofFound; x++) { + for (int z = loc.getBlockZ() - radius; z <= loc.getBlockZ() + radius && !roofFound; z++) { + if (!((x > loc.getBlockX() - radius && x < loc.getBlockX() + radius) && (z > loc.getBlockZ() - radius && z < loc.getBlockZ() + radius))) { Block b = world.getBlockAt(x, roofY, z); if (!Walls.WALL_BLOCKS.contains(b.getType())) { // Look up - for (int y = roofY; y < world.getMaxHeight(); y++) { + for (int y = roofY; y < world.getMaxHeight() && !roofFound; y++) { if (ROOF_BLOCKS.contains(world.getBlockAt(x,y,z).getType())) { roofFound = true; loc = new Location(world,x,y,z); - break; } } } } - if (roofFound) { - break; - } } - if (roofFound) { - break; - } - } - if (roofFound) { - break; } } if (!roofFound) return false; diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml index 4240129..f23d848 100644 --- a/src/main/resources/locales/en-US.yml +++ b/src/main/resources/locales/en-US.yml @@ -65,6 +65,7 @@ greenhouses: FAIL_NO_LAVA: "&cLava is required to make this recipe" FAIL_NO_WATER: "&cWater is required to make this recipe" FAIL_INSUFFICIENT_BLOCKS: "&cMore blocks are required to make this recipe!" + FAIL_OVERLAPPING: "&cGreenhouses cannot share walls, sorry." success: "&2You successfully made a [biome] biome greenhouse! Biome will sync at next teleport or login." missing-blocks: "&cMissing [material] x [number]" unknown-recipe: "&cUnknown recipe" diff --git a/src/test/java/world/bentobox/greenhouses/greenhouse/RoofTest.java b/src/test/java/world/bentobox/greenhouses/greenhouse/RoofTest.java index 1b457de..316386d 100644 --- a/src/test/java/world/bentobox/greenhouses/greenhouse/RoofTest.java +++ b/src/test/java/world/bentobox/greenhouses/greenhouse/RoofTest.java @@ -39,7 +39,7 @@ public class RoofTest { public void setUp() throws Exception { when(world.getMaxHeight()).thenReturn(255); // Block - when(block.getType()).thenReturn(Material.AIR, Material.AIR, Material.AIR, Material.AIR, Material.AIR, + when(block.getType()).thenReturn(Material.AIR, Material.AIR, Material.AIR, Material.AIR, Material.GLASS, Material.GLASS, Material.GLASS, Material.GLASS, Material.GLASS, Material.GLASS, Material.GLASS, Material.GLASS, Material.GLASS, Material.GLASS, Material.GLASS, Material.GLASS, @@ -76,12 +76,12 @@ public class RoofTest { // Test roof = new Roof(location); } - + @Test public void testNoGlass() { when(block.getType()).thenReturn(Material.AIR); roof = new Roof(location); - + } /**