Skip to content

Actors - Spawn Rules Module

anvil.api.actors.spawn_rules

SpawnRule

Bases: AddonObject

add_condition property

Create and add a new spawn condition to this spawn rule.

Each condition represents a different spawning scenario. Multiple conditions allow entities to spawn under various circumstances (e.g., surface vs underground).

Returns:

Name Type Description
_SpawnRuleCondition

New condition interface for setting spawn requirements.

description property

Access the spawn rule description for setting basic properties.

Returns:

Name Type Description
_SpawnRuleDescription

Description interface for population control and metadata.

identifier property

Returns the identifier of the addon object in the format 'namespace:name'.

Returns:

Name Type Description
str Identifier

The identifier of the addon object.

name property

Returns the name of the addon object.

Returns:

Name Type Description
str str

The name of the addon object.

__init__(identifier, is_vanilla)

Initialize a spawn rule for the specified entity.

Parameters:

Name Type Description Default
identifier str

Entity identifier (e.g., "mypack:custom_mob").

required
is_vanilla bool

Whether this is a vanilla Minecraft entity.

required

content(content)

Sets the content of the addon object and returns the object.

Parameters:

Name Type Description Default
content any

The content to be set for the addon object.

required

Returns:

Name Type Description
self AddonObject

The instance of the current AddonObject.

do_not_shorten()

Setter property that disables shortening of dict when exporting.

queue(directory=None)

Queue this spawn rule for generation in the behavior pack.

Exports the description and all conditions to JSON format and adds the spawn rule file to the generation queue. Only queues if conditions exist.

Parameters:

Name Type Description Default
directory str

Custom directory path. Uses default if None.

None

Returns:

Name Type Description
SpawnRule

Self for method chaining, or None if no conditions exist.