Interface SpawnRule
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Biome.
Before implementing this interface, check the static factory methods, a suitable implementation may already exist.
To combine multiple variant rules into one, see firstMatch(SpawnRule...).
-
Method Summary
Modifier and TypeMethodDescriptionapply(net.minecraft.world.level.biome.Biome biome) Called once for each biome during server startup.static SpawnRulefirstMatch(SpawnRule... rules) Combines multiple spawn rules into a single rule by evaluating them in order, from first to last.static SpawnRuleifBiome(BiomeFilter filter, SpawnData spawnData) Returns the providedSpawnDataif the givenBiomeFiltermatches the current biome.static SpawnRulenever()ASpawnRulethat prevents the entity from spawning in any biome.
-
Method Details
-
apply
Called once for each biome during server startup.This method determines how frequently and in what group sizes a mob should spawn in the given biome by returning a
SpawnDatainstance. Ifnullis returned, the mob will not spawn in that biome.- Parameters:
biome- the biome to evaluate- Returns:
- spawn settings for the mob in this biome, or
nullif the mob should not spawn here
-
never
ASpawnRulethat prevents the entity from spawning in any biome.Always returns
nullwhen evaluated, indicating that the entity should not spawn. This is the default rule applied when building anEntityInjection.- Returns:
- a spawn rule that disables natural spawning for the entity
-
ifBiome
Returns the providedSpawnDataif the givenBiomeFiltermatches the current biome.This allows you to conditionally enable spawning in specific biomes using predefined filters, such as
BiomeFilter.overworld(),BiomeFilter.tag(Key), orBiomeFilter.baseTemperature(DoubleRange).- Parameters:
filter- the biome filter used to determine where the entity should spawnspawnData- the spawn data to return if the biome matches the filter- Returns:
- a spawn rule that applies the given spawn data when the biome matches
-
firstMatch
Combines multiple spawn rules into a single rule by evaluating them in order, from first to last.The first rule that returns a non-null
SpawnDatawill be used. All subsequent rules are ignored. This creates layered fallback logic where more specific rules are prioritized.
-