🧾 recipes#

Recipe rendering package.

Re-exports the dispatcher and the public registry surface. Existing call sites keep importing from ..recipes. The built-in type renderers load on first lookup rather than on import, see load_builtin_renderers().

buttons#

The typed wiki button produced by the recipe renderer.

class WikiButtonRender(
*,
glyph: str,
hover: TextComponent,
target: PageRef | JsonDict | None = None,
blue_craft: bool = False,
priority: int = 1,
is_info: bool = False,
)[source]#

Bases: object

A single wiki button (icon + hover) with a deferred click target.

blue_craft marks a craft that has no result (only ingredients), used by overflow handling. target is either a PageRef (resolved after page ordering) or a literal click-event dict (e.g. an author-provided open_url from a WikiButton).

>>> button = WikiButtonRender(glyph="X", hover=["Some hover text"])
>>> button.priority, button.target is None
(1, True)
glyph: str[source]#

The font character drawn as the button icon.

hover: TextComponent[source]#

Tooltip content shown when hovering the button.

target: PageRef | JsonDict | None[source]#

Deferred page link, literal click event, or None for no click action.

blue_craft: bool[source]#

True for crafts without a result (only ingredients); used by overflow handling.

priority: int[source]#

Higher priority buttons survive overflow trimming longer.

is_info: bool[source]#

True for WikiButton info buttons (kept first, never treated as blue).

collection#

Craft collection and pure recipe helpers.

collect_for_item gathers an item’s own recipes, the crafts that consume it, and mining pseudo-recipes from no-silk-touch drops. remove_unknown_crafts keeps only craft types that have a registered CraftRenderer, so it auto-extends with new types.

convert_shapeless_to_shaped(
craft: JsonDict,
) → JsonDict[source]#

Convert a shapeless craft to a readable shaped layout.

>>> craft = {"type": "crafting_shapeless", "result_count": 1, "ingredients": [{"item": "minecraft:stick"}] * 4}
>>> shaped = convert_shapeless_to_shaped(craft)
>>> shaped["type"], shaped["shape"]
('crafting_shaped', ['AA', 'AA'])
>>> nine = {
...     "type": "crafting_shapeless", "result_count": 1,
...     "ingredients": [{"item": "minecraft:iron_ingot"}] * 8 + [{"item": "minecraft:diamond"}],
... }
>>> convert_shapeless_to_shaped(nine)["shape"]
['AAA', 'ABA', 'AAA']
shaped_layout(ordered_keys: list[str]) → list[str][source]#

The grid showing a shapeless craft’s ingredients, a ring around the odd one out when there is one.

>>> shaped_layout(list("AAAAB")), shaped_layout(list("ABBBBCCCC")), shaped_layout(list("ABCDE"))
([' A ', 'ABA', ' A '], ['BCB', 'CAC', 'BCB'], ['ABC', 'DE'])
column_count(total_items: int) → int[source]#

The columns a grid of total_items takes: a square when the count is one, else the narrowest of 2, 3 or 4 that fits.

>>> [column_count(n) for n in (1, 3, 4, 7, 9, 12, 16)]
[1, 2, 2, 3, 3, 4, 4]
remove_duplicate_furnace_crafts(
crafts: list[JsonDict],
item: str,
) → list[JsonDict][source]#

Keep only one furnace craft per (ingredient, result, count) triple.

remove_unknown_crafts(
crafts: list[JsonDict],
) → list[JsonDict][source]#

Drop crafts whose type has no registered renderer.

craft_ingredient_ids(
craft: RecipeBase,
) → set[str][source]#

All ingredient ids (without namespace) appearing in a craft.

item_in_ingredients(
item: str,
craft: RecipeBase,
) → bool[source]#

Whether item appears among a craft’s ingredients.

build_consumer_index(
definitions: dict[str, Item],
) → dict[str, list[tuple[str, JsonDict]]][source]#

Map each ingredient id to the (consumer item, craft) pairs that consume it.

One pass over all recipes, so generate_otherside_crafts() becomes a dict lookup instead of an O(items x recipes) rescan per item.

generate_otherside_crafts(
item: str,
definitions: dict[str, Item],
index: dict[str, list[tuple[str, JsonDict]]] | None = None,
) → list[JsonDict][source]#

Find crafts in other items that consume item (the “used for crafting” list).

collect_for_item(
r: RecipeRenderer,
name: str,
item_obj: Item,
definitions_as_objects: dict[str, Item],
) → list[JsonDict][source]#

Gather an item’s own recipes, otherside crafts, and mining drops (deduped).

ores_dropping(name: str) → list[str][source]#

The items that drop name when mined without silk touch.

drop_id(
drop: JsonDict | NoSilkTouchDrop | str | LootTable,
) → str | None[source]#

The item a no silk touch drop gives, None for a loot table.

own_mining_recipe(
name: str,
drop: JsonDict | NoSilkTouchDrop | str | LootTable,
ns: str,
) → JsonDict[source]#

The pseudo recipe showing what mining name without silk touch drops, a loot table’s drop being dynamic.

add_mining_count(
mining_recipe: JsonDict,
drop: JsonDict | NoSilkTouchDrop | str | LootTable,
) → None[source]#

Mark a loot table’s drop as dynamic, or show the count a drop gives, min-max for a range.

>>> recipe = {}
>>> add_mining_count(recipe, {"id": "x", "count": {"min": 1, "max": 3}}); recipe
{'result_count': '1-3'}

registry#

Recipe-type renderer base class and the global registry.

Each recipe type has one CraftRenderer that owns all of its rendering: the main page layout (render_body()), the wiki-button hover lines (append_hover()), its human name (name), its high-res template glyph (static_glyph()) and its low-res image (build_image()). Renderers register themselves into CRAFT_RENDERERS via register_craft_renderer(), so adding a recipe type is one new file + one call.

The r argument passed to renderer methods is the RecipeRenderer dispatcher, exposing r.config / r.glyphs / r.images / r.item_component(...) / r.append_or_invisible(...) / r.render_main(...).

class CraftRenderer[source]#

Bases: object

Base class for a recipe-type renderer.

Subclass it, set types (and optionally name), override the render methods you need, then call register_craft_renderer() on an instance.

>>> class _EchoRenderer(CraftRenderer):
...     types = ("test_echo",)
...     name = "Echo"
>>> _ = register_craft_renderer(_EchoRenderer())
>>> get_craft_renderer("test_echo") is CRAFT_RENDERERS["test_echo"]
True
>>> get_craft_renderer("unknown_type") is None
True
>>> del CRAFT_RENDERERS["test_echo"]
types: ClassVar[tuple[str, ...]] = ()[source]#

The craft type strings this renderer handles.

name: ClassVar[str] = ''[source]#

Human title shown in the wiki-button hover. Empty = no title line (e.g. crafting recipes).

static_glyph(
craft: JsonDict,
) → str[source]#

The high-res template glyph for this craft (empty if the type has no template).

render_body(
r: RecipeRenderer,
craft: JsonDict,
name: str,
content: list[TextComponent],
result_component: JsonDict,
page_font: str,
use_dialog: bool,
add_change_page_to_ingr: bool,
) → None[source]#

Append this craft’s page layout to content. Subclasses must implement.

add_change_page_to_ingr is the prologue flag controlling whether the single ingredient links to its page (used by furnace/linear layouts).

append_hover(
r: RecipeRenderer,
craft: JsonDict,
hover: list[TextComponent],
) → None[source]#

Append per-ingredient hover lines. Default: a single - x1 <ingredient> line.

build_image(
r: RecipeRenderer,
name: str,
page_font: str,
craft: JsonDict,
output_name: str = '',
) → None[source]#

Generate the low-resolution recipe PNG (no-op for types that don’t need one).

CRAFT_RENDERERS: dict[str, CraftRenderer] = {'blasting': BlastingRenderer(), 'campfire_cooking': CampfireRenderer(), 'crafting_shaped': ShapedRenderer(), 'crafting_shapeless': ShapedRenderer(), 'mining': MiningRenderer(), 'simplenergy_pulverizing': PulverizingRenderer(), 'smelting': SmeltingRenderer(), 'smithing_transform': SmithingTransformRenderer(), 'smithing_trim': SmithingTrimRenderer(), 'smoking': SmokingRenderer(), 'stardust_awakened_forge': AwakenedForgeRenderer(), 'stonecutting': StonecuttingRenderer()}[source]#

Registry of all craft renderers, by craft type.

BUILTIN_RENDERER_MODULES: tuple[str, ...] = ('awakened_forge', 'furnace', 'linear', 'shaped', 'smithing')[source]#

Modules under .types that register the built-in renderers when they execute.

register_craft_renderer(
renderer: CraftRenderer,
) → CraftRenderer[source]#

Register renderer for each of its types. Returns it.

load_builtin_renderers() → dict[str, CraftRenderer][source]#

Import the built-in renderer modules once, then return the populated registry.

Those modules register themselves as a side effect of executing, which under PEP 810 never happens on its own since nothing imports them by name. Every lookup goes through here instead of relying on the package import that used to pull them in eagerly.

Returns:

The registry, with every built-in renderer present

Return type:

dict[str, CraftRenderer]

>>> "crafting_shaped" in load_builtin_renderers()
True
get_craft_renderer(
craft_type: str,
) → CraftRenderer | None[source]#

Return the renderer registered for craft_type (or None).

renderer#

The RecipeRenderer dispatcher.

Builds craft content, item hover components and wiki buttons for a manual by delegating each recipe type to its registered CraftRenderer. Keeps the shared prologue and button scaffolding; the per-type layout/hover/glyph/image live under types.

class RecipeRenderer(manual: Manual)[source]#

Bases: object

Dispatcher: delegates per-type rendering to the registry, owns the shared scaffolding.

eq=False keeps identity semantics: this class and Manual reference each other, so field-based equality would recurse.

manual: Manual[source]#

The owning Manual instance.

consumer_index_cache: tuple[dict[str, Item], dict[str, list[tuple[str, JsonDict]]]] | None[source]#

Memoized (definitions, consumer index) pair used by collect_for_item().

Keyed on the definitions dict identity so watch rebuilds and later definition changes get a fresh index. One renderer exists per manual build, hence caching it here.

property config: ManualConfig[source]#

Shortcut to the manual’s ManualConfig.

property glyphs: GlyphAllocator[source]#

Shortcut to the manual’s GlyphAllocator.

property images: GlyphImageBuilder[source]#

Shortcut to the manual’s GlyphImageBuilder.

item_component(
ingredient: str | Ingr,
only_those_components: list[str] | None = None,
count: int = 1,
add_change_page: bool = True,
) → JsonDict[source]#

Build a hoverable/clickable text component for an ingredient.

high_res_font_from_ingredient(
ingredient: str | Ingr,
count: int = 1,
) → str[source]#

Generate the high-res glyph for an ingredient.

collect_for_item(
name: str,
item_obj: Item,
definitions_as_objects: dict[str, Item],
) → list[JsonDict][source]#

Gather an item’s own recipes, otherside crafts, and mining drops (deduped).

static append_or_invisible(
content: list[TextComponent],
component: JsonDict,
i: int,
) → None[source]#

Append component on the first row, an invisible-width copy on the second.

render_main(
craft: JsonDict,
name: str,
page_font: str,
in_lore: bool = False,
) → list[TextComponent][source]#

Build the full text-component layout for a single craft shown on a page.

render_button(
craft: JsonDict,
name: str,
index: int = 0,
) → WikiButtonRender[source]#

Build a single wiki button (hover + icon + deferred target) for a craft.

index makes the low-resolution recipe image filename stable/unique per button.

craft_preview(
craft: JsonDict,
name: str,
index: int,
) → list[TextComponent][source]#

The start of a button’s hover: the craft’s glyph in low resolution, its page content in high resolution.

static target_button(
button: WikiButtonRender,
craft: JsonDict,
name: str,
) → None[source]#

Point a button at the page of what the craft makes, or of its single ingredient when it makes the page’s item.

A craft with no result is one using the page’s item, drawn blue.

static single_ingredient(
craft: JsonDict,
) → str[source]#

The id of a craft’s only ingredient, empty when it has several.

>>> RecipeRenderer.single_ingredient({"ingredients": {"X": {"item": "minecraft:stick"}}})
'stick'
button_for_item(
item_id: str,
index: int = 0,
) → WikiButtonRender | None[source]#

Build the wiki button of another item’s craft, linking to that item’s page.

Use it to cross-link related pages, e.g. show the Starlight Infuser’s recipe button on the Stardust Pillar page. index selects which of the item’s crafts to render (same order as its own page). Returns None (with a warning) if the item has no such craft.

Build a wiki button that simply links to another item’s page (no recipe).

The icon shows the item in a wiki slot; hover defaults to its name plus a click hint. craft_type picks the slot background: "source_link" is the grey one of the seeds and containers an item comes from.

growing_seed_button(
item_obj: Item,
) → WikiButtonRender | None[source]#

Build an info button describing a block’s GrowingSeed drops, if any.

static drop_lines(
loot: GrowingSeedLoot,
) → list[TextComponent][source]#

The hover lines describing one drop of a growing seed: how many, of what, and what Fortune adds.