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.

@FunctionalInterface public interface SpawnRule
A functional interface with one method used to determine in what quantities and how often an entity will spawn in a certain 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 Details

    • apply

      @Nullable SpawnData apply(net.minecraft.world.level.biome.Biome biome)
      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. If null 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

      static SpawnRule never()
      A SpawnRule 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 an EntityInjection.

      Returns:
      a spawn rule that disables natural spawning for the entity
    • ifBiome

      static SpawnRule ifBiome(BiomeFilter filter, SpawnData spawnData)
      Returns the provided SpawnData if the given BiomeFilter matches the current biome.

      This allows you to conditionally enable spawning in specific biomes using predefined filters, such as BiomeFilter.overworld(), BiomeFilter.tag(Key), or BiomeFilter.baseTemperature(DoubleRange).

      Parameters:
      filter - the biome filter used to determine where the entity should spawn
      spawnData - 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

      static SpawnRule firstMatch(SpawnRule... rules)
      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.

      Parameters:
      rules - the spawn rules to evaluate in order
      Returns:
      a SpawnRule returning the first non-null SpawnData or null if none is provided