From a7e454065db25c13fb7c3880011cdf9de6d08537 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 22 Aug 2020 15:22:14 -0700 Subject: [PATCH] Mobs can spawn on blocks with plants on them. Fixes https://github.com/BentoBoxWorld/Greenhouses/issues/56 --- .../bentobox/greenhouses/greenhouse/BiomeRecipe.java | 2 +- .../greenhouses/managers/EcoSystemManager.java | 2 +- .../greenhouses/greenhouse/BiomeRecipeTest.java | 10 ++++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java b/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java index d179e99..f309a16 100644 --- a/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java +++ b/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java @@ -370,7 +370,7 @@ public class BiomeRecipe implements Comparable { * @return true if successful */ public boolean growPlant(Block bl) { - if (bl.getType() != Material.AIR) { + if (!bl.isEmpty()) { return false; } return getRandomPlant().map(p -> { diff --git a/src/main/java/world/bentobox/greenhouses/managers/EcoSystemManager.java b/src/main/java/world/bentobox/greenhouses/managers/EcoSystemManager.java index 9f91d19..4a7c866 100644 --- a/src/main/java/world/bentobox/greenhouses/managers/EcoSystemManager.java +++ b/src/main/java/world/bentobox/greenhouses/managers/EcoSystemManager.java @@ -180,7 +180,7 @@ public class EcoSystemManager { for (int z = (int)gh.getBoundingBox().getMinZ() + 1; z < (int)gh.getBoundingBox().getMaxZ(); z++) { for (int y = (int)gh.getBoundingBox().getMaxY() - 2; y >= (int)gh.getBoundingBox().getMinY(); y--) { Block b = gh.getLocation().getWorld().getBlockAt(x, y, z); - if (!b.getType().equals(Material.AIR) && b.getRelative(BlockFace.UP).getType().equals(Material.AIR)) { + if ((!b.isEmpty() && !b.isPassable()) && (b.getRelative(BlockFace.UP).isEmpty() || b.getRelative(BlockFace.UP).isPassable())) { result.add(b.getRelative(BlockFace.UP)); break; } diff --git a/src/test/java/world/bentobox/greenhouses/greenhouse/BiomeRecipeTest.java b/src/test/java/world/bentobox/greenhouses/greenhouse/BiomeRecipeTest.java index a969db6..240698d 100644 --- a/src/test/java/world/bentobox/greenhouses/greenhouse/BiomeRecipeTest.java +++ b/src/test/java/world/bentobox/greenhouses/greenhouse/BiomeRecipeTest.java @@ -111,7 +111,7 @@ public class BiomeRecipeTest { when(block.getLocation()).thenReturn(location); when(location.clone()).thenReturn(location); when(location.add(any(Vector.class))).thenReturn(location); - + // Plugin when(addon.getPlugin()).thenReturn(plugin); // Manager @@ -125,7 +125,7 @@ public class BiomeRecipeTest { // Settings when(addon.getSettings()).thenReturn(settings); when(settings.isStartupLog()).thenReturn(true); - + // Set up default recipe br = new BiomeRecipe(addon, type, 0); br.setIcecoverage(2); // 1% @@ -516,6 +516,7 @@ public class BiomeRecipeTest { @Test public void testGrowPlantNoPlants() { when(block.getType()).thenReturn(Material.AIR); + when(block.isEmpty()).thenReturn(true); assertFalse(br.growPlant(block)); } @@ -526,6 +527,7 @@ public class BiomeRecipeTest { public void testGrowPlantPlantsYZero() { when(block.getY()).thenReturn(0); when(block.getType()).thenReturn(Material.AIR); + when(block.isEmpty()).thenReturn(true); assertTrue(br.addPlants(Material.BAMBOO_SAPLING, 100, Material.GRASS_BLOCK)); assertFalse(br.growPlant(block)); } @@ -537,8 +539,10 @@ public class BiomeRecipeTest { public void testGrowPlantPlants() { when(block.getY()).thenReturn(10); when(block.getType()).thenReturn(Material.AIR); + when(block.isEmpty()).thenReturn(true); Block ob = mock(Block.class); when(ob.getType()).thenReturn(Material.GRASS_BLOCK); + when(block.getRelative(any())).thenReturn(ob); assertTrue(br.addPlants(Material.BAMBOO_SAPLING, 100, Material.GRASS_BLOCK)); assertTrue(br.growPlant(block)); @@ -555,6 +559,7 @@ public class BiomeRecipeTest { when(Bukkit.createBlockData(any(Material.class))).thenReturn(bisected); when(block.getY()).thenReturn(10); when(block.getType()).thenReturn(Material.AIR); + when(block.isEmpty()).thenReturn(true); Block ob = mock(Block.class); when(ob.getType()).thenReturn(Material.GRASS_BLOCK); when(block.getRelative(eq(BlockFace.DOWN))).thenReturn(ob); @@ -575,6 +580,7 @@ public class BiomeRecipeTest { when(Bukkit.createBlockData(any(Material.class))).thenReturn(bisected); when(block.getY()).thenReturn(10); when(block.getType()).thenReturn(Material.AIR); + when(block.isEmpty()).thenReturn(true); Block ob = mock(Block.class); when(ob.getType()).thenReturn(Material.GRASS_BLOCK); when(block.getRelative(eq(BlockFace.DOWN))).thenReturn(ob);