Blocks only convert based on blocks inside the greenhouse.
Fixes https://github.com/BentoBoxWorld/Greenhouses/issues/63
This commit is contained in:
parent
2260e2176d
commit
0bbc25cfd1
|
@ -214,14 +214,18 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if block should be converted
|
* Check if block should be converted
|
||||||
|
* @param gh - greenhouse
|
||||||
* @param b - block to check
|
* @param b - block to check
|
||||||
*/
|
*/
|
||||||
public void convertBlock(Block b) {
|
public void convertBlock(Greenhouse gh, Block b) {
|
||||||
conversionBlocks.get(b.getType()).stream().filter(Objects::nonNull)
|
conversionBlocks.get(b.getType()).stream().filter(Objects::nonNull)
|
||||||
.filter(bc -> random.nextDouble() < bc.getProbability())
|
.filter(bc -> random.nextDouble() < bc.getProbability())
|
||||||
.forEach(bc -> {
|
.forEach(bc -> {
|
||||||
// Check if the block is in the right area, up, down, n,s,e,w
|
// Check if the block is in the right area, up, down, n,s,e,w
|
||||||
if (ADJ_BLOCKS.stream().map(b::getRelative).map(Block::getType).anyMatch(m -> bc.getLocalMaterial() == null || m == bc.getLocalMaterial())) {
|
if (ADJ_BLOCKS.stream().map(b::getRelative)
|
||||||
|
.filter(r -> gh.contains(r.getLocation()))
|
||||||
|
.map(Block::getType)
|
||||||
|
.anyMatch(m -> bc.getLocalMaterial() == null || m == bc.getLocalMaterial())) {
|
||||||
// Convert!
|
// Convert!
|
||||||
b.setType(bc.getNewMaterial());
|
b.setType(bc.getNewMaterial());
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,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 > 0; y--) {
|
for (int y = (int)gh.getBoundingBox().getMaxY() - 2; y >= (int)gh.getBoundingBox().getMinY() && y > 0; y--) {
|
||||||
Block b = gh.getWorld().getBlockAt(x, y, z).getRelative(BlockFace.DOWN);
|
Block b = gh.getWorld().getBlockAt(x, y, z).getRelative(BlockFace.DOWN);
|
||||||
if (!b.isEmpty()) gh.getBiomeRecipe().convertBlock(b);
|
if (!b.isEmpty()) gh.getBiomeRecipe().convertBlock(gh, b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,6 +99,7 @@ public class BiomeRecipeTest {
|
||||||
bb = new BoundingBox(10, 100, 10, 20, 120, 20);
|
bb = new BoundingBox(10, 100, 10, 20, 120, 20);
|
||||||
when(gh.getBoundingBox()).thenReturn(bb);
|
when(gh.getBoundingBox()).thenReturn(bb);
|
||||||
when(gh.getWorld()).thenReturn(world);
|
when(gh.getWorld()).thenReturn(world);
|
||||||
|
when(gh.contains(any())).thenReturn(true);
|
||||||
when(world.getBlockAt(anyInt(), anyInt(), anyInt())).thenReturn(block);
|
when(world.getBlockAt(anyInt(), anyInt(), anyInt())).thenReturn(block);
|
||||||
// Block
|
// Block
|
||||||
when(block.getType()).thenReturn(Material.AIR,
|
when(block.getType()).thenReturn(Material.AIR,
|
||||||
|
@ -246,10 +247,29 @@ public class BiomeRecipeTest {
|
||||||
Block ab = mock(Block.class);
|
Block ab = mock(Block.class);
|
||||||
when(ab.getType()).thenReturn(Material.WATER);
|
when(ab.getType()).thenReturn(Material.WATER);
|
||||||
when(b.getRelative(any())).thenReturn(ab);
|
when(b.getRelative(any())).thenReturn(ab);
|
||||||
br.convertBlock(b);
|
br.convertBlock(gh, b);
|
||||||
verify(b).setType(Material.CLAY);
|
verify(b).setType(Material.CLAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link world.bentobox.greenhouses.greenhouse.BiomeRecipe#convertBlock(org.bukkit.block.Block)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testConvertBlockNotInGreenhouse() {
|
||||||
|
// Setup
|
||||||
|
this.testAddConvBlocks();
|
||||||
|
// Mock
|
||||||
|
Block b = mock(Block.class);
|
||||||
|
when(b.getType()).thenReturn(Material.SAND);
|
||||||
|
Block ab = mock(Block.class);
|
||||||
|
when(ab.getType()).thenReturn(Material.WATER);
|
||||||
|
when(b.getRelative(any())).thenReturn(ab);
|
||||||
|
when(ab.getLocation()).thenReturn(location);
|
||||||
|
when(gh.contains(any())).thenReturn(false);
|
||||||
|
br.convertBlock(gh, b);
|
||||||
|
verify(b, never()).setType(any());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.greenhouses.greenhouse.BiomeRecipe#convertBlock(org.bukkit.block.Block)}.
|
* Test method for {@link world.bentobox.greenhouses.greenhouse.BiomeRecipe#convertBlock(org.bukkit.block.Block)}.
|
||||||
*/
|
*/
|
||||||
|
@ -263,7 +283,7 @@ public class BiomeRecipeTest {
|
||||||
Block ab = mock(Block.class);
|
Block ab = mock(Block.class);
|
||||||
when(ab.getType()).thenReturn(Material.SAND);
|
when(ab.getType()).thenReturn(Material.SAND);
|
||||||
when(b.getRelative(any())).thenReturn(ab);
|
when(b.getRelative(any())).thenReturn(ab);
|
||||||
br.convertBlock(b);
|
br.convertBlock(gh, b);
|
||||||
verify(b, never()).setType(Material.CLAY);
|
verify(b, never()).setType(Material.CLAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,7 +295,7 @@ public class BiomeRecipeTest {
|
||||||
// Mock
|
// Mock
|
||||||
Block b = mock(Block.class);
|
Block b = mock(Block.class);
|
||||||
when(b.getType()).thenReturn(Material.SAND);
|
when(b.getType()).thenReturn(Material.SAND);
|
||||||
br.convertBlock(b);
|
br.convertBlock(gh, b);
|
||||||
verify(b, never()).setType(Material.CLAY);
|
verify(b, never()).setType(Material.CLAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,7 +317,7 @@ public class BiomeRecipeTest {
|
||||||
Block ab = mock(Block.class);
|
Block ab = mock(Block.class);
|
||||||
when(ab.getType()).thenReturn(Material.WATER);
|
when(ab.getType()).thenReturn(Material.WATER);
|
||||||
when(b.getRelative(any())).thenReturn(ab);
|
when(b.getRelative(any())).thenReturn(ab);
|
||||||
br.convertBlock(b);
|
br.convertBlock(gh, b);
|
||||||
verify(b, never()).setType(Material.CLAY);
|
verify(b, never()).setType(Material.CLAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue