Sounds - Sound Events
anvil.api.sounds.sound_events
The resource pack's sounds.json: the sounds played by block, entity, individual and
interactive events.
SoundEvent
Bases: JsonFile[_SoundsFile]
The sound events of the resource pack, sounds.json: the sounds blocks and entities
play for each event, and sounds played by name. There is one per pack.
Documentation reference
identifier
property
The file's identifier.
name
property
The identifier's name, without its namespace.
__export__()
Exports the addon object after potentially shortening its content and replacing backslashes. Logs the event and writes the object to a file.
__schema__()
classmethod
The JSON Schema (draft 2020-12) of this file: the schema of its _document_type, with
the file's type as title and where it is written under x-anvil-file.
Raises:
| Type | Description |
|---|---|
TypeError
|
When the class is an abstract file base, with no document type. |
add_block_event(block, sound_reference, sound_event, volume=1.0, pitch=_DEFAULT_PITCH, max_distance=None, min_distance=None, subtitle=None, server_sound=None)
Plays a sound for a block's event, adds the block to blocks.json, and defines
the sound.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
block
|
str
|
The block identifier. |
required |
sound_reference
|
str
|
The sound name, written as |
required |
sound_event
|
BlockSoundEvent
|
The event. |
required |
volume
|
float
|
The volume. Defaults to 1. |
1.0
|
pitch
|
float | tuple[float, float]
|
The pitch, or a random pitch range. Defaults to (0.8, 1.2). |
_DEFAULT_PITCH
|
max_distance
|
float
|
The distance the sound is no longer heard at. |
None
|
min_distance
|
float
|
The distance the sound starts to fade at. |
None
|
subtitle
|
str
|
The subtitle text. |
None
|
server_sound
|
MusicInfo
|
Also registers the sound in the behavior pack's server sound definitions. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
_SoundDescription |
_SoundDescription
|
The sound definition; add its files with |
add_block_interactive_event(block, sound_reference, sound_event, volume=1.0, pitch=_DEFAULT_PITCH, max_distance=None, min_distance=None, subtitle=None, server_sound=None)
Plays a sound when an entity interacts with a block, such as stepping on it, adds
the block to blocks.json, and defines the sound.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
block
|
str
|
The block identifier. |
required |
sound_reference
|
str
|
The sound name, written as |
required |
sound_event
|
BlockInteractiveSoundEvent
|
The event. |
required |
volume
|
float
|
The volume. Defaults to 1. |
1.0
|
pitch
|
float | tuple[float, float]
|
The pitch, or a random pitch range. Defaults to (0.8, 1.2). |
_DEFAULT_PITCH
|
max_distance
|
float
|
The distance the sound is no longer heard at. |
None
|
min_distance
|
float
|
The distance the sound starts to fade at. |
None
|
subtitle
|
str
|
The subtitle text. |
None
|
server_sound
|
MusicInfo
|
Also registers the sound in the behavior pack's server sound definitions. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
_SoundDescription |
_SoundDescription
|
The sound definition; add its files with |
add_entity_event(entity, sound_reference, sound_event, category, volume=1.0, pitch=_DEFAULT_PITCH, max_distance=None, min_distance=None, variant_query=None, variant_map=None, subtitle=None, server_sound=None)
Plays a sound for an entity's event, and defines the sound.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity
|
str
|
The entity identifier. |
required |
sound_reference
|
str
|
The sound name, written as |
required |
sound_event
|
EntitySoundEvent
|
The event. |
required |
category
|
SoundCategory
|
The volume slider the sound follows. |
required |
volume
|
float
|
The volume. Defaults to 1. |
1.0
|
pitch
|
float | tuple[float, float]
|
The pitch, or a random pitch range. Defaults to (0.8, 1.2). |
_DEFAULT_PITCH
|
max_distance
|
float
|
The distance the sound is no longer heard at. |
None
|
min_distance
|
float
|
The distance the sound starts to fade at. |
None
|
variant_query
|
Molang | str
|
The key the entity's sound variants are
picked by. With |
None
|
variant_map
|
str
|
The value of |
None
|
subtitle
|
str
|
The subtitle text. |
None
|
server_sound
|
MusicInfo
|
Also registers the sound in the behavior pack's server sound definitions. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
_SoundDescription |
_SoundDescription
|
The sound definition; add its files with |
add_individual_event(sound_reference, category, volume=1.0, pitch=_DEFAULT_PITCH, max_distance=None, min_distance=None, subtitle=None, server_sound=None)
Plays a sound for the event named sound_reference, and defines the sound.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sound_reference
|
str
|
The event name, and the sound name written as
|
required |
category
|
SoundCategory
|
The volume slider the sound follows. |
required |
volume
|
float
|
The volume. Defaults to 1. |
1.0
|
pitch
|
float | tuple[float, float]
|
The pitch, or a random pitch range. Game default (0.8, 1.2). |
_DEFAULT_PITCH
|
max_distance
|
float
|
The distance the sound is no longer heard at. |
None
|
min_distance
|
float
|
The distance the sound starts to fade at. |
None
|
subtitle
|
str
|
The subtitle text. |
None
|
server_sound
|
MusicInfo
|
Also registers the sound in the behavior pack's server sound definitions. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
_SoundDescription |
_SoundDescription
|
The sound definition; add its files with |
add_individual_named_sound(sound_reference, category=SoundCategory.Ambient, volume=1.0, pitch=_DEFAULT_PITCH, max_distance=None, min_distance=None)
Registers a sound in individual_named_sounds, and defines it. Client biome
ambient sounds (minecraft:ambient_sounds) must be defined here.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sound_reference
|
str
|
The name, and the sound name written as
|
required |
category
|
SoundCategory
|
The volume slider the sound follows. Defaults to Ambient. |
Ambient
|
volume
|
float
|
The volume. Defaults to 1. |
1.0
|
pitch
|
float | tuple[float, float]
|
The pitch, or a random pitch range. Game default (0.8, 1.2). |
_DEFAULT_PITCH
|
max_distance
|
float
|
The distance the sound is no longer heard at. |
None
|
min_distance
|
float
|
The distance the sound starts to fade at. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
_SoundDescription |
_SoundDescription
|
The sound definition; add its files with |
queue()
Queues sounds.json for export, when a sound event was added.