Skip to content

Core - Sounds Module

anvil.lib.sounds

MusicDefinition

Bases: AddonObject

Handles music definitions.

Attributes:

Name Type Description
_extensions dict

The file extensions for the music definition.

_sounds list[SoundDescription]

A list of sound descriptions. Defaults to empty list.

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.

queue property

Returns the queue for the music definition.

Returns:

Name Type Description
queue

The queue for the music definition.

__init__()

Initializes a MusicDefinition instance.

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.

music_definition(music_reference, min_delay=60, max_delay=180)

Defines a music for the MusicDefinition instance.

Parameters:

Name Type Description Default
music_category MusicCategory

The category of the music.

required
min_delay int

The minimum delay for the music. Defaults to 60.

60
max_delay int

The maximum delay for the music. Defaults to 180.

180

Returns:

Name Type Description
SoundDescription

The created sound description instance.

SoundDefinition

Bases: AddonObject

Handles sound definitions.

Attributes:

Name Type Description
_sounds list[SoundDescription]

A list of sound descriptions. Defaults to empty list.

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.

queue property

Returns the queue for the sound definition.

Returns:

Name Type Description
queue

The queue for the sound definition.

__init__()

Initializes a SoundDefinition instance.

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.

sound_reference(sound_reference, category, use_legacy_max_distance=False, max_distance=0, min_distance=9999)

Defines a sound for the SoundDefinition instance.

Parameters:

Name Type Description Default
sound_reference str

The sound_reference of the sound.

required
category SoundCategory

The category of the sound.

required
use_legacy_max_distance bool

Use legacy max distance if True. Defaults to False.

False
max_distance int

The maximum distance for the sound. Defaults to 0.

0
min_distance int

The minimum distance for the sound. Defaults to 9999.

9999

Returns:

Name Type Description
SoundDescription

The created sound description instance.

SoundDescription

Represents a sound description for Minecraft addon sound definitions.

Manages the configuration and properties of individual sound effects, including volume, distance, and 3D positioning parameters.

identifier property

Gets the sound definition identifier.

Returns:

Name Type Description
str

The sound definition identifier.

__init__(sound_reference, category, use_legacy_max_distance=False, max_distance=0, min_distance=9999)

Initializes a SoundDescription instance.

Parameters:

Name Type Description Default
sound_reference str

The definition of the sound.

required
category SoundCategory

The category of the sound.

required
use_legacy_max_distance bool

Use legacy max distance if True. Defaults to False.

False
max_distance int

The maximum distance for the sound. Defaults to 0.

0
min_distance int

The minimum distance for the sound. Defaults to 9999.

9999

add_sound(sound_name, volume=1, weight=1, pitch=[1, 1], is_3d=None, stream=None, load_on_low_memory=False)

Adds a sound to the SoundDescription instance.

Parameters:

Name Type Description Default
sound_name str

The name of the sound.

required
volume int

The volume of the sound. Defaults to 1.

1
weight int

The weight of the sound. Defaults to 1.

1
pitch list[int]

The pitch of the sound. Defaults to [1, 1].

[1, 1]
is_3d bool

If the sound is 3D. Defaults to None.

None
stream bool

If the sound is streamed. Defaults to None.

None
load_on_low_memory bool

If the sound is loaded on low memory. Defaults to False.

False

SoundEvent

Bases: AddonObject

Handles sound events for entities and individual sounds.

Manages the creation and configuration of sound events that can be triggered by entities or as standalone sounds in the game.

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.

queue property

Returns the queue for the sound event.

Returns:

Name Type Description
queue

The queue for the sound event.

__init__()

Initializes a SoundEvent instance.

add_entity_event(entity_identifier, sound_identifier, sound_event, volume=1.0, pitch=(0.8, 1.2), variant_query=None, variant_map=None)

Adds an entity event to the SoundEvent instance.

Parameters:

Name Type Description Default
entity_identifier Identifier

The identifier of the entity.

required
sound_event EntitySoundEvent

The sound event for the entity.

required
sound_identifier str

The identifier of the sound.

required
volume float

The volume of the event. Defaults to 1.0.

1.0
pitch tuple[float, float]

The pitch of the event. Defaults to (0.8, 1.2).

(0.8, 1.2)
variant_query Molang

The variant query for the event. Defaults to None.

None
variant_map str

The variant map for the event. Defaults to None.

None

add_individual_event(sound_identifier, volume=1.0, pitch=(0.8, 1.2))

Adds an individual event to the SoundEvent instance.

Parameters:

Name Type Description Default
sound_identifier str

The identifier of the sound.

required
volume float

The volume of the event. Defaults to 1.0.

1.0
pitch tuple[float, float]

The pitch of the event. Defaults to (0.8, 1.2).

(0.8, 1.2)

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.