Mobs can spawn on blocks with plants on them.

Fixes https://github.com/BentoBoxWorld/Greenhouses/issues/56
This commit is contained in:
tastybento 2020-08-22 15:22:14 -07:00
parent 56b1a9aa93
commit a7e454065d
3 changed files with 10 additions and 4 deletions

View File

@ -370,7 +370,7 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {
* @return true if successful * @return true if successful
*/ */
public boolean growPlant(Block bl) { public boolean growPlant(Block bl) {
if (bl.getType() != Material.AIR) { if (!bl.isEmpty()) {
return false; return false;
} }
return getRandomPlant().map(p -> { return getRandomPlant().map(p -> {

View File

@ -180,7 +180,7 @@ public class EcoSystemManager {
for (int z = (int)gh.getBoundingBox().getMinZ() + 1; z < (int)gh.getBoundingBox().getMaxZ(); z++) { 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--) { for (int y = (int)gh.getBoundingBox().getMaxY() - 2; y >= (int)gh.getBoundingBox().getMinY(); y--) {
Block b = gh.getLocation().getWorld().getBlockAt(x, y, z); 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)); result.add(b.getRelative(BlockFace.UP));
break; break;
} }

View File

@ -111,7 +111,7 @@ public class BiomeRecipeTest {
when(block.getLocation()).thenReturn(location); when(block.getLocation()).thenReturn(location);
when(location.clone()).thenReturn(location); when(location.clone()).thenReturn(location);
when(location.add(any(Vector.class))).thenReturn(location); when(location.add(any(Vector.class))).thenReturn(location);
// Plugin // Plugin
when(addon.getPlugin()).thenReturn(plugin); when(addon.getPlugin()).thenReturn(plugin);
// Manager // Manager
@ -125,7 +125,7 @@ public class BiomeRecipeTest {
// Settings // Settings
when(addon.getSettings()).thenReturn(settings); when(addon.getSettings()).thenReturn(settings);
when(settings.isStartupLog()).thenReturn(true); when(settings.isStartupLog()).thenReturn(true);
// Set up default recipe // Set up default recipe
br = new BiomeRecipe(addon, type, 0); br = new BiomeRecipe(addon, type, 0);
br.setIcecoverage(2); // 1% br.setIcecoverage(2); // 1%
@ -516,6 +516,7 @@ public class BiomeRecipeTest {
@Test @Test
public void testGrowPlantNoPlants() { public void testGrowPlantNoPlants() {
when(block.getType()).thenReturn(Material.AIR); when(block.getType()).thenReturn(Material.AIR);
when(block.isEmpty()).thenReturn(true);
assertFalse(br.growPlant(block)); assertFalse(br.growPlant(block));
} }
@ -526,6 +527,7 @@ public class BiomeRecipeTest {
public void testGrowPlantPlantsYZero() { public void testGrowPlantPlantsYZero() {
when(block.getY()).thenReturn(0); when(block.getY()).thenReturn(0);
when(block.getType()).thenReturn(Material.AIR); when(block.getType()).thenReturn(Material.AIR);
when(block.isEmpty()).thenReturn(true);
assertTrue(br.addPlants(Material.BAMBOO_SAPLING, 100, Material.GRASS_BLOCK)); assertTrue(br.addPlants(Material.BAMBOO_SAPLING, 100, Material.GRASS_BLOCK));
assertFalse(br.growPlant(block)); assertFalse(br.growPlant(block));
} }
@ -537,8 +539,10 @@ public class BiomeRecipeTest {
public void testGrowPlantPlants() { public void testGrowPlantPlants() {
when(block.getY()).thenReturn(10); when(block.getY()).thenReturn(10);
when(block.getType()).thenReturn(Material.AIR); when(block.getType()).thenReturn(Material.AIR);
when(block.isEmpty()).thenReturn(true);
Block ob = mock(Block.class); Block ob = mock(Block.class);
when(ob.getType()).thenReturn(Material.GRASS_BLOCK); when(ob.getType()).thenReturn(Material.GRASS_BLOCK);
when(block.getRelative(any())).thenReturn(ob); when(block.getRelative(any())).thenReturn(ob);
assertTrue(br.addPlants(Material.BAMBOO_SAPLING, 100, Material.GRASS_BLOCK)); assertTrue(br.addPlants(Material.BAMBOO_SAPLING, 100, Material.GRASS_BLOCK));
assertTrue(br.growPlant(block)); assertTrue(br.growPlant(block));
@ -555,6 +559,7 @@ public class BiomeRecipeTest {
when(Bukkit.createBlockData(any(Material.class))).thenReturn(bisected); when(Bukkit.createBlockData(any(Material.class))).thenReturn(bisected);
when(block.getY()).thenReturn(10); when(block.getY()).thenReturn(10);
when(block.getType()).thenReturn(Material.AIR); when(block.getType()).thenReturn(Material.AIR);
when(block.isEmpty()).thenReturn(true);
Block ob = mock(Block.class); Block ob = mock(Block.class);
when(ob.getType()).thenReturn(Material.GRASS_BLOCK); when(ob.getType()).thenReturn(Material.GRASS_BLOCK);
when(block.getRelative(eq(BlockFace.DOWN))).thenReturn(ob); when(block.getRelative(eq(BlockFace.DOWN))).thenReturn(ob);
@ -575,6 +580,7 @@ public class BiomeRecipeTest {
when(Bukkit.createBlockData(any(Material.class))).thenReturn(bisected); when(Bukkit.createBlockData(any(Material.class))).thenReturn(bisected);
when(block.getY()).thenReturn(10); when(block.getY()).thenReturn(10);
when(block.getType()).thenReturn(Material.AIR); when(block.getType()).thenReturn(Material.AIR);
when(block.isEmpty()).thenReturn(true);
Block ob = mock(Block.class); Block ob = mock(Block.class);
when(ob.getType()).thenReturn(Material.GRASS_BLOCK); when(ob.getType()).thenReturn(Material.GRASS_BLOCK);
when(block.getRelative(eq(BlockFace.DOWN))).thenReturn(ob); when(block.getRelative(eq(BlockFace.DOWN))).thenReturn(ob);