Skip to content

Core - Textures Module

anvil.lib.textures

FlipBookTexturesObject

Bases: AddonObject

Handles flip book textures for the addon.

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__()

Initializes a FlipBookTexturesObject instance.

__new__()

Ensures only one instance of FlipBookTexturesObject exists (singleton pattern).

add_block(block_name, directory, block_texture, frames, ticks_per_frame=20, atlas_index=None, atlas_tile_variant=None, replicate=1, blend_frames=True)

Adds an animated flipbook texture for a block.

Flipbook textures are animated textures used by blocks like fire, water, lava and magma. The animation parameters defined here will be applied to blocks using this texture shortname.

Parameters:

Name Type Description Default
block_name str

The shortname defined in terrain_texture.json for this block.

required
directory str

The directory path for the textures relative to the project blocks folder.

required
block_texture str

The name of the block texture file (without extension).

required
frames list[int]

List with frame index to use on each frame, or the total number of frames to be repeated one after another. Defaults to [1].

required
ticks_per_frame int

How fast frames should be changed. 20 ticks = 1 second. Defaults to 20.

20
atlas_index int

The index of the texture array inside the terrain_texture.json definition. Use this when the shortname has multiple textures in an array and you want to animate a specific index.

None
atlas_tile_variant int

The variant of the block's texture array inside the shortname's block variation. Use this when you want to animate a specific variation path.

None
replicate int

Sets the size of pixels. Changes size of the piece of used texture. Can only take values that are multiples of two. Default: 1.

1
blend_frames bool

Defines whether frames transition should be smooth or not. Defaults to True.

True
Note
  • The texture file should be a vertical strip containing all animation frames
  • atlas_index is used when terrain_texture.json has: "textures": ["path1", "path2"]
  • atlas_tile_variant is used when terrain_texture.json has variations array
  • replicate value of 2 renders 1/4 pixels of frame, x renders 1/x² pixels
Documentation reference:
https://wiki.bedrock.dev/blocks/flipbook-textures.html

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()

Queues the block textures.

Returns:

Name Type Description
object

The parent's queue method result.

set_identifier_data(data)

Sets the data of the addon object.

Parameters:

Name Type Description Default
data any

The data to be set for the addon object.

required

ItemTexturesObject

Bases: AddonObject

Handles item textures for the addon.

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

Queues the item textures.

Returns:

Name Type Description
object

The parent's queue method result.

__init__()

Initializes a ItemTexturesObject instance.

add_item(item_name, directory, *item_sprites)

Adds item textures to the content.

Parameters:

Name Type Description Default
item_name str

The name of the item.

required
directory str

The directory path for the textures.

required
item_sprites str

The names of the item sprites.

()

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.

set_identifier_data(data)

Sets the data of the addon object.

Parameters:

Name Type Description Default
data any

The data to be set for the addon object.

required

TerrainTexturesObject

Bases: AddonObject

Handles terrain textures for the addon.

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__()

Initializes a TerrainTexturesObject instance.

__new__()

Ensures only one instance of TerrainTexturesObject exists (singleton pattern).

add_block(block_name, directory, block_textures)

Adds block textures to the content.

Parameters:

Name Type Description Default
block_name str

The name of the block.

required
directory str

The directory path for the textures.

required
block_textures str

The names of the block textures.

required

add_block_variations(block_name, directory, block_variant)

Adds block textures with variations to the content.

Parameters:

Name Type Description Default
shortname str

The shortname defined in terrain_texture.json for this block.

required
blockbench_name str

The name of the blockbench model.

required
variations list[dict]

List of variations for the block textures.

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()

Queues the block textures.

Returns:

Name Type Description
object

The parent's queue method result.

set_identifier_data(data)

Sets the data of the addon object.

Parameters:

Name Type Description Default
data any

The data to be set for the addon object.

required

UITexturesObject

Bases: AddonObject

Handles UI textures for the addon.

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

Queues the item textures.

Returns:

Name Type Description
object

The parent's queue method result.

__init__()

Initializes a UITexturesObject instance.

add_item(texture_name, directory, *textures)

Adds item textures to the content.

Parameters:

Name Type Description Default
texture_name str

The name of the texture.

required
directory str

The directory path for the textures.

required
textures str

The names of the textures.

()

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.

set_identifier_data(data)

Sets the data of the addon object.

Parameters:

Name Type Description Default
data any

The data to be set for the addon object.

required