From 69ef8fd128274c8947e526c965d181d7ed157719 Mon Sep 17 00:00:00 2001 From: navarchus Date: Sat, 24 Aug 2024 20:50:00 -0400 Subject: [PATCH 1/5] Document allay flay cost difference --- .../main/resources/assets/hexcasting/lang/en_us.flatten.json5 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Common/src/main/resources/assets/hexcasting/lang/en_us.flatten.json5 b/Common/src/main/resources/assets/hexcasting/lang/en_us.flatten.json5 index ea81041b3..0c1a29144 100644 --- a/Common/src/main/resources/assets/hexcasting/lang/en_us.flatten.json5 +++ b/Common/src/main/resources/assets/hexcasting/lang/en_us.flatten.json5 @@ -1517,9 +1517,9 @@ quenching_allays: { "1": "THEY ARE BITS OF MEDIA. How did I not see it sooner? They are -- as I am a heap of flesh with a scrap, blessed with a scrap of thought, an Allay is a self-sustaining quarrel of media pinned to a scrap of flesh. It explains everything -- their propensity for media, their response to music, I SEE NOW, HOW did the ones before NOT?", "2": "And given this it is only RIGHT I conquer their peculiar minds -- their peculiar selves -- that is all they are, a mind, a self, a coda. Something about their phase speaks to me. I can... I can compress _media with them, overlay two wends of thought in one space, physical and cognitive, all and once.$(br2)Somehow, the process produces _media of its own. How? Perhaps -- perhaps MY work, the process of doing it --", - "3": "It matters not. I matter not. They matter not, all that matters is what it does. And this is it.$(br2)It must hurt so very much.", + "3": "It matters not. I matter not. They matter not, all that matters is what it does. And this is it.$(br2)It must hurt so very much.$(br2)Ten $(l:items/amethyst)$(item)Amethyst Dust/$ is the price to enact such a perverse ritual.", "4": "The product is fragile. Breaking it shatters it into pieces, with $(thing)Fortune/$ increasing the yield... if I wish the block itself I need a silken touch.$(br2)The produced shards are worth thrice an $(l:items/amethyst)$(item)Charged Amethyst Crystal/$ apiece. The block itself is worth four of the shards.", - "5": "They are mercurial, they seem to twist and wink under my fingers, and by giving them a mentor in another form of _media they may be coerced into its shape, in an equivalent exchange of _media.", + "5": "They are mercurial, they seem to twist and wink under my fingers, and by giving them a mentor in another form of _media they may be coerced into its shape, in an equivalent exchange of _media." }, From 1b538319b7db3472df93eaaf6f1e56194c1d342b Mon Sep 17 00:00:00 2001 From: navarchus Date: Sat, 24 Aug 2024 20:51:23 -0400 Subject: [PATCH 2/5] re-add comma to avoid random change --- .../main/resources/assets/hexcasting/lang/en_us.flatten.json5 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Common/src/main/resources/assets/hexcasting/lang/en_us.flatten.json5 b/Common/src/main/resources/assets/hexcasting/lang/en_us.flatten.json5 index 0c1a29144..9551e07fb 100644 --- a/Common/src/main/resources/assets/hexcasting/lang/en_us.flatten.json5 +++ b/Common/src/main/resources/assets/hexcasting/lang/en_us.flatten.json5 @@ -1519,7 +1519,7 @@ "2": "And given this it is only RIGHT I conquer their peculiar minds -- their peculiar selves -- that is all they are, a mind, a self, a coda. Something about their phase speaks to me. I can... I can compress _media with them, overlay two wends of thought in one space, physical and cognitive, all and once.$(br2)Somehow, the process produces _media of its own. How? Perhaps -- perhaps MY work, the process of doing it --", "3": "It matters not. I matter not. They matter not, all that matters is what it does. And this is it.$(br2)It must hurt so very much.$(br2)Ten $(l:items/amethyst)$(item)Amethyst Dust/$ is the price to enact such a perverse ritual.", "4": "The product is fragile. Breaking it shatters it into pieces, with $(thing)Fortune/$ increasing the yield... if I wish the block itself I need a silken touch.$(br2)The produced shards are worth thrice an $(l:items/amethyst)$(item)Charged Amethyst Crystal/$ apiece. The block itself is worth four of the shards.", - "5": "They are mercurial, they seem to twist and wink under my fingers, and by giving them a mentor in another form of _media they may be coerced into its shape, in an equivalent exchange of _media." + "5": "They are mercurial, they seem to twist and wink under my fingers, and by giving them a mentor in another form of _media they may be coerced into its shape, in an equivalent exchange of _media.", }, From 79bd9fdf29989b5c113751585ff2f73ad28c4ca1 Mon Sep 17 00:00:00 2001 From: navarchus Date: Sat, 24 Aug 2024 23:04:46 -0400 Subject: [PATCH 3/5] display flay costs in dust/shards/crystals in book --- .../patchouli/BrainsweepProcessor.java | 31 ++++++++++++++++++- .../en_us/templates/brainsweep.json | 6 ++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Common/src/main/java/at/petrak/hexcasting/interop/patchouli/BrainsweepProcessor.java b/Common/src/main/java/at/petrak/hexcasting/interop/patchouli/BrainsweepProcessor.java index ada9cc416..7e6b60d4c 100644 --- a/Common/src/main/java/at/petrak/hexcasting/interop/patchouli/BrainsweepProcessor.java +++ b/Common/src/main/java/at/petrak/hexcasting/interop/patchouli/BrainsweepProcessor.java @@ -1,19 +1,26 @@ package at.petrak.hexcasting.interop.patchouli; +import at.petrak.hexcasting.api.misc.MediaConstants; +import at.petrak.hexcasting.common.lib.HexItems; import at.petrak.hexcasting.common.recipe.BrainsweepRecipe; import at.petrak.hexcasting.common.recipe.HexRecipeStuffRegistry; import net.minecraft.client.Minecraft; -import net.minecraft.core.Registry; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; import org.jetbrains.annotations.Nullable; import vazkii.patchouli.api.IComponentProcessor; import vazkii.patchouli.api.IVariable; import vazkii.patchouli.api.IVariableProvider; +import javax.print.attribute.standard.Media; +import java.util.ArrayList; +import java.util.List; + public class BrainsweepProcessor implements IComponentProcessor { private BrainsweepRecipe recipe; @Nullable @@ -77,6 +84,28 @@ public IVariable process(Level level, String key) { .map(IVariable::from) .toList()); } + case "mediaCost" -> { + ArrayList validItemStacks = new java.util.ArrayList<>(); + // if divisible by even number of charged crystals shards or dust render appropriately + if (this.recipe.mediaCost() % MediaConstants.CRYSTAL_UNIT == 0){ + validItemStacks.add(new ItemStack(HexItems.CHARGED_AMETHYST, (int) (this.recipe.mediaCost() / MediaConstants.CRYSTAL_UNIT))); + } + if (this.recipe.mediaCost() % MediaConstants.SHARD_UNIT == 0) { + validItemStacks.add(new ItemStack(Items.AMETHYST_SHARD, (int) (this.recipe.mediaCost() / MediaConstants.SHARD_UNIT))); + } + if (this.recipe.mediaCost() % MediaConstants.DUST_UNIT == 0){ + validItemStacks.add(new ItemStack(HexItems.AMETHYST_DUST, (int) (this.recipe.mediaCost() / MediaConstants.DUST_UNIT))); + } + + if (!validItemStacks.isEmpty()) { + return IVariable.wrapList(validItemStacks.stream() + .map(IVariable::from) + .toList()); + } + + // fallback: display in terms of dust + return IVariable.from(new ItemStack(HexItems.AMETHYST_DUST, (int) (this.recipe.mediaCost() / MediaConstants.DUST_UNIT))); + } default -> { return null; } diff --git a/Common/src/main/resources/assets/hexcasting/patchouli_books/thehexbook/en_us/templates/brainsweep.json b/Common/src/main/resources/assets/hexcasting/patchouli_books/thehexbook/en_us/templates/brainsweep.json index 6be171dfd..c7081d0b5 100644 --- a/Common/src/main/resources/assets/hexcasting/patchouli_books/thehexbook/en_us/templates/brainsweep.json +++ b/Common/src/main/resources/assets/hexcasting/patchouli_books/thehexbook/en_us/templates/brainsweep.json @@ -37,6 +37,12 @@ "y": 35, "item": "#input" }, + { + "type": "patchouli:item", + "x": 12, + "y": 55, + "item": "#mediaCost" + }, { "type": "patchouli:item", "x": 87, From 7abeb32eb2ffbd3b7cb7de1a981e8f66f2fa6980 Mon Sep 17 00:00:00 2001 From: navarchus Date: Sat, 24 Aug 2024 23:37:23 -0400 Subject: [PATCH 4/5] make it functional --- .../patchouli/BrainsweepProcessor.java | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/Common/src/main/java/at/petrak/hexcasting/interop/patchouli/BrainsweepProcessor.java b/Common/src/main/java/at/petrak/hexcasting/interop/patchouli/BrainsweepProcessor.java index 7e6b60d4c..576e82bb4 100644 --- a/Common/src/main/java/at/petrak/hexcasting/interop/patchouli/BrainsweepProcessor.java +++ b/Common/src/main/java/at/petrak/hexcasting/interop/patchouli/BrainsweepProcessor.java @@ -16,9 +16,7 @@ import vazkii.patchouli.api.IComponentProcessor; import vazkii.patchouli.api.IVariable; import vazkii.patchouli.api.IVariableProvider; - -import javax.print.attribute.standard.Media; -import java.util.ArrayList; +import java.util.Arrays; import java.util.List; public class BrainsweepProcessor implements IComponentProcessor { @@ -85,24 +83,27 @@ public IVariable process(Level level, String key) { .toList()); } case "mediaCost" -> { - ArrayList validItemStacks = new java.util.ArrayList<>(); - // if divisible by even number of charged crystals shards or dust render appropriately - if (this.recipe.mediaCost() % MediaConstants.CRYSTAL_UNIT == 0){ - validItemStacks.add(new ItemStack(HexItems.CHARGED_AMETHYST, (int) (this.recipe.mediaCost() / MediaConstants.CRYSTAL_UNIT))); - } - if (this.recipe.mediaCost() % MediaConstants.SHARD_UNIT == 0) { - validItemStacks.add(new ItemStack(Items.AMETHYST_SHARD, (int) (this.recipe.mediaCost() / MediaConstants.SHARD_UNIT))); - } - if (this.recipe.mediaCost() % MediaConstants.DUST_UNIT == 0){ - validItemStacks.add(new ItemStack(HexItems.AMETHYST_DUST, (int) (this.recipe.mediaCost() / MediaConstants.DUST_UNIT))); + record ItemCost(Item item, int cost) { + public boolean dividesEvenly (int dividend) { + return dividend % cost == 0; + } } + ItemCost[] costs = { + new ItemCost(HexItems.AMETHYST_DUST, (int)MediaConstants.DUST_UNIT), + new ItemCost(Items.AMETHYST_SHARD, (int)MediaConstants.SHARD_UNIT), + new ItemCost(HexItems.CHARGED_AMETHYST, (int)MediaConstants.CRYSTAL_UNIT), + }; - if (!validItemStacks.isEmpty()) { - return IVariable.wrapList(validItemStacks.stream() + // get evenly divisible ItemStacks + List validItemStacks = Arrays.stream(costs) + .filter(itemCost -> itemCost.dividesEvenly((int)this.recipe.mediaCost())) + .map(validItemCost -> new ItemStack(validItemCost.item, (int) this.recipe.mediaCost() / validItemCost.cost)) .map(IVariable::from) - .toList()); - } + .toList(); + if (!validItemStacks.isEmpty()) { + return IVariable.wrapList(validItemStacks); + } // fallback: display in terms of dust return IVariable.from(new ItemStack(HexItems.AMETHYST_DUST, (int) (this.recipe.mediaCost() / MediaConstants.DUST_UNIT))); } From db37c5b2cc56a2a67e6b8761b9f2e4d34db0a7d0 Mon Sep 17 00:00:00 2001 From: object-Object Date: Mon, 25 Nov 2024 12:22:50 -0500 Subject: [PATCH 5/5] 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 d609633a5..eeb060280 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 69bad23a8..8b6e9439a 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 d99c2cdfc..1389f7e92 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 000000000..89b296105 --- /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