Skip to content

Commit 14bfa88

Browse files
authored
Document allay flay cost difference (#742)
2 parents ddb8174 + 2f060c9 commit 14bfa88

File tree

7 files changed

+100
-5
lines changed

7 files changed

+100
-5
lines changed

Common/src/main/java/at/petrak/hexcasting/interop/patchouli/BrainsweepProcessor.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
package at.petrak.hexcasting.interop.patchouli;
22

3+
import at.petrak.hexcasting.api.misc.MediaConstants;
4+
import at.petrak.hexcasting.common.lib.HexItems;
35
import at.petrak.hexcasting.common.recipe.BrainsweepRecipe;
46
import at.petrak.hexcasting.common.recipe.HexRecipeStuffRegistry;
57
import net.minecraft.client.Minecraft;
6-
import net.minecraft.core.Registry;
78
import net.minecraft.core.registries.BuiltInRegistries;
89
import net.minecraft.nbt.CompoundTag;
910
import net.minecraft.resources.ResourceLocation;
11+
import net.minecraft.world.item.Item;
1012
import net.minecraft.world.item.ItemStack;
13+
import net.minecraft.world.item.Items;
1114
import net.minecraft.world.level.Level;
1215
import org.jetbrains.annotations.Nullable;
1316
import vazkii.patchouli.api.IComponentProcessor;
1417
import vazkii.patchouli.api.IVariable;
1518
import vazkii.patchouli.api.IVariableProvider;
19+
import java.util.Arrays;
20+
import java.util.List;
1621

1722
public class BrainsweepProcessor implements IComponentProcessor {
1823
private BrainsweepRecipe recipe;
@@ -77,6 +82,31 @@ public IVariable process(Level level, String key) {
7782
.map(IVariable::from)
7883
.toList());
7984
}
85+
case "mediaCost" -> {
86+
record ItemCost(Item item, int cost) {
87+
public boolean dividesEvenly (int dividend) {
88+
return dividend % cost == 0;
89+
}
90+
}
91+
ItemCost[] costs = {
92+
new ItemCost(HexItems.AMETHYST_DUST, (int)MediaConstants.DUST_UNIT),
93+
new ItemCost(Items.AMETHYST_SHARD, (int)MediaConstants.SHARD_UNIT),
94+
new ItemCost(HexItems.CHARGED_AMETHYST, (int)MediaConstants.CRYSTAL_UNIT),
95+
};
96+
97+
// get evenly divisible ItemStacks
98+
List<IVariable> validItemStacks = Arrays.stream(costs)
99+
.filter(itemCost -> itemCost.dividesEvenly((int)this.recipe.mediaCost()))
100+
.map(validItemCost -> new ItemStack(validItemCost.item, (int) this.recipe.mediaCost() / validItemCost.cost))
101+
.map(IVariable::from)
102+
.toList();
103+
104+
if (!validItemStacks.isEmpty()) {
105+
return IVariable.wrapList(validItemStacks);
106+
}
107+
// fallback: display in terms of dust
108+
return IVariable.from(new ItemStack(HexItems.AMETHYST_DUST, (int) (this.recipe.mediaCost() / MediaConstants.DUST_UNIT)));
109+
}
80110
default -> {
81111
return null;
82112
}

Common/src/main/resources/assets/hexcasting/lang/en_us.flatten.json5

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,8 +1600,8 @@
16001600
quenching_allays: {
16011601
"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?",
16021602
"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 --",
1603-
"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.",
1604-
"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 a $(l:items/amethyst)$(item)Charged Amethyst Crystal/$ apiece. The block itself is worth four of the shards.",
1603+
"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.",
1604+
"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.",
16051605
"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.",
16061606
},
16071607

Common/src/main/resources/assets/hexcasting/patchouli_books/thehexbook/en_us/templates/brainsweep.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@
3737
"y": 35,
3838
"item": "#input"
3939
},
40+
{
41+
"type": "patchouli:item",
42+
"x": 12,
43+
"y": 55,
44+
"item": "#mediaCost"
45+
},
4046
{
4147
"type": "patchouli:item",
4248
"x": 87,

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)