From db37c5b2cc56a2a67e6b8761b9f2e4d34db0a7d0 Mon Sep 17 00:00:00 2001 From: object-Object Date: Mon, 25 Nov 2024 12:22:50 -0500 Subject: [PATCH] Add flay cost to hexdoc brainsweep recipe --- .../_templates/index.css.jinja | 6 +++ .../recipes/hexcasting/brainsweep.html.jinja | 10 +++++ doc/src/hexdoc_hexcasting/book/recipes.py | 41 ++++++++++++++++++- doc/src/hexdoc_hexcasting/utils/constants.py | 6 +++ 4 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 doc/src/hexdoc_hexcasting/utils/constants.py diff --git a/doc/src/hexdoc_hexcasting/_templates/index.css.jinja b/doc/src/hexdoc_hexcasting/_templates/index.css.jinja index d609633a5d..eeb0602801 100644 --- a/doc/src/hexdoc_hexcasting/_templates/index.css.jinja +++ b/doc/src/hexdoc_hexcasting/_templates/index.css.jinja @@ -17,6 +17,12 @@ left: 24px; } +.flay-recipe-cost{ + position: absolute; + top: 110px; + left: 24px; +} + /* entity chamber starts at top: 38px & left: 74px. it is 52px wide & 96px tall */ .flay-recipe-entity{ position: absolute; diff --git a/doc/src/hexdoc_hexcasting/_templates/recipes/hexcasting/brainsweep.html.jinja b/doc/src/hexdoc_hexcasting/_templates/recipes/hexcasting/brainsweep.html.jinja index 69bad23a85..8b6e9439a3 100644 --- a/doc/src/hexdoc_hexcasting/_templates/recipes/hexcasting/brainsweep.html.jinja +++ b/doc/src/hexdoc_hexcasting/_templates/recipes/hexcasting/brainsweep.html.jinja @@ -34,6 +34,16 @@ {% endblock ingredient %} + {% block cost %} +
+ {% for item in recipe.cost_items %} +
+ {{ texture_macros.render_item(item|hexdoc_item, count=item.count, is_first=true) }} +
+ {% endfor %} +
+ {% endblock cost %} + {% block result %}
{{ texture_macros.render_item(recipe.result.name) }} diff --git a/doc/src/hexdoc_hexcasting/book/recipes.py b/doc/src/hexdoc_hexcasting/book/recipes.py index d99c2cdfc0..1389f7e923 100644 --- a/doc/src/hexdoc_hexcasting/book/recipes.py +++ b/doc/src/hexdoc_hexcasting/book/recipes.py @@ -1,12 +1,17 @@ from abc import ABC, abstractmethod from typing import Any, Literal, Self -from hexdoc.core import IsVersion, ResourceLocation +from hexdoc.core import IsVersion, ItemStack, ResourceLocation from hexdoc.minecraft.assets import ItemWithTexture, PNGTexture from hexdoc.minecraft.i18n import I18n, LocalizedStr from hexdoc.minecraft.recipe import ItemIngredient, ItemIngredientList, Recipe from hexdoc.model import HexdocModel, TypeTaggedTemplate from hexdoc.utils import NoValue, classproperty +from hexdoc_hexcasting.utils.constants import ( + MEDIA_CRYSTAL_UNIT, + MEDIA_DUST_UNIT, + MEDIA_SHARD_UNIT, +) from pydantic import Field, PrivateAttr, ValidationInfo, model_validator # ingredients @@ -139,16 +144,44 @@ def brainsweepee(self) -> Any: For example, `BrainsweepRecipe_0_11` returns `entityIn`. """ + @property + @abstractmethod + def cost(self) -> int: + """Returns the cost of this recipe in raw media units.""" + + @property + def cost_items(self) -> list[ItemStack]: + """Returns the items to display for the recipe's cost.""" + + costs = [ + ("hexcasting", "amethyst_dust", MEDIA_DUST_UNIT), + ("minecraft", "amethyst_shard", MEDIA_SHARD_UNIT), + ("hexcasting", "charged_amethyst", MEDIA_CRYSTAL_UNIT), + ] + + return [ + ItemStack(namespace, path, self.cost // media) + for namespace, path, media in costs + if self.cost % media == 0 + ] or [ + # fallback if nothing divides evenly + ItemStack("hexcasting", "amethyst_dust", self.cost // MEDIA_DUST_UNIT), + ] + @IsVersion(">=1.20") class BrainsweepRecipe_0_11(BrainsweepRecipe, type="hexcasting:brainsweep"): - cost: int + cost_: int = Field(alias="cost") entityIn: BrainsweepeeIngredient @property def brainsweepee(self): return self.entityIn + @property + def cost(self): + return self.cost_ + @IsVersion("<1.20") class BrainsweepRecipe_0_10(BrainsweepRecipe, type="hexcasting:brainsweep"): @@ -157,3 +190,7 @@ class BrainsweepRecipe_0_10(BrainsweepRecipe, type="hexcasting:brainsweep"): @property def brainsweepee(self): return self.villagerIn + + @property + def cost(self): + return 10 * MEDIA_CRYSTAL_UNIT diff --git a/doc/src/hexdoc_hexcasting/utils/constants.py b/doc/src/hexdoc_hexcasting/utils/constants.py new file mode 100644 index 0000000000..89b296105b --- /dev/null +++ b/doc/src/hexdoc_hexcasting/utils/constants.py @@ -0,0 +1,6 @@ +MEDIA_DUST_UNIT = 10000 +MEDIA_SHARD_UNIT = 5 * MEDIA_DUST_UNIT +MEDIA_CRYSTAL_UNIT = 10 * MEDIA_DUST_UNIT + +MEDIA_QUENCHED_SHARD_UNIT = 3 * MEDIA_CRYSTAL_UNIT +MEDIA_QUENCHED_BLOCK_UNIT = 4 * MEDIA_QUENCHED_SHARD_UNIT