🎨 item_models#

Generates the item models of the resource pack.

add_to_atlas(textures: set[str] = {}) → None[source]#

Add textures to the specified atlas.

Parameters:

textures – The set of texture paths to add. Defaults to an empty set.

beet_default(ctx: Context)[source]#

Main entry point for the item models plugin.

Parameters:

ctx – The beet context.

object#

class BlockShape(parent: str, sides: tuple[str, ...])[source]#

Bases: object

A vanilla block model a custom block takes when it has a texture for each of its sides.

parent: str[source]#
sides: tuple[str, ...][source]#
BLOCK_SHAPES: tuple[BlockShape, ...] = (BlockShape(parent='block/cake', sides=('bottom', 'side', 'top', 'inner')), BlockShape(parent='block/orientable_with_bottom', sides=('front', 'bottom', 'side', 'top')), BlockShape(parent='block/cube_bottom_top', sides=('bottom', 'side', 'top')), BlockShape(parent='block/orientable', sides=('front', 'side', 'top')), BlockShape(parent='block/cube_column', sides=('end', 'side')))[source]#

Tried in order, the first whose sides all have a texture winning.

to_atlas(texture: str) → str[source]#

Convert a texture path to its atlas sprite path.

Parameters:

texture – The original texture path.

Returns:

The converted atlas sprite path.

Return type:

str

class AutoModel(
data: Item,
source_textures: dict[str, str],
ignore_textures: bool = False,
)[source]#

Bases: object

Class to handle item model processing.

DEFAULT_PARENT: str = 'item/generated'[source]#
obj: Item[source]#

The item data from the definitions.

ns: str[source]#

The namespace of the item model.

block_or_item: str[source]#

Whether this is a block or item model.

used_textures: set[str][source]#

Set of used textures.

used_minecraft_textures: set[str][source]#

Set of used Minecraft textures.

source_textures: dict[str, str][source]#

Dictionary of source textures.

ignore_textures: bool[source]#

Whether to ignore texture-related errors.

parent: str[source]#

The parent model of this item model.

textures: JsonDict[source]#

The textures used by this item model.

classmethod from_definitions(
data: Item,
source_textures: dict[str, str],
ignore_textures: bool = False,
) → AutoModel[source]#

Create an AutoModel from a definitions entry.

Parameters:
  • data – The item data from the definitions.

  • source_textures – Dictionary of source textures.

  • ignore_textures – Whether to ignore textures in the model.

Returns:

The created AutoModel instance.

Return type:

AutoModel

get_powered_texture(
variants: list[str],
side: str,
on_off: str,
) → str[source]#

Get the powered texture for a given side.

Parameters:
  • variants – List of texture variants.

  • side – The side to get the texture for.

  • on_off – The power state suffix.

Returns:

The texture path.

Return type:

str

model_in_variants(
models: Iterable[str],
variants: list[str],
) → bool[source]#

Check if all models are in a string of any variant.

Parameters:
  • models – List of models to check.

  • variants – List of variants to check against.

Returns:

True if all models are in variants.

Return type:

bool

get_same_folder_variants(
variants: Iterable[str],
) → list[str][source]#

Get variants that are in the same folder as the item.

Parameters:

variants – Iterable of variant names.

Returns:

List of variants in the same folder.

Return type:

list[str]

handle_growing_seeds() → None[source]#

Handle growing seeds by adding growth stage models and textures.

copy_and_register_textures(
content: JsonDict,
) → None[source]#

Copy a model’s textures to the assets and register them for atlas handling.

Parameters:

content – The model content whose textures should be processed (may be modified in place).

copy_texture(texture: str) → None[source]#

Copy one texture of the project into the assets, found in the source textures by its file name.

Raises:

ValueError – When it is not there and ignore_textures is off.

handle_hand_model(
variants: list[str],
on_off: str,
) → JsonDict[source]#

Generate the in-hand model from the item’s hand_model and return the items/ definition switching between the regular and in-hand models based on the display context.

Parameters:
  • variants – List of texture variants of the item.

  • on_off – The power state suffix.

Returns:

The content of the items/ definition file.

Return type:

JsonDict

process() → set[str][source]#

Write the item’s models, and its items/ definition, for each of its power states.

Returns:

Block textures to be added to the items atlas.

own_variants() → list[str][source]#

The source textures named after the item, at most 2 underscores longer than its id.

The bound keeps awakened_stardust.png from claiming awakened_stardust_furnace_generator_on.png.

power_states() → list[str][source]#

The suffixes to write a model for, _on first when the item has a texture ending in _on.

The plain items definition written after it then finds the _on model a lit host shows.

write_power_state(
variants: list[str],
on_off: str,
overrides: JsonDict,
) → None[source]#

Write the model and the items/ definition of one power state, on_off being “” or “_on”.

margin_scale() → float[source]#

The scale the elements of the model grow by when a display shows it in a host, 1.0 for none.

write_displayed_elements(
content: JsonDict,
on_off: str,
) → None[source]#

Grow the elements of the model, and write the copies of it a block shows turned by uvlock, flipped by half, or as the corner its stairs host makes.

host_state_select(
model: JsonDict,
suffix: str,
) → JsonDict[source]#

model, or a select showing the copy of it drawn for the host state the display’s custom_model_data string names.

datapack.custom_blocks keeps that string on the state of VanillaBlock.host_states the host is in.

block_content(
variants: list[str],
on_off: str,
overrides: JsonDict,
) → JsonDict[source]#

A block’s model: one texture on every face, or the first of BLOCK_SHAPES its textures fill.

Raises:

ValueError – When its textures fill no shape, the model overrides none, and ignore_textures is off.

block_shape(
variants: list[str],
overrides: JsonDict,
) → BlockShape | None[source]#

The first of BLOCK_SHAPES the block’s textures fill, None when they fill none.

Raises:

ValueError – When they fill none, the model overrides no texture, and ignore_textures is off.

item_content(
variants: list[str],
on_off: str,
overrides: JsonDict,
) → JsonDict[source]#

An item’s model: its base item’s parent, with a second layer for leather and overlays, and pulling states for a bow.

write_bow_pulling(
variants: list[str],
parent: str,
on_off: str,
) → None[source]#

Write a model per _pulling_<n> texture, and the items/ definition switching between them as the bow is drawn.

write_layer_model(
variant: str,
parent: str,
suffix: str,
) → None[source]#

Copy the texture variant and write the model showing it, the item’s model with suffix.

charged_model(
variants: list[str],
parent: str,
charge: str,
last_pulling: int,
) → JsonDict[source]#

The model of a crossbow loaded with an arrow or a rocket, from its _arrow or _firework texture, else its drawn one.

items_definition(
variants: list[str],
on_off: str,
) → JsonDict[source]#

The items/ definition: the hand model’s switch, a spear’s in-hand switch, or the model alone.

spear_definition(
on_off: str,
) → JsonDict[source]#

Write a spear’s in-hand model and texture, and return the items/ definition showing it outside the GUI.

displayed_elements(
model: JsonDict,
) → JsonList | None[source]#

The elements a model draws: its own, its first parent’s in the pack, or those of a cube or cake vanilla parent.

displayed_variants(
vanilla: VanillaBlock | None,
on_off: str,
) → list[tuple[int, bool, str]][source]#

The turn, half and stairs corner of each copy of the model a display shows, all but the model itself.

The corners of a turn and half come before its plain copy, so the items definition written with that copy finds them.

displayed_copy(
elements: JsonList,
y: int,
upper: bool,
corner: str,
scale: float,
) → JsonList[source]#

The elements cut into a stairs corner unless empty, turned y degrees, flipped on the upper half, grown by scale.

excludes_textures(
overrides: JsonDict,
) → bool[source]#

Whether the model overrides set textures to None, which leaves the model without any.

switch_on(
textures: JsonDict,
variants: list[str],
) → None[source]#

Point each texture at its _on variant where the item has one.

silent#