🧾 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().
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,
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_itemstakes: 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,
Keep only one furnace craft per (ingredient, result, count) triple.
- remove_unknown_crafts(
- crafts: list[JsonDict],
Drop crafts whose type has no registered renderer.
- craft_ingredient_ids(
- craft: RecipeBase,
All ingredient ids (without namespace) appearing in a craft.
- item_in_ingredients(
- item: str,
- craft: RecipeBase,
Whether
itemappears among a craft’s ingredients.
- build_consumer_index(
- definitions: dict[str, Item],
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,
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],
Gather an item’s own recipes, otherside crafts, and mining drops (deduped).
- drop_id(
- drop: JsonDict | NoSilkTouchDrop | str | LootTable,
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,
The pseudo recipe showing what mining
namewithout silk touch drops, a loot table’s drop being dynamic.
- add_mining_count(
- mining_recipe: JsonDict,
- drop: JsonDict | NoSilkTouchDrop | str | LootTable,
Mark a loot table’s drop as dynamic, or show the count a drop gives,
min-maxfor 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:
objectBase class for a recipe-type renderer.
Subclass it, set
types(and optionallyname), override the render methods you need, then callregister_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"]
- name: ClassVar[str] = ''[source]#
Human title shown in the wiki-button hover. Empty = no title line (e.g. crafting recipes).
- static_glyph(
- craft: JsonDict,
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,
Append this craft’s page layout to
content. Subclasses must implement.add_change_page_to_ingris 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],
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 = '',
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,
Register
rendererfor each of itstypes. 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,
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:
objectDispatcher: delegates per-type rendering to the registry, owns the shared scaffolding.
eq=Falsekeeps identity semantics: this class andManualreference each other, so field-based equality would recurse.- 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,
Build a hoverable/clickable text component for an ingredient.
- high_res_font_from_ingredient(
- ingredient: str | Ingr,
- count: int = 1,
Generate the high-res glyph for an ingredient.
- collect_for_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,
Append
componenton the first row, an invisible-width copy on the second.
- render_main(
- craft: JsonDict,
- name: str,
- page_font: str,
- in_lore: bool = False,
Build the full text-component layout for a single craft shown on a page.
- render_button(
- craft: JsonDict,
- name: str,
- index: int = 0,
Build a single wiki button (hover + icon + deferred target) for a craft.
indexmakes the low-resolution recipe image filename stable/unique per button.
- craft_preview(
- craft: JsonDict,
- name: str,
- index: int,
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,
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,
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,
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.
indexselects 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.
- link_button(
- item_id: str,
- hover: TextComponent | None = None,
- craft_type: str = 'page_link',
Build a wiki button that simply links to another item’s page (no recipe).
The icon shows the item in a wiki slot;
hoverdefaults to its name plus a click hint.craft_typepicks the slot background:"source_link"is the grey one of the seeds and containers an item comes from.
- growing_seed_button(
- item_obj: Item,
Build an info button describing a block’s
GrowingSeeddrops, if any.
- static drop_lines(
- loot: GrowingSeedLoot,
The hover lines describing one drop of a growing seed: how many, of what, and what Fortune adds.