Skip to content

Commit

Permalink
Add max mobs option #99
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Mar 1, 2023
1 parent 4351247 commit 66270cf
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
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;
Expand Down Expand Up @@ -102,6 +101,7 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {

private String permission = "";
private final Random random = new Random();
private int maxMob;


/**
Expand Down Expand Up @@ -715,5 +715,20 @@ public Set<EntityType> getMobTypes() {
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;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ private void addMobs(Greenhouse gh) {
Collections.shuffle(list, new Random(System.currentTimeMillis()));
Iterator<GrowthBlock> 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())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ private BiomeRecipe getBiomeRecipe(ConfigurationSection biomeRecipeConfig, Strin
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;
}

Expand Down
48 changes: 46 additions & 2 deletions src/main/resources/biomes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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:
Expand All @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -304,4 +344,8 @@ biomes:
mobs:
skeleton: 5:STONE
glow_squid: 5:WATER
moblimit: 5
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

0 comments on commit 66270cf

Please sign in to comment.