From 66270cf3e7feb61a2b5423313394f8e2fe067880 Mon Sep 17 00:00:00 2001 From: tastybento Date: Wed, 1 Mar 2023 08:26:34 -0800 Subject: [PATCH] Add max mobs option #99 --- .../greenhouses/greenhouse/BiomeRecipe.java | 17 ++++++- .../managers/EcoSystemManager.java | 3 ++ .../greenhouses/managers/RecipeManager.java | 1 + src/main/resources/biomes.yml | 48 ++++++++++++++++++- 4 files changed, 66 insertions(+), 3 deletions(-) diff --git a/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java b/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java index 7cd7266..92ad899 100644 --- a/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java +++ b/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java @@ -32,7 +32,6 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Hoglin; import org.bukkit.entity.Piglin; -import org.bukkit.material.CocoaPlant; import org.bukkit.util.Vector; import com.google.common.base.Enums; @@ -102,6 +101,7 @@ public class BiomeRecipe implements Comparable { private String permission = ""; private final Random random = new Random(); + private int maxMob; /** @@ -715,5 +715,20 @@ public class BiomeRecipe implements Comparable { return mobTree.values().stream().map(GreenhouseMob::mobType).collect(Collectors.toSet()); } + /** + * Set the maximum number of mobs in a greenhouse + * @param maxMob maximum + */ + public void setMaxMob(int maxMob) { + this.maxMob = maxMob; + } + + /** + * @return the maxMob + */ + public int getMaxMob() { + return maxMob; + } + } diff --git a/src/main/java/world/bentobox/greenhouses/managers/EcoSystemManager.java b/src/main/java/world/bentobox/greenhouses/managers/EcoSystemManager.java index b4032b8..9684e31 100644 --- a/src/main/java/world/bentobox/greenhouses/managers/EcoSystemManager.java +++ b/src/main/java/world/bentobox/greenhouses/managers/EcoSystemManager.java @@ -161,6 +161,9 @@ public class EcoSystemManager { Collections.shuffle(list, new Random(System.currentTimeMillis())); Iterator it = list.iterator(); // Check if the greenhouse is full + if (sum >= gh.getBiomeRecipe().getMaxMob()) { + return; + } while (it.hasNext() && (sum == 0 || gh.getArea() / sum >= gh.getBiomeRecipe().getMobLimit())) { // Spawn something if chance says so if (gh.getBiomeRecipe().spawnMob(it.next().block())) { diff --git a/src/main/java/world/bentobox/greenhouses/managers/RecipeManager.java b/src/main/java/world/bentobox/greenhouses/managers/RecipeManager.java index 248ba15..7e0f559 100644 --- a/src/main/java/world/bentobox/greenhouses/managers/RecipeManager.java +++ b/src/main/java/world/bentobox/greenhouses/managers/RecipeManager.java @@ -155,6 +155,7 @@ public class RecipeManager { b.setLavacoverage(biomeRecipeConfig.getInt("lavacoverage",-1)); b.setIcecoverage(biomeRecipeConfig.getInt("icecoverage",-1)); b.setMobLimit(biomeRecipeConfig.getInt("moblimit", 9)); + b.setMaxMob(biomeRecipeConfig.getInt("maxmob", -1)); return b; } diff --git a/src/main/resources/biomes.yml b/src/main/resources/biomes.yml index 1a2807c..d196791 100644 --- a/src/main/resources/biomes.yml +++ b/src/main/resources/biomes.yml @@ -38,8 +38,12 @@ biomes: # The minimum number of blocks each mob requires. # Mobs will not spawn if there is more than 1 per this number of # blocks in the greenhouse. e.g., in this case only 2 mobs will spawn if the - # greenhouse area is 18 blocks + # greenhouse area is 18 blocks. This enables bigger greenhouses to spawn more. moblimit: 9 + # Maxmobs - this is the maximum number of greenhouse-spawed mobs allowed in + # the greenhouse at once. Spawning will stop when this limit is reached. + # If this value is not given, there is no maximum. + maxmobs: 5 Snowy_beach: friendlyname: "Snowy beach" biome: SNOWY_BEACH @@ -65,6 +69,10 @@ biomes: mobs: WOLF: 10:SNOW moblimit: 9 + # Maxmobs - this is the maximum number of greenhouse-spawed mobs allowed in + # the greenhouse at once. Spawning will stop when this limit is reached. + # If this value is not given, there is no maximum. + maxmobs: 5 Cold_Rabbit: friendlyname: "Cold Taiga Forest" biome: OLD_GROWTH_SPRUCE_TAIGA @@ -80,6 +88,10 @@ biomes: mobs: RABBIT: 10:SNOW moblimit: 9 + # Maxmobs - this is the maximum number of greenhouse-spawed mobs allowed in + # the greenhouse at once. Spawning will stop when this limit is reached. + # If this value is not given, there is no maximum. + maxmobs: 20 DESERT: friendlyname: "Desert" biome: DESERT @@ -134,6 +146,10 @@ biomes: STRIDER: 10:LAVA ENDERMAN: 5:NETHERRACK moblimit: 9 + # Maxmobs - this is the maximum number of greenhouse-spawed mobs allowed in + # the greenhouse at once. Spawning will stop when this limit is reached. + # If this value is not given, there is no maximum. + maxmobs: 50 permission: greenhouses.biome.nether SOUL_SAND_VALLEY: friendlyname: "&cSoul Sand Valley" @@ -149,6 +165,10 @@ biomes: mobs: SKELETON: 10:SOUL_SAND moblimit: 9 + # Maxmobs - this is the maximum number of greenhouse-spawed mobs allowed in + # the greenhouse at once. Spawning will stop when this limit is reached. + # If this value is not given, there is no maximum. + maxmobs: 50 permission: greenhouses.biome.nether # Conversion list - in this case, an adjacent block is required to convert # Format is: @@ -173,6 +193,10 @@ biomes: PIGLIN: 10:CRIMSON_NYLIUM HOGLIN: 10:CRIMSON_NYLIUM moblimit: 9 + # Maxmobs - this is the maximum number of greenhouse-spawed mobs allowed in + # the greenhouse at once. Spawning will stop when this limit is reached. + # If this value is not given, there is no maximum. + maxmobs: 50 permission: greenhouses.biome.nether WARPED_FOREST: friendlyname: "&cWarped Forest" @@ -190,6 +214,10 @@ biomes: STRIDER: 10:LAVA ENDERMAN: 20:WARPED_NYLIUM moblimit: 9 + # Maxmobs - this is the maximum number of greenhouse-spawed mobs allowed in + # the greenhouse at once. Spawning will stop when this limit is reached. + # If this value is not given, there is no maximum. + maxmobs: 50 permission: greenhouses.biome.nether JUNGLE: biome: JUNGLE @@ -221,6 +249,10 @@ biomes: mobs: MUSHROOM_COW: 10:MYCELIUM moblimit: 9 + # Maxmobs - this is the maximum number of greenhouse-spawed mobs allowed in + # the greenhouse at once. Spawning will stop when this limit is reached. + # If this value is not given, there is no maximum. + maxmobs: 20 OCEAN: biome: OCEAN icon: WATER_BUCKET @@ -242,6 +274,10 @@ biomes: mobs: HORSE: 10:GRASS_BLOCK moblimit: 1 + # Maxmobs - this is the maximum number of greenhouse-spawed mobs allowed in + # the greenhouse at once. Spawning will stop when this limit is reached. + # If this value is not given, there is no maximum. + maxmobs: 10 RIVER: friendlyname: "Clay river" biome: RIVER @@ -286,6 +322,10 @@ biomes: mobs: SLIME: 5:WATER moblimit: 3 + # Maxmobs - this is the maximum number of greenhouse-spawed mobs allowed in + # the greenhouse at once. Spawning will stop when this limit is reached. + # If this value is not given, there is no maximum. + maxmobs: 10 dripstone_caves: friendlyname: "&6Drippy Drops" biome: dripstone_caves @@ -304,4 +344,8 @@ biomes: mobs: skeleton: 5:STONE glow_squid: 5:WATER - moblimit: 5 \ No newline at end of file + moblimit: 5 + # Maxmobs - this is the maximum number of greenhouse-spawed mobs allowed in + # the greenhouse at once. Spawning will stop when this limit is reached. + # If this value is not given, there is no maximum. + maxmobs: 25 \ No newline at end of file