Skip to content

Commit db37c5b

Browse files
committed
Add flay cost to hexdoc brainsweep recipe
1 parent ce5a14f commit db37c5b

File tree

4 files changed

+61
-2
lines changed

4 files changed

+61
-2
lines changed

doc/src/hexdoc_hexcasting/_templates/index.css.jinja

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
left: 24px;
1818
}
1919

20+
.flay-recipe-cost{
21+
position: absolute;
22+
top: 110px;
23+
left: 24px;
24+
}
25+
2026
/* entity chamber starts at top: 38px & left: 74px. it is 52px wide & 96px tall */
2127
.flay-recipe-entity{
2228
position: absolute;

doc/src/hexdoc_hexcasting/_templates/recipes/hexcasting/brainsweep.html.jinja

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@
3434
</div>
3535
{% endblock ingredient %}
3636

37+
{% block cost %}
38+
<div class="flay-recipe-cost texture item-texture multi-textures cycle-textures">
39+
{% for item in recipe.cost_items %}
40+
<div class="texture item-texture {{ 'multi-texture-active' if loop.first }}">
41+
{{ texture_macros.render_item(item|hexdoc_item, count=item.count, is_first=true) }}
42+
</div>
43+
{% endfor %}
44+
</div>
45+
{% endblock cost %}
46+
3747
{% block result %}
3848
<div class="flay-recipe-result">
3949
{{ texture_macros.render_item(recipe.result.name) }}

doc/src/hexdoc_hexcasting/book/recipes.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
from abc import ABC, abstractmethod
22
from typing import Any, Literal, Self
33

4-
from hexdoc.core import IsVersion, ResourceLocation
4+
from hexdoc.core import IsVersion, ItemStack, ResourceLocation
55
from hexdoc.minecraft.assets import ItemWithTexture, PNGTexture
66
from hexdoc.minecraft.i18n import I18n, LocalizedStr
77
from hexdoc.minecraft.recipe import ItemIngredient, ItemIngredientList, Recipe
88
from hexdoc.model import HexdocModel, TypeTaggedTemplate
99
from hexdoc.utils import NoValue, classproperty
10+
from hexdoc_hexcasting.utils.constants import (
11+
MEDIA_CRYSTAL_UNIT,
12+
MEDIA_DUST_UNIT,
13+
MEDIA_SHARD_UNIT,
14+
)
1015
from pydantic import Field, PrivateAttr, ValidationInfo, model_validator
1116

1217
# ingredients
@@ -139,16 +144,44 @@ def brainsweepee(self) -> Any:
139144
For example, `BrainsweepRecipe_0_11` returns `entityIn`.
140145
"""
141146

147+
@property
148+
@abstractmethod
149+
def cost(self) -> int:
150+
"""Returns the cost of this recipe in raw media units."""
151+
152+
@property
153+
def cost_items(self) -> list[ItemStack]:
154+
"""Returns the items to display for the recipe's cost."""
155+
156+
costs = [
157+
("hexcasting", "amethyst_dust", MEDIA_DUST_UNIT),
158+
("minecraft", "amethyst_shard", MEDIA_SHARD_UNIT),
159+
("hexcasting", "charged_amethyst", MEDIA_CRYSTAL_UNIT),
160+
]
161+
162+
return [
163+
ItemStack(namespace, path, self.cost // media)
164+
for namespace, path, media in costs
165+
if self.cost % media == 0
166+
] or [
167+
# fallback if nothing divides evenly
168+
ItemStack("hexcasting", "amethyst_dust", self.cost // MEDIA_DUST_UNIT),
169+
]
170+
142171

143172
@IsVersion(">=1.20")
144173
class BrainsweepRecipe_0_11(BrainsweepRecipe, type="hexcasting:brainsweep"):
145-
cost: int
174+
cost_: int = Field(alias="cost")
146175
entityIn: BrainsweepeeIngredient
147176

148177
@property
149178
def brainsweepee(self):
150179
return self.entityIn
151180

181+
@property
182+
def cost(self):
183+
return self.cost_
184+
152185

153186
@IsVersion("<1.20")
154187
class BrainsweepRecipe_0_10(BrainsweepRecipe, type="hexcasting:brainsweep"):
@@ -157,3 +190,7 @@ class BrainsweepRecipe_0_10(BrainsweepRecipe, type="hexcasting:brainsweep"):
157190
@property
158191
def brainsweepee(self):
159192
return self.villagerIn
193+
194+
@property
195+
def cost(self):
196+
return 10 * MEDIA_CRYSTAL_UNIT
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
MEDIA_DUST_UNIT = 10000
2+
MEDIA_SHARD_UNIT = 5 * MEDIA_DUST_UNIT
3+
MEDIA_CRYSTAL_UNIT = 10 * MEDIA_DUST_UNIT
4+
5+
MEDIA_QUENCHED_SHARD_UNIT = 3 * MEDIA_CRYSTAL_UNIT
6+
MEDIA_QUENCHED_BLOCK_UNIT = 4 * MEDIA_QUENCHED_SHARD_UNIT

0 commit comments

Comments
 (0)