mirror of
https://github.com/BentoBoxWorld/Greenhouses.git
synced 2024-11-25 03:55:29 +01:00
Code clean up.
This commit is contained in:
parent
ca4f1a3f43
commit
a7eeef7edc
@ -287,8 +287,8 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {
|
||||
Material bType = b.getType();
|
||||
// Check if there is a block conversion for this block, as while the rest of the method won't do anything if .get() returns nothing anyway it still seems to be quite expensive
|
||||
if(conversionBlocks.keySet().contains(bType)) {
|
||||
for(GreenhouseBlockConversions conversion_option : conversionBlocks.get(bType)) {
|
||||
rollTheDice(b, conversion_option);
|
||||
for(GreenhouseBlockConversions conversionOption : conversionBlocks.get(bType)) {
|
||||
rollTheDice(b, conversionOption);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -450,7 +450,10 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {
|
||||
// Grow a random plant that can grow
|
||||
double r = random.nextDouble();
|
||||
Double key = underwater ? underwaterPlants.ceilingKey(r) : plantTree.ceilingKey(r);
|
||||
return key == null ? Optional.empty() : Optional.ofNullable(underwater ? underwaterPlants.get(key) : plantTree.get(key));
|
||||
if (key == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.ofNullable(underwater ? underwaterPlants.get(key) : plantTree.get(key));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -476,12 +479,10 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {
|
||||
public boolean growPlant(GrowthBlock block, boolean underwater) {
|
||||
Block bl = block.block();
|
||||
return getRandomPlant(underwater).map(p -> {
|
||||
if (bl.getY() != 0 && canGrowOn(block, p)) {
|
||||
if (plantIt(bl, p)) {
|
||||
if (bl.getY() != 0 && canGrowOn(block, p) && plantIt(bl, p)) {
|
||||
bl.getWorld().spawnParticle(Particle.SNOWBALL, bl.getLocation(), 10, 2, 2, 2);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}).orElse(false);
|
||||
}
|
||||
@ -569,14 +570,12 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {
|
||||
BlockFace d = null;
|
||||
boolean waterLogged = false;
|
||||
for (BlockFace adj : ADJ_BLOCKS) {
|
||||
if (b.getRelative(adj).getType().equals(Material.AIR)) {
|
||||
d = adj;
|
||||
break;
|
||||
}
|
||||
// Lichen can grow under water too
|
||||
if (b.getRelative(adj).getType().equals(Material.WATER)) {
|
||||
Material type = b.getRelative(adj).getType();
|
||||
if (type.equals(Material.AIR) || type.equals(Material.WATER)) {
|
||||
d = adj;
|
||||
if (type.equals(Material.WATER)) {
|
||||
waterLogged = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -95,17 +95,17 @@ public class EcoSystemManager {
|
||||
return;
|
||||
}
|
||||
final BoundingBox ibb = gh.getInternalBoundingBox();
|
||||
int gh_min_x = NumberConversions.floor(ibb.getMinX());
|
||||
int gh_max_x = NumberConversions.floor(ibb.getMaxX());
|
||||
int gh_min_y = NumberConversions.floor(gh.getBoundingBox().getMinY()); // Note: this gets the floor
|
||||
int gh_max_y = NumberConversions.floor(ibb.getMaxY());
|
||||
int gh_min_z = NumberConversions.floor(ibb.getMinZ());
|
||||
int gh_max_z = NumberConversions.floor(ibb.getMaxZ());
|
||||
int ghMinX = NumberConversions.floor(ibb.getMinX());
|
||||
int ghMaxX = NumberConversions.floor(ibb.getMaxX());
|
||||
int ghMinY = NumberConversions.floor(gh.getBoundingBox().getMinY()); // Note: this gets the floor
|
||||
int ghMaxY = NumberConversions.floor(ibb.getMaxY());
|
||||
int ghMinZ = NumberConversions.floor(ibb.getMinZ());
|
||||
int ghMaxZ = NumberConversions.floor(ibb.getMaxZ());
|
||||
BiomeRecipe biomeRecipe = gh.getBiomeRecipe();
|
||||
|
||||
for (int x = gh_min_x; x < gh_max_x; x++) {
|
||||
for (int z = gh_min_z; z < gh_max_z; z++) {
|
||||
for (int y = gh_min_y; y < gh_max_y; y++) {
|
||||
for (int x = ghMinX; x < ghMaxX; x++) {
|
||||
for (int z = ghMinZ; z < ghMaxZ; z++) {
|
||||
for (int y = ghMinY; y < ghMaxY; y++) {
|
||||
Block b = world.getBlockAt(x, y, z);
|
||||
|
||||
if(!b.isEmpty()) {
|
||||
|
@ -34,7 +34,6 @@ public class GreenhouseFinder {
|
||||
* This is the count of the various items
|
||||
*/
|
||||
private CounterCheck counterCheck = new CounterCheck();
|
||||
private Roof roof;
|
||||
|
||||
static class CounterCheck {
|
||||
int doorCount;
|
||||
@ -63,7 +62,7 @@ public class GreenhouseFinder {
|
||||
// Get a world cache
|
||||
AsyncWorldCache cache = new AsyncWorldCache(addon, location.getWorld());
|
||||
// Find the roof
|
||||
roof = new Roof(cache, location, addon);
|
||||
Roof roof = new Roof(cache, location, addon);
|
||||
roof.findRoof().thenAccept(found -> {
|
||||
if (Boolean.FALSE.equals(found)) {
|
||||
result.add(GreenhouseResult.FAIL_NO_ROOF);
|
||||
|
@ -6,7 +6,6 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
@ -138,7 +137,7 @@ public class GreenhouseMap {
|
||||
* @return a list of all the Greenhouses
|
||||
*/
|
||||
public List<Greenhouse> getGreenhouses() {
|
||||
return greenhouses.values().stream().flatMap(List::stream).collect(Collectors.toList());
|
||||
return greenhouses.values().stream().flatMap(List::stream).toList();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -185,12 +185,12 @@ public class RecipeManager {
|
||||
}
|
||||
// Get the list of conversions
|
||||
for (String oldMat : biomeRecipeConfig.getStringList("conversion-list")) {
|
||||
parseConversionList(oldMat, conversionSec, b);
|
||||
parseConversionList(oldMat, b);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void parseConversionList(String oldMat, ConfigurationSection conversionSec, BiomeRecipe b) {
|
||||
private void parseConversionList(String oldMat, BiomeRecipe b) {
|
||||
try {
|
||||
// Split the string
|
||||
String[] split = oldMat.split(":");
|
||||
|
@ -5,7 +5,6 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ -61,7 +60,7 @@ public class GreenhouseTest {
|
||||
// RecipeManager
|
||||
PowerMockito.mockStatic(RecipeManager.class);
|
||||
when(br.getName()).thenReturn("test");
|
||||
when(RecipeManager.getBiomeRecipies(eq("test"))).thenReturn(Optional.of(br));
|
||||
when(RecipeManager.getBiomeRecipies("test")).thenReturn(Optional.of(br));
|
||||
// Walls
|
||||
when(walls.getMinX()).thenReturn(MINX);
|
||||
when(walls.getMinZ()).thenReturn(MINZ);
|
||||
|
@ -151,7 +151,7 @@ public class BiomeRecipeTest {
|
||||
double convChance = 100D;
|
||||
Material localMaterial = Material.WATER;
|
||||
br.addConvBlocks(oldMaterial, newMaterial, convChance, localMaterial);
|
||||
verify(addon).log(eq(" 100.0% chance for Sand to convert to Clay"));
|
||||
verify(addon).log(" 100.0% chance for Sand to convert to Clay");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -163,7 +163,7 @@ public class BiomeRecipeTest {
|
||||
int mobProbability = 50;
|
||||
Material mobSpawnOn = Material.GRASS_BLOCK;
|
||||
br.addMobs(mobType, mobProbability, mobSpawnOn);
|
||||
verify(addon).log(eq(" 50.0% chance for Cat to spawn on Grass Block."));
|
||||
verify(addon).log(" 50.0% chance for Cat to spawn on Grass Block.");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -177,7 +177,7 @@ public class BiomeRecipeTest {
|
||||
br.addMobs(mobType, mobProbability, mobSpawnOn);
|
||||
br.addMobs(mobType, mobProbability, mobSpawnOn);
|
||||
br.addMobs(mobType, mobProbability, mobSpawnOn);
|
||||
verify(addon).logError(eq("Mob chances add up to > 100% in BADLANDS biome recipe! Skipping CAT"));
|
||||
verify(addon).logError("Mob chances add up to > 100% in BADLANDS biome recipe! Skipping CAT");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -190,7 +190,7 @@ public class BiomeRecipeTest {
|
||||
Material mobSpawnOn = Material.GRASS_BLOCK;
|
||||
br.addMobs(mobType, mobProbability, mobSpawnOn);
|
||||
br.addMobs(mobType, mobProbability, mobSpawnOn);
|
||||
verify(addon).logError(eq("Mob chances add up to > 100% in BADLANDS biome recipe! Skipping CAT"));
|
||||
verify(addon).logError("Mob chances add up to > 100% in BADLANDS biome recipe! Skipping CAT");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -202,7 +202,7 @@ public class BiomeRecipeTest {
|
||||
int plantProbability = 20;
|
||||
Material plantGrowOn = Material.DIRT;
|
||||
br.addPlants(plantMaterial, plantProbability, plantGrowOn);
|
||||
verify(addon).log(eq(" 20.0% chance for Jungle Sapling to grow on Dirt"));
|
||||
verify(addon).log(" 20.0% chance for Jungle Sapling to grow on Dirt");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -215,7 +215,7 @@ public class BiomeRecipeTest {
|
||||
Material plantGrowOn = Material.DIRT;
|
||||
br.addPlants(plantMaterial, plantProbability, plantGrowOn);
|
||||
br.addPlants(plantMaterial, plantProbability, plantGrowOn);
|
||||
verify(addon).logError(eq("Plant chances add up to > 100% in BADLANDS biome recipe! Skipping JUNGLE_SAPLING"));
|
||||
verify(addon).logError("Plant chances add up to > 100% in BADLANDS biome recipe! Skipping JUNGLE_SAPLING");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -226,7 +226,7 @@ public class BiomeRecipeTest {
|
||||
Material blockMaterial = Material.BLACK_CONCRETE;
|
||||
int blockQty = 30;
|
||||
br.addReqBlocks(blockMaterial, blockQty);
|
||||
verify(addon).log(eq(" BLACK_CONCRETE x 30"));
|
||||
verify(addon).log(" BLACK_CONCRETE x 30");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -451,7 +451,7 @@ public class BiomeRecipeTest {
|
||||
|
||||
br.addMobs(mobType, mobProbability, mobSpawnOn);
|
||||
assertFalse(br.spawnMob(block));
|
||||
verify(world).spawnEntity(eq(location), eq(EntityType.CAT));
|
||||
verify(world).spawnEntity(location, EntityType.CAT);
|
||||
verify(location).add(any(Vector.class));
|
||||
}
|
||||
|
||||
@ -477,7 +477,7 @@ public class BiomeRecipeTest {
|
||||
|
||||
br.addMobs(mobType, mobProbability, mobSpawnOn);
|
||||
assertTrue(br.spawnMob(block));
|
||||
verify(world).spawnEntity(eq(location), eq(EntityType.CAT));
|
||||
verify(world).spawnEntity(location, EntityType.CAT);
|
||||
verify(location).add(any(Vector.class));
|
||||
}
|
||||
|
||||
@ -504,7 +504,7 @@ public class BiomeRecipeTest {
|
||||
|
||||
br.addMobs(mobType, mobProbability, mobSpawnOn);
|
||||
assertTrue(br.spawnMob(block));
|
||||
verify(world).spawnEntity(eq(location), eq(EntityType.HOGLIN));
|
||||
verify(world).spawnEntity(location, EntityType.HOGLIN);
|
||||
verify(location).add(any(Vector.class));
|
||||
verify(hoglin).setImmuneToZombification(true);
|
||||
}
|
||||
@ -532,7 +532,7 @@ public class BiomeRecipeTest {
|
||||
|
||||
br.addMobs(mobType, mobProbability, mobSpawnOn);
|
||||
assertTrue(br.spawnMob(block));
|
||||
verify(world).spawnEntity(eq(location), eq(EntityType.PIGLIN));
|
||||
verify(world).spawnEntity(location, EntityType.PIGLIN);
|
||||
verify(location).add(any(Vector.class));
|
||||
verify(piglin).setImmuneToZombification(true);
|
||||
}
|
||||
@ -562,7 +562,7 @@ public class BiomeRecipeTest {
|
||||
|
||||
br.addMobs(mobType, mobProbability, mobSpawnOn);
|
||||
assertTrue(br.spawnMob(block));
|
||||
verify(world).spawnEntity(eq(location), eq(EntityType.PIGLIN));
|
||||
verify(world).spawnEntity(location, EntityType.PIGLIN);
|
||||
verify(location).add(any(Vector.class));
|
||||
verify(piglin, never()).setImmuneToZombification(true);
|
||||
}
|
||||
@ -586,7 +586,7 @@ public class BiomeRecipeTest {
|
||||
|
||||
br.addMobs(mobType, mobProbability, mobSpawnOn);
|
||||
assertFalse(br.spawnMob(block));
|
||||
verify(world, never()).spawnEntity(eq(location), eq(EntityType.CAT));
|
||||
verify(world, never()).spawnEntity(location, EntityType.CAT);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -706,8 +706,8 @@ public class BiomeRecipeTest {
|
||||
assertTrue(br.addPlants(Material.SUNFLOWER, 100, Material.GRASS_BLOCK));
|
||||
assertTrue(br.growPlant(new GrowthBlock(block, true), false));
|
||||
verify(world).spawnParticle(eq(Particle.SNOWBALL), any(Location.class), anyInt(), anyDouble(), anyDouble(), anyDouble());
|
||||
verify(bisected).setHalf(eq(Half.BOTTOM));
|
||||
verify(bisected).setHalf(eq(Half.TOP));
|
||||
verify(bisected).setHalf(Half.BOTTOM);
|
||||
verify(bisected).setHalf(Half.TOP);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -722,8 +722,8 @@ public class BiomeRecipeTest {
|
||||
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);
|
||||
when(block.getRelative(eq(BlockFace.UP))).thenReturn(ob);
|
||||
when(block.getRelative(BlockFace.DOWN)).thenReturn(ob);
|
||||
when(block.getRelative(BlockFace.UP)).thenReturn(ob);
|
||||
assertTrue(br.addPlants(Material.SUNFLOWER, 100, Material.GRASS_BLOCK));
|
||||
assertFalse(br.growPlant(new GrowthBlock(block, true), false));
|
||||
}
|
||||
|
@ -83,22 +83,22 @@ public class EcoSystemManagerTest {
|
||||
// Liquid false
|
||||
when(air.isEmpty()).thenReturn(true);
|
||||
when(air.isPassable()).thenReturn(true);
|
||||
when(air.getRelative(eq(BlockFace.UP))).thenReturn(air);
|
||||
when(air.getRelative(BlockFace.UP)).thenReturn(air);
|
||||
// Plant
|
||||
// Empty false
|
||||
// Liquid false
|
||||
when(plant.isPassable()).thenReturn(true);
|
||||
when(plant.getRelative(eq(BlockFace.UP))).thenReturn(air);
|
||||
when(plant.getRelative(BlockFace.UP)).thenReturn(air);
|
||||
// Liquid
|
||||
// Empty false
|
||||
when(liquid.isLiquid()).thenReturn(true);
|
||||
when(liquid.isPassable()).thenReturn(true);
|
||||
when(liquid.getRelative(eq(BlockFace.UP))).thenReturn(air);
|
||||
when(liquid.getRelative(BlockFace.UP)).thenReturn(air);
|
||||
// Default for block
|
||||
// Empty false
|
||||
// Passable false
|
||||
// Liquid false
|
||||
when(block.getRelative(eq(BlockFace.UP))).thenReturn(air);
|
||||
when(block.getRelative(BlockFace.UP)).thenReturn(air);
|
||||
|
||||
// Recipe
|
||||
when(recipe.noMobs()).thenReturn(true);
|
||||
|
Loading…
Reference in New Issue
Block a user