Skip to content

Models - Animations Module

anvil.api.models.animations

Builders for Bedrock animation files (*.animations.json).

An :class:Animations is one animations file holding any number of :class:_Animation objects. An animation hands out :class:_AnimBone objects by bone name, and each keyframe call returns the same bone so keyframes chain.

Example
anims = Animations("my_mob")

walk = anims.animation("walk", length=1.0, loop=True)
walk.bone("arm").add_rotation(0.0, [0, 0, 0]).add_rotation(
    0.5, [0, 30, 0]
).add_rotation(1.0, [0, 0, 0])
walk.bone("body").add_position(0.5, [0, 1, 0], pre=[0, 0, 0])
walk.particle(0.25, "minecraft:dust", locator="foot")
walk.sound(0.25, "step")
walk.add_timeline(0.5, "v.step = 1;")

anims.queue()

Documentation reference

Animations

Bases: JsonFile[_AnimationsFile]

An animations file (<name>.animations.json) holding many animations.

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.

__init__(name, is_vanilla=False, *, identifier=None)

Constructs all the necessary attributes for the JsonFile object.

Parameters:

Name Type Description Default
name str

The file name. Without identifier, it is also the identifier, and the file is named after the identifier's name.

required
is_vanilla bool

If the file overrides a vanilla definition. Packages of type addon cannot.

False
identifier str

The identifier the file writes, when it is not the file name.

None

Raises:

Type Description
TypeError

When the class is an abstract file base, with no document type.

ValueError

When the identifier is not valid (see Identifier.parse), or a vanilla override is not allowed.

__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.

animation(name, length=None, loop=False, anim_time_update=None, override_previous_animation=False)

Creates an animation in this file and returns it.

This is the only way to add an animation to a set.

Parameters:

Name Type Description Default
name str

The animation's name in this file.

required
length float

The length in seconds. By default the game uses the time of the last keyframe or event.

None
loop bool | Literal['hold_on_last_frame']

Whether the animation stops, loops, or stays on its last frame when it ends.

False
anim_time_update float | str

How time passes while it plays.

None
override_previous_animation bool

Resets the animated bones to their default pose first.

False

queue(directory=None)

Queues the addon object for processing and logs the event.

Parameters:

Name Type Description Default
directory str

The directory of the addon object.

None

Returns:

Name Type Description
self 'JsonFile[D]'

The instance of the current JsonFile.

validate(geometry)

Checks that every animated bone and locator exists in geometry.

Raises a single ValueError listing all problems.