Blocks - Beta Components Module
anvil.beta.blocks.components
Experimental block components. They need features.experimental in anvilconfig.json.
BlockClimbable
Bases: JsonComponent
[EXPERIMENTAL] Defines the climbable properties of the block.
Experimental: needs features.experimental in anvilconfig.json.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
can_climb
|
bool
|
Whether an entity can climb this block when its feet share the same position as the block. |
required |
can_hold_position_while_sneaking
|
bool
|
Whether a player can stop descending and hold their position on this block by sneaking when their feet share the same position as the block. With |
required |
__required__ = ()
class-attribute
JSON keys the schema marks required although their field is optional, because
__validate__ requires them.
__from_json__(data)
classmethod
Builds the object from its parsed JSON, the inverse of __json__(). Each key goes
to the field written under it, read through the field's annotation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
The parsed JSON object. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
The data is not an object, or a value does not match its field. |
ValueError
|
The data has a key the class does not write, or a constant field holds another value. |
__json__()
The component as {identifier: payload}.
__json_fields__()
classmethod
The compiled fields of this class, compiled on first use.
__payload_schema__(definitions)
classmethod
The schema of the payload under the identifier.
__post_init__()
Side effects after construction.
__prepare_export__(owner, *, root=True)
Finishes the object for export, where its owner calls it. Components with a
localized name override it. root is False for a permutation's components.
__schema__()
classmethod
The JSON Schema (draft 2020-12) of this object's JSON, its parts under $defs.
__schema_body__(definitions)
classmethod
The schema of {identifier: payload}.
BlockCollisionBox
Bases: JsonComponent
[EXPERIMENTAL] The area of the block that collides with entities, as boxes given by their two corners.
It writes minecraft:collision_box like the deprecated origin and size form,
anvil.api.blocks.components.BlockCollisionBox, and clashes with it: a block cannot use both,
in its components or in a permutation.
Experimental: needs features.experimental in anvilconfig.json.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min
|
tuple[float, float, float]
|
The minimal corner of the box, in pixels from the bottom-left corner of the block. |
required |
max
|
tuple[float, float, float]
|
The maximal corner of the box. Boxes must stay within (0, 0, 0) and (16, 24, 16). |
required |
Give either min and max, or a voxel shape with set_voxel_shape. Add more boxes with
add_box, up to 32. Boxes are always written as a list.
__required__ = ()
class-attribute
JSON keys the schema marks required although their field is optional, because
__validate__ requires them.
__from_json__(data)
classmethod
Builds the object from its parsed JSON, the inverse of __json__(). Each key goes
to the field written under it, read through the field's annotation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
The parsed JSON object. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
The data is not an object, or a value does not match its field. |
ValueError
|
The data has a key the class does not write, or a constant field holds another value. |
__json_fields__()
classmethod
The compiled fields of this class, compiled on first use.
__payload_schema__(definitions)
classmethod
The schema of the payload under the identifier.
__post_init__()
Side effects after construction.
__prepare_export__(owner, *, root=True)
Finishes the object for export, where its owner calls it. Components with a
localized name override it. root is False for a permutation's components.
__schema__()
classmethod
The JSON Schema (draft 2020-12) of this object's JSON, its parts under $defs.
__schema_body__(definitions)
classmethod
The schema of {identifier: payload}.
add_box(*, min, max)
Adds another collision box, for more complex shapes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min
|
tuple[float, float, float]
|
The minimal corner of the box. |
required |
max
|
tuple[float, float, float]
|
The maximal corner of the box. |
required |
set_voxel_shape(voxel_shape=None, *, blockbench=None, collection=None)
Uses a voxel shape as the collision shape instead of boxes.
Example
BlockCollisionBox().set_voxel_shape(blockbench="lantern")
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
voxel_shape
|
VoxelShape
|
A voxel shape built in code, queued for export. |
None
|
blockbench
|
str
|
The Blockbench model whose bounding boxes build the shape, the same shape |
None
|
collection
|
str
|
The collection of the Blockbench model to build the shape from. |
None
|
Give either voxel_shape or blockbench.
BlockDestructibleByMining
Bases: _Switchable
Describes how long the block takes to mine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_time_to_destroy
|
int
|
Sets the number of server simulation ticks it takes to mine the block with base equipment. Greater numbers result in greater mining times. A negative number means the block can't be mined. |
required |
item_specific_speeds
|
list[ItemSpecificSpeed]
|
The seconds to mine it with specific items. Set them directly or add them with |
required |
enabled
|
bool
|
False makes the block indestructible by mining, written as |
required |
Documentation reference
__required__ = ()
class-attribute
JSON keys the schema marks required although their field is optional, because
__validate__ requires them.
__from_json__(data)
classmethod
Builds the object from its parsed JSON, the inverse of __json__(). Each key goes
to the field written under it, read through the field's annotation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
The parsed JSON object. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
The data is not an object, or a value does not match its field. |
ValueError
|
The data has a key the class does not write, or a constant field holds another value. |
__json_fields__()
classmethod
The compiled fields of this class, compiled on first use.
__payload_schema__(definitions)
classmethod
The schema of the payload under the identifier.
__post_init__()
Side effects after construction.
__prepare_export__(owner, *, root=True)
Finishes the object for export, where its owner calls it. Components with a
localized name override it. root is False for a permutation's components.
__schema__()
classmethod
The JSON Schema (draft 2020-12) of this object's JSON, its parts under $defs.
__schema_body__(definitions)
classmethod
The schema of {identifier: payload}.
__validate__()
Cross-field checks, run on export after the fields are checked.
add_item_specific_speed(*, item, destroy_speed)
Adds the seconds to mine the block with an item, or items with tags.
Example
mining.add_item_specific_speed( ... item=ItemTagFilter(tags=Query.AllTags(["minecraft:is_axe"])), destroy_speed=1.5 ... )
BlockEnchantmentPowerTransmitter
Bases: JsonValueComponent
[EXPERIMENTAL] Whether the block transmits enchantment power. When true and the block sits
in the 1 block gap between an enchanting table and a bookshelf, the table stays powered by
the bookshelf.
Experimental: needs features.experimental in anvilconfig.json.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
bool
|
Whether the block transmits enchantment power. Defaults to True. |
required |
__required__ = ()
class-attribute
JSON keys the schema marks required although their field is optional, because
__validate__ requires them.
__from_json__(data)
classmethod
Builds the object from its parsed JSON, the inverse of __json__(). Each key goes
to the field written under it, read through the field's annotation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
The parsed JSON object. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
The data is not an object, or a value does not match its field. |
ValueError
|
The data has a key the class does not write, or a constant field holds another value. |
__json_fields__()
classmethod
The compiled fields of this class, compiled on first use.
__post_init__()
Side effects after construction.
__prepare_export__(owner, *, root=True)
Finishes the object for export, where its owner calls it. Components with a
localized name override it. root is False for a permutation's components.
__schema__()
classmethod
The JSON Schema (draft 2020-12) of this object's JSON, its parts under $defs.
__schema_body__(definitions)
classmethod
The schema of {identifier: payload}.
BlockEntity
Bases: BlockEntity
[EXPERIMENTAL] Gives each placed block its own data, with an inventory and entity storage.
It writes minecraft:block_entity like the public BlockEntity, which only has
dynamic_properties. Experimental: needs features.experimental in anvilconfig.json.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
container
|
BlockEntityContainer
|
An inventory. Set it with |
required |
dynamic_properties
|
bool
|
Whether scripts can store dynamic properties on the block. Game default false. |
required |
entity_storage
|
bool
|
Whether scripts can store serialized entities in the block. Game default false. |
required |
Documentation reference
__required__ = ()
class-attribute
JSON keys the schema marks required although their field is optional, because
__validate__ requires them.
__from_json__(data)
classmethod
Builds the object from its parsed JSON, the inverse of __json__(). Each key goes
to the field written under it, read through the field's annotation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
The parsed JSON object. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
The data is not an object, or a value does not match its field. |
ValueError
|
The data has a key the class does not write, or a constant field holds another value. |
__json__()
The component as {identifier: payload}.
__json_fields__()
classmethod
The compiled fields of this class, compiled on first use.
__payload_schema__(definitions)
classmethod
The schema of the payload under the identifier.
__post_init__()
Side effects after construction.
__prepare_export__(owner, *, root=True)
Adds the container title to the language file under
tile.<identifier>.container_title for the root, and
tile.<identifier>.<name>.container_title for a permutation, then writes the key.
__schema__()
classmethod
The JSON Schema (draft 2020-12) of this object's JSON, its parts under $defs.
__schema_body__(definitions)
classmethod
The schema of {identifier: payload}.
set_container(*, slot_count, title=None, show_ui_on_interaction=None)
Gives the block an inventory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slot_count
|
int
|
The number of slots, from 1 to 54. |
required |
title
|
str
|
The title shown on the container, 1 to 256 characters. Anvil adds it to the language file under a key made from the block identifier. Leaving it out leaves the heading blank. |
None
|
show_ui_on_interaction
|
bool
|
Whether interacting with the block opens its container UI. When false, normal block interaction events run instead. Game default true. |
None
|
BlockEntityContainer
Bases: JsonObject
The inventory of a block entity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slot_count
|
int
|
The number of slots, from 1 to 54. |
required |
show_ui_on_interaction
|
bool
|
Determines whether interacting with this block opens its container UI. Defaults to true. When false, normal block interaction events can run instead. |
required |
title
|
str
|
The title shown on the container, 1 to 256 characters. Anvil adds it to the language file under a key made from the block identifier. Leaving it out leaves the heading blank. |
required |
__required__ = ()
class-attribute
JSON keys the schema marks required although their field is optional, because
__validate__ requires them.
__from_json__(data)
classmethod
Builds the object from its parsed JSON, the inverse of __json__(). Each key goes
to the field written under it, read through the field's annotation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
The parsed JSON object. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
The data is not an object, or a value does not match its field. |
ValueError
|
The data has a key the class does not write, or a constant field holds another value. |
__json__()
The JSON payload of this object, built from its fields after checking them.
__json_fields__()
classmethod
The compiled fields of this class, compiled on first use.
__post_init__()
Side effects after construction.
__prepare_export__(owner, *, root=True)
Finishes the object for export, where its owner calls it. Components with a
localized name override it. root is False for a permutation's components.
__schema__()
classmethod
The JSON Schema (draft 2020-12) of this object's JSON, its parts under $defs.
__schema_body__(definitions)
classmethod
The schema of this object's JSON, adding the parts it uses to definitions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
definitions
|
dict[str, JsonSchema]
|
The |
required |
__validate__()
Cross-field checks, run on export after the fields are checked.
BlockJukeBoxPlaylistSource
Bases: JsonComponent
[EXPERIMENTAL] Allows a jukebox directly below this block to use its existing container as a playlist source. This component is an empty object. It does not create a container and has no effect without one.
Experimental: needs features.experimental in anvilconfig.json.
__required__ = ()
class-attribute
JSON keys the schema marks required although their field is optional, because
__validate__ requires them.
__from_json__(data)
classmethod
Builds the object from its parsed JSON, the inverse of __json__(). Each key goes
to the field written under it, read through the field's annotation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
The parsed JSON object. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
The data is not an object, or a value does not match its field. |
ValueError
|
The data has a key the class does not write, or a constant field holds another value. |
__json__()
The component as {identifier: payload}.
__json_fields__()
classmethod
The compiled fields of this class, compiled on first use.
__payload_schema__(definitions)
classmethod
The schema of the payload under the identifier.
__post_init__()
Side effects after construction.
__prepare_export__(owner, *, root=True)
Finishes the object for export, where its owner calls it. Components with a
localized name override it. root is False for a permutation's components.
__schema__()
classmethod
The JSON Schema (draft 2020-12) of this object's JSON, its parts under $defs.
__schema_body__(definitions)
classmethod
The schema of {identifier: payload}.
BlockMinMaxBox
Bases: JsonObject
A box inside the block, in pixels, by its two corners. (0, 0, 0) is the bottom-left corner of the block and (16, 16, 16) the top-right.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min
|
tuple[float, float, float]
|
The minimal corner, within (0, 0, 0) and (16, 24, 16). |
required |
max
|
tuple[float, float, float]
|
The maximal corner, within (0, 0, 0) and (16, 24, 16), not below |
required |
__required__ = ()
class-attribute
JSON keys the schema marks required although their field is optional, because
__validate__ requires them.
__from_json__(data)
classmethod
Builds the object from its parsed JSON, the inverse of __json__(). Each key goes
to the field written under it, read through the field's annotation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
The parsed JSON object. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
The data is not an object, or a value does not match its field. |
ValueError
|
The data has a key the class does not write, or a constant field holds another value. |
__json__()
The JSON payload of this object, built from its fields after checking them.
__json_fields__()
classmethod
The compiled fields of this class, compiled on first use.
__post_init__()
Side effects after construction.
__prepare_export__(owner, *, root=True)
Finishes the object for export, where its owner calls it. Components with a
localized name override it. root is False for a permutation's components.
__schema__()
classmethod
The JSON Schema (draft 2020-12) of this object's JSON, its parts under $defs.
__schema_body__(definitions)
classmethod
The schema of this object's JSON, adding the parts it uses to definitions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
definitions
|
dict[str, JsonSchema]
|
The |
required |
BlockNeighborChange
Bases: JsonComponent
[EXPERIMENTAL] Which neighbouring block changes trigger the neighbor change after event of
the block's custom components.
Experimental: needs features.experimental in anvilconfig.json.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
neighbor_directions
|
list[all | up | down | north | south | west | east]
|
The directions to observe, 1 to 6 of them, no repeats. "all" must be used alone. |
required |
__required__ = ()
class-attribute
JSON keys the schema marks required although their field is optional, because
__validate__ requires them.
__from_json__(data)
classmethod
Builds the object from its parsed JSON, the inverse of __json__(). Each key goes
to the field written under it, read through the field's annotation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
The parsed JSON object. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
The data is not an object, or a value does not match its field. |
ValueError
|
The data has a key the class does not write, or a constant field holds another value. |
__json__()
The component as {identifier: payload}.
__json_fields__()
classmethod
The compiled fields of this class, compiled on first use.
__payload_schema__(definitions)
classmethod
The schema of the payload under the identifier.
__post_init__()
Side effects after construction.
__prepare_export__(owner, *, root=True)
Finishes the object for export, where its owner calls it. Components with a
localized name override it. root is False for a permutation's components.
__schema__()
classmethod
The JSON Schema (draft 2020-12) of this object's JSON, its parts under $defs.
__schema_body__(definitions)
classmethod
The schema of {identifier: payload}.
BlockVibrationProperties
Bases: JsonComponent
[EXPERIMENTAL] How the block affects vibrations.
Experimental: needs features.experimental in anvilconfig.json.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dampen_vibrations
|
bool
|
Whether the block dampens vibrations. The game defaults to False. |
required |
occlude_vibrations
|
bool
|
Whether the block occludes vibrations. The game defaults to False. |
required |
__required__ = ()
class-attribute
JSON keys the schema marks required although their field is optional, because
__validate__ requires them.
__from_json__(data)
classmethod
Builds the object from its parsed JSON, the inverse of __json__(). Each key goes
to the field written under it, read through the field's annotation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
The parsed JSON object. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
The data is not an object, or a value does not match its field. |
ValueError
|
The data has a key the class does not write, or a constant field holds another value. |
__json__()
The component as {identifier: payload}.
__json_fields__()
classmethod
The compiled fields of this class, compiled on first use.
__payload_schema__(definitions)
classmethod
The schema of the payload under the identifier.
__post_init__()
Side effects after construction.
__prepare_export__(owner, *, root=True)
Finishes the object for export, where its owner calls it. Components with a
localized name override it. root is False for a permutation's components.
__schema__()
classmethod
The JSON Schema (draft 2020-12) of this object's JSON, its parts under $defs.
__schema_body__(definitions)
classmethod
The schema of {identifier: payload}.