Skip to content

Commit

Permalink
Code clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Sep 20, 2023
1 parent ca4f1a3 commit a7eeef7
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ public void convertBlock(Block b) {
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);
}
}
}
Expand Down Expand Up @@ -450,7 +450,10 @@ private Optional<GreenhousePlant> getRandomPlant(boolean underwater) {
// 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));
}

/**
Expand All @@ -476,11 +479,9 @@ public int getWaterCoverage() {
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)) {
bl.getWorld().spawnParticle(Particle.SNOWBALL, bl.getLocation(), 10, 2, 2, 2);
return true;
}
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);
Expand Down Expand Up @@ -569,14 +570,12 @@ private boolean placeLichen(Block bl) {
BlockFace d = null;
boolean waterLogged = false;
for (BlockFace adj : ADJ_BLOCKS) {
if (b.getRelative(adj).getType().equals(Material.AIR)) {
Material type = b.getRelative(adj).getType();
if (type.equals(Material.AIR) || type.equals(Material.WATER)) {
d = adj;
break;
}
// Lichen can grow under water too
if (b.getRelative(adj).getType().equals(Material.WATER)) {
d = adj;
waterLogged = true;
if (type.equals(Material.WATER)) {
waterLogged = true;
}
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,17 @@ private void convertBlocks(Greenhouse gh) {
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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -63,7 +62,7 @@ public CompletableFuture<Set<GreenhouseResult>> find(Location location) {
// 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

import org.bukkit.Location;

Expand Down Expand Up @@ -138,7 +137,7 @@ public void removeGreenhouses(Island island) {
* @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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,12 @@ private void loadBlockConversions(ConfigurationSection biomeRecipeConfig, BiomeR
}
// 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(":");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
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;

Expand Down Expand Up @@ -61,7 +60,7 @@ public void setUp() {
// 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void testAddConvBlocks() {
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");
}

/**
Expand All @@ -163,7 +163,7 @@ public void testAddMobs() {
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.");
}

/**
Expand All @@ -177,7 +177,7 @@ public void testAddMobsOver100Percent() {
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");
}

/**
Expand All @@ -190,7 +190,7 @@ public void testAddMobsOver100PercentDouble() {
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");
}

/**
Expand All @@ -202,7 +202,7 @@ public void testAddPlants() {
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");
}

/**
Expand All @@ -215,7 +215,7 @@ public void testAddPlantsOver100Percent() {
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");
}

/**
Expand All @@ -226,7 +226,7 @@ public void testAddReqBlocks() {
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");
}

/**
Expand Down Expand Up @@ -451,7 +451,7 @@ public void testSpawnMobOutsideWall() {

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

Expand All @@ -477,7 +477,7 @@ public void testSpawnMob() {

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

Expand All @@ -504,7 +504,7 @@ public void testSpawnMobHoglin() {

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);
}
Expand Down Expand Up @@ -532,7 +532,7 @@ public void testSpawnMobPiglin() {

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);
}
Expand Down Expand Up @@ -562,7 +562,7 @@ public void testSpawnMobPiglinNether() {

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);
}
Expand All @@ -586,7 +586,7 @@ public void testSpawnMobWrongSurface() {

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

/**
Expand Down Expand Up @@ -706,8 +706,8 @@ public void testGrowPlantPlantsDoublePlant() {
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);
}

/**
Expand All @@ -722,8 +722,8 @@ public void testGrowPlantPlantsDoublePlantNoRoom() {
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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,22 @@ public void setUp() {
// 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);
Expand Down

0 comments on commit a7eeef7

Please sign in to comment.