Code clean up.

This commit is contained in:
tastybento 2023-09-19 22:15:46 -07:00
parent ca4f1a3f43
commit a7eeef7edc
8 changed files with 49 additions and 53 deletions

View File

@ -287,8 +287,8 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {
Material bType = b.getType(); 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 // 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)) { if(conversionBlocks.keySet().contains(bType)) {
for(GreenhouseBlockConversions conversion_option : conversionBlocks.get(bType)) { for(GreenhouseBlockConversions conversionOption : conversionBlocks.get(bType)) {
rollTheDice(b, conversion_option); rollTheDice(b, conversionOption);
} }
} }
} }
@ -450,7 +450,10 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {
// Grow a random plant that can grow // Grow a random plant that can grow
double r = random.nextDouble(); double r = random.nextDouble();
Double key = underwater ? underwaterPlants.ceilingKey(r) : plantTree.ceilingKey(r); 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) { public boolean growPlant(GrowthBlock block, boolean underwater) {
Block bl = block.block(); Block bl = block.block();
return getRandomPlant(underwater).map(p -> { return getRandomPlant(underwater).map(p -> {
if (bl.getY() != 0 && canGrowOn(block, p)) { if (bl.getY() != 0 && canGrowOn(block, p) && plantIt(bl, p)) {
if (plantIt(bl, p)) {
bl.getWorld().spawnParticle(Particle.SNOWBALL, bl.getLocation(), 10, 2, 2, 2); bl.getWorld().spawnParticle(Particle.SNOWBALL, bl.getLocation(), 10, 2, 2, 2);
return true; return true;
} }
}
return false; return false;
}).orElse(false); }).orElse(false);
} }
@ -569,14 +570,12 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {
BlockFace d = null; BlockFace d = null;
boolean waterLogged = false; boolean waterLogged = false;
for (BlockFace adj : ADJ_BLOCKS) { for (BlockFace adj : ADJ_BLOCKS) {
if (b.getRelative(adj).getType().equals(Material.AIR)) { Material type = b.getRelative(adj).getType();
d = adj; if (type.equals(Material.AIR) || type.equals(Material.WATER)) {
break;
}
// Lichen can grow under water too
if (b.getRelative(adj).getType().equals(Material.WATER)) {
d = adj; d = adj;
if (type.equals(Material.WATER)) {
waterLogged = true; waterLogged = true;
}
break; break;
} }
} }

View File

@ -95,17 +95,17 @@ public class EcoSystemManager {
return; return;
} }
final BoundingBox ibb = gh.getInternalBoundingBox(); final BoundingBox ibb = gh.getInternalBoundingBox();
int gh_min_x = NumberConversions.floor(ibb.getMinX()); int ghMinX = NumberConversions.floor(ibb.getMinX());
int gh_max_x = NumberConversions.floor(ibb.getMaxX()); int ghMaxX = NumberConversions.floor(ibb.getMaxX());
int gh_min_y = NumberConversions.floor(gh.getBoundingBox().getMinY()); // Note: this gets the floor int ghMinY = NumberConversions.floor(gh.getBoundingBox().getMinY()); // Note: this gets the floor
int gh_max_y = NumberConversions.floor(ibb.getMaxY()); int ghMaxY = NumberConversions.floor(ibb.getMaxY());
int gh_min_z = NumberConversions.floor(ibb.getMinZ()); int ghMinZ = NumberConversions.floor(ibb.getMinZ());
int gh_max_z = NumberConversions.floor(ibb.getMaxZ()); int ghMaxZ = NumberConversions.floor(ibb.getMaxZ());
BiomeRecipe biomeRecipe = gh.getBiomeRecipe(); BiomeRecipe biomeRecipe = gh.getBiomeRecipe();
for (int x = gh_min_x; x < gh_max_x; x++) { for (int x = ghMinX; x < ghMaxX; x++) {
for (int z = gh_min_z; z < gh_max_z; z++) { for (int z = ghMinZ; z < ghMaxZ; z++) {
for (int y = gh_min_y; y < gh_max_y; y++) { for (int y = ghMinY; y < ghMaxY; y++) {
Block b = world.getBlockAt(x, y, z); Block b = world.getBlockAt(x, y, z);
if(!b.isEmpty()) { if(!b.isEmpty()) {

View File

@ -34,7 +34,6 @@ public class GreenhouseFinder {
* This is the count of the various items * This is the count of the various items
*/ */
private CounterCheck counterCheck = new CounterCheck(); private CounterCheck counterCheck = new CounterCheck();
private Roof roof;
static class CounterCheck { static class CounterCheck {
int doorCount; int doorCount;
@ -63,7 +62,7 @@ public class GreenhouseFinder {
// Get a world cache // Get a world cache
AsyncWorldCache cache = new AsyncWorldCache(addon, location.getWorld()); AsyncWorldCache cache = new AsyncWorldCache(addon, location.getWorld());
// Find the roof // Find the roof
roof = new Roof(cache, location, addon); Roof roof = new Roof(cache, location, addon);
roof.findRoof().thenAccept(found -> { roof.findRoof().thenAccept(found -> {
if (Boolean.FALSE.equals(found)) { if (Boolean.FALSE.equals(found)) {
result.add(GreenhouseResult.FAIL_NO_ROOF); result.add(GreenhouseResult.FAIL_NO_ROOF);

View File

@ -6,7 +6,6 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors;
import org.bukkit.Location; import org.bukkit.Location;
@ -138,7 +137,7 @@ public class GreenhouseMap {
* @return a list of all the Greenhouses * @return a list of all the Greenhouses
*/ */
public List<Greenhouse> getGreenhouses() { public List<Greenhouse> getGreenhouses() {
return greenhouses.values().stream().flatMap(List::stream).collect(Collectors.toList()); return greenhouses.values().stream().flatMap(List::stream).toList();
} }
/** /**

View File

@ -185,12 +185,12 @@ public class RecipeManager {
} }
// Get the list of conversions // Get the list of conversions
for (String oldMat : biomeRecipeConfig.getStringList("conversion-list")) { 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 { try {
// Split the string // Split the string
String[] split = oldMat.split(":"); String[] split = oldMat.split(":");

View File

@ -5,7 +5,6 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -61,7 +60,7 @@ public class GreenhouseTest {
// RecipeManager // RecipeManager
PowerMockito.mockStatic(RecipeManager.class); PowerMockito.mockStatic(RecipeManager.class);
when(br.getName()).thenReturn("test"); when(br.getName()).thenReturn("test");
when(RecipeManager.getBiomeRecipies(eq("test"))).thenReturn(Optional.of(br)); when(RecipeManager.getBiomeRecipies("test")).thenReturn(Optional.of(br));
// Walls // Walls
when(walls.getMinX()).thenReturn(MINX); when(walls.getMinX()).thenReturn(MINX);
when(walls.getMinZ()).thenReturn(MINZ); when(walls.getMinZ()).thenReturn(MINZ);

View File

@ -151,7 +151,7 @@ public class BiomeRecipeTest {
double convChance = 100D; double convChance = 100D;
Material localMaterial = Material.WATER; Material localMaterial = Material.WATER;
br.addConvBlocks(oldMaterial, newMaterial, convChance, localMaterial); 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; int mobProbability = 50;
Material mobSpawnOn = Material.GRASS_BLOCK; Material mobSpawnOn = Material.GRASS_BLOCK;
br.addMobs(mobType, mobProbability, mobSpawnOn); 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); 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; Material mobSpawnOn = Material.GRASS_BLOCK;
br.addMobs(mobType, mobProbability, mobSpawnOn); 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");
} }
/** /**
@ -202,7 +202,7 @@ public class BiomeRecipeTest {
int plantProbability = 20; int plantProbability = 20;
Material plantGrowOn = Material.DIRT; Material plantGrowOn = Material.DIRT;
br.addPlants(plantMaterial, plantProbability, plantGrowOn); 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; Material plantGrowOn = Material.DIRT;
br.addPlants(plantMaterial, plantProbability, plantGrowOn); br.addPlants(plantMaterial, plantProbability, plantGrowOn);
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; Material blockMaterial = Material.BLACK_CONCRETE;
int blockQty = 30; int blockQty = 30;
br.addReqBlocks(blockMaterial, blockQty); 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); br.addMobs(mobType, mobProbability, mobSpawnOn);
assertFalse(br.spawnMob(block)); assertFalse(br.spawnMob(block));
verify(world).spawnEntity(eq(location), eq(EntityType.CAT)); verify(world).spawnEntity(location, EntityType.CAT);
verify(location).add(any(Vector.class)); verify(location).add(any(Vector.class));
} }
@ -477,7 +477,7 @@ public class BiomeRecipeTest {
br.addMobs(mobType, mobProbability, mobSpawnOn); br.addMobs(mobType, mobProbability, mobSpawnOn);
assertTrue(br.spawnMob(block)); assertTrue(br.spawnMob(block));
verify(world).spawnEntity(eq(location), eq(EntityType.CAT)); verify(world).spawnEntity(location, EntityType.CAT);
verify(location).add(any(Vector.class)); verify(location).add(any(Vector.class));
} }
@ -504,7 +504,7 @@ public class BiomeRecipeTest {
br.addMobs(mobType, mobProbability, mobSpawnOn); br.addMobs(mobType, mobProbability, mobSpawnOn);
assertTrue(br.spawnMob(block)); 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(location).add(any(Vector.class));
verify(hoglin).setImmuneToZombification(true); verify(hoglin).setImmuneToZombification(true);
} }
@ -532,7 +532,7 @@ public class BiomeRecipeTest {
br.addMobs(mobType, mobProbability, mobSpawnOn); br.addMobs(mobType, mobProbability, mobSpawnOn);
assertTrue(br.spawnMob(block)); 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(location).add(any(Vector.class));
verify(piglin).setImmuneToZombification(true); verify(piglin).setImmuneToZombification(true);
} }
@ -562,7 +562,7 @@ public class BiomeRecipeTest {
br.addMobs(mobType, mobProbability, mobSpawnOn); br.addMobs(mobType, mobProbability, mobSpawnOn);
assertTrue(br.spawnMob(block)); 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(location).add(any(Vector.class));
verify(piglin, never()).setImmuneToZombification(true); verify(piglin, never()).setImmuneToZombification(true);
} }
@ -586,7 +586,7 @@ public class BiomeRecipeTest {
br.addMobs(mobType, mobProbability, mobSpawnOn); br.addMobs(mobType, mobProbability, mobSpawnOn);
assertFalse(br.spawnMob(block)); 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.addPlants(Material.SUNFLOWER, 100, Material.GRASS_BLOCK));
assertTrue(br.growPlant(new GrowthBlock(block, true), false)); assertTrue(br.growPlant(new GrowthBlock(block, true), false));
verify(world).spawnParticle(eq(Particle.SNOWBALL), any(Location.class), anyInt(), anyDouble(), anyDouble(), anyDouble()); verify(world).spawnParticle(eq(Particle.SNOWBALL), any(Location.class), anyInt(), anyDouble(), anyDouble(), anyDouble());
verify(bisected).setHalf(eq(Half.BOTTOM)); verify(bisected).setHalf(Half.BOTTOM);
verify(bisected).setHalf(eq(Half.TOP)); verify(bisected).setHalf(Half.TOP);
} }
/** /**
@ -722,8 +722,8 @@ public class BiomeRecipeTest {
when(block.isEmpty()).thenReturn(true); 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(BlockFace.DOWN)).thenReturn(ob);
when(block.getRelative(eq(BlockFace.UP))).thenReturn(ob); when(block.getRelative(BlockFace.UP)).thenReturn(ob);
assertTrue(br.addPlants(Material.SUNFLOWER, 100, Material.GRASS_BLOCK)); assertTrue(br.addPlants(Material.SUNFLOWER, 100, Material.GRASS_BLOCK));
assertFalse(br.growPlant(new GrowthBlock(block, true), false)); assertFalse(br.growPlant(new GrowthBlock(block, true), false));
} }

View File

@ -83,22 +83,22 @@ public class EcoSystemManagerTest {
// Liquid false // Liquid false
when(air.isEmpty()).thenReturn(true); when(air.isEmpty()).thenReturn(true);
when(air.isPassable()).thenReturn(true); when(air.isPassable()).thenReturn(true);
when(air.getRelative(eq(BlockFace.UP))).thenReturn(air); when(air.getRelative(BlockFace.UP)).thenReturn(air);
// Plant // Plant
// Empty false // Empty false
// Liquid false // Liquid false
when(plant.isPassable()).thenReturn(true); when(plant.isPassable()).thenReturn(true);
when(plant.getRelative(eq(BlockFace.UP))).thenReturn(air); when(plant.getRelative(BlockFace.UP)).thenReturn(air);
// Liquid // Liquid
// Empty false // Empty false
when(liquid.isLiquid()).thenReturn(true); when(liquid.isLiquid()).thenReturn(true);
when(liquid.isPassable()).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 // Default for block
// Empty false // Empty false
// Passable false // Passable false
// Liquid false // Liquid false
when(block.getRelative(eq(BlockFace.UP))).thenReturn(air); when(block.getRelative(BlockFace.UP)).thenReturn(air);
// Recipe // Recipe
when(recipe.noMobs()).thenReturn(true); when(recipe.noMobs()).thenReturn(true);