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 SpawnRule
firstMatch
(SpawnRule... rules) Combines multiple spawn rules into a single rule by evaluating them in order, from first to last.static SpawnRule
ifBiome
(BiomeFilter filter, SpawnData spawnData) Returns the providedSpawnData
if the givenBiomeFilter
matches the current biome.static SpawnRule
never()
ASpawnRule
that 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
SpawnData
instance. Ifnull
is 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
null
if the mob should not spawn here
-
never
ASpawnRule
that prevents the entity from spawning in any biome.Always returns
null
when 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 providedSpawnData
if the givenBiomeFilter
matches 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
SpawnData
will be used. All subsequent rules are ignored. This creates layered fallback logic where more specific rules are prioritized.
-