Skip to content

Commit

Permalink
Add flay cost to hexdoc brainsweep recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
object-Object committed Nov 25, 2024
1 parent ce5a14f commit db37c5b
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
6 changes: 6 additions & 0 deletions doc/src/hexdoc_hexcasting/_templates/index.css.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@
</div>
{% endblock ingredient %}

{% block cost %}
<div class="flay-recipe-cost texture item-texture multi-textures cycle-textures">
{% for item in recipe.cost_items %}
<div class="texture item-texture {{ 'multi-texture-active' if loop.first }}">
{{ texture_macros.render_item(item|hexdoc_item, count=item.count, is_first=true) }}
</div>
{% endfor %}
</div>
{% endblock cost %}

{% block result %}
<div class="flay-recipe-result">
{{ texture_macros.render_item(recipe.result.name) }}
Expand Down
41 changes: 39 additions & 2 deletions doc/src/hexdoc_hexcasting/book/recipes.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"):
Expand All @@ -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
6 changes: 6 additions & 0 deletions doc/src/hexdoc_hexcasting/utils/constants.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit db37c5b

Please sign in to comment.