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
*/
public boolean growPlant(Block bl) {
if (bl.getType() != Material.AIR) {
if (!bl.isEmpty()) {
return false;
}
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 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;
}

View File

@ -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);