Skip to content

Commit

Permalink
Mobs can spawn on blocks with plants on them.
Browse files Browse the repository at this point in the history
Fixes #56
  • Loading branch information
tastybento committed Aug 22, 2020
1 parent 56b1a9a commit a7e4540
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ public int getWaterCoverage() {
* @return true if successful
*/
public boolean growPlant(Block bl) {
if (bl.getType() != Material.AIR) {
if (!bl.isEmpty()) {
return false;
}
return getRandomPlant().map(p -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private List<Block> getAvailableBlocks(Greenhouse gh) {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void setUp() throws Exception {
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
Expand All @@ -125,7 +125,7 @@ public void setUp() throws Exception {
// 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%
Expand Down Expand Up @@ -516,6 +516,7 @@ public void testGrowPlantNotAir() {
@Test
public void testGrowPlantNoPlants() {
when(block.getType()).thenReturn(Material.AIR);
when(block.isEmpty()).thenReturn(true);
assertFalse(br.growPlant(block));
}

Expand All @@ -526,6 +527,7 @@ public void testGrowPlantNoPlants() {
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));
}
Expand All @@ -537,8 +539,10 @@ public void testGrowPlantPlantsYZero() {
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));
Expand All @@ -555,6 +559,7 @@ public void testGrowPlantPlantsDoublePlant() {
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);
Expand All @@ -575,6 +580,7 @@ public void testGrowPlantPlantsDoublePlantNoRoom() {
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);
Expand Down

0 comments on commit a7e4540

Please sign in to comment.