@terrafirmagreg-team/recipe 1.2.40 → 1.2.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/package.json +2 -2
  2. package/src/components/cards/calc-add-item.tsx +55 -0
  3. package/src/components/cards/card/index.tsx +2 -0
  4. package/src/components/cards/card/text.tsx +20 -4
  5. package/src/components/views/browser/card-grid.tsx +11 -23
  6. package/src/components/views/browser/frame.tsx +7 -10
  7. package/src/components/views/browser/item-view/index.tsx +8 -10
  8. package/src/components/views/browser/settings.tsx +6 -0
  9. package/src/components/views/browser/toolbar.tsx +7 -7
  10. package/src/components/views/browser/type-view.tsx +10 -10
  11. package/src/components/views/calc/calculator/index.tsx +4 -0
  12. package/src/components/views/calc/flow/index.tsx +42 -1
  13. package/src/components/views/calc/flow/picker-dialogs.tsx +15 -8
  14. package/src/components/views/calc/flow/toolbar.tsx +2 -0
  15. package/src/components/views/calc/flow/view-menu.tsx +13 -0
  16. package/src/components/views/calc/member-picker.tsx +7 -2
  17. package/src/components/views/calc/node-card/full.tsx +34 -5
  18. package/src/components/views/calc/node-card/menu.tsx +32 -0
  19. package/src/components/views/calc/recipe-picker/body.tsx +9 -9
  20. package/src/hooks/calc/flow/use-layout.ts +1 -1
  21. package/src/hooks/calc/flow/use-pickers.ts +14 -10
  22. package/src/hooks/calc/use-actions.ts +54 -31
  23. package/src/hooks/calc/use-recipe-ids.ts +33 -0
  24. package/src/hooks/use-card-grid.ts +14 -0
  25. package/src/lib/alloy/parse.ts +6 -3
  26. package/src/lib/browser/card-dim.test.ts +39 -0
  27. package/src/lib/browser/card-dim.ts +38 -0
  28. package/src/lib/browser/lookup.ts +3 -2
  29. package/src/lib/browser/row-match.test.ts +34 -0
  30. package/src/lib/browser/row-match.ts +8 -0
  31. package/src/lib/calc/flow.ts +3 -1
  32. package/src/lib/calc/member.test.ts +178 -0
  33. package/src/lib/calc/member.ts +90 -0
  34. package/src/lib/calc/scheme.test.ts +213 -0
  35. package/src/lib/calc/scheme.ts +8 -3
  36. package/src/lib/calc/tree/index.ts +5 -1
  37. package/src/lib/calc/tree/recipe.test.ts +88 -0
  38. package/src/lib/calc/tree/recipe.ts +19 -3
  39. package/src/lib/calc/wire.test.ts +70 -0
  40. package/src/lib/calc/wire.ts +6 -2
  41. package/src/lib/cards/model.test.ts +61 -1
  42. package/src/lib/cards/model.ts +9 -2
  43. package/src/types/calc-flow-props.ts +2 -0
  44. package/styles/calc.css +4 -0
@@ -10,6 +10,7 @@ import {
10
10
  resolveRecipeRows,
11
11
  } from '@terrafirmagreg-team/recipe/lib/client-index';
12
12
  import { stackIdFromRef } from '@terrafirmagreg-team/dump/lib/dump/contract/ref';
13
+ import { refsMatchBase } from '@terrafirmagreg-team/recipe/lib/browser/row-match';
13
14
  import { loadFluidIoIndex } from '@terrafirmagreg-team/recipe/lib/browser/fluid-outputs';
14
15
 
15
16
  export { registryId, tagPseudoId } from '@terrafirmagreg-team/dump/lib/dump/paths';
@@ -59,7 +60,7 @@ export async function recipesForOutput(
59
60
  const keepTagRows = opts?.includeTagRows ?? false;
60
61
  return (await resolveRecipeRows(dataset, index, ids, opts)).filter(
61
62
  (row) =>
62
- row.out.includes(base) ||
63
+ refsMatchBase(row.out, base) ||
63
64
  (keepTagRows &&
64
65
  (row.cat ?? index.types[row.type]) === 'emi:tag'),
65
66
  );
@@ -130,7 +131,7 @@ export async function usesForInput(
130
131
  }),
131
132
  ]);
132
133
  return uniqueRows([
133
- ...refRows.filter((row) => row.in.includes(base)),
134
+ ...refRows.filter((row) => refsMatchBase(row.in, base)),
134
135
  ...tagRows.filter((row) =>
135
136
  row.in.some((id) => acceptedTags.has(id)),
136
137
  ),
@@ -0,0 +1,34 @@
1
+ import assert from 'node:assert/strict';
2
+ import { test } from 'node:test';
3
+ import { refsMatchBase } from './row-match';
4
+
5
+ const NBT_OUT = 'gtceu:duranium_hammer{"Damage":0,"GT.Tool":{}}';
6
+ const NBT_IN = 'gtceu:duranium_hammer{"Damage":10239,"GT.Tool":{}}';
7
+
8
+ test('NBT-carrying refs match the queried base id', () => {
9
+ assert.equal(
10
+ refsMatchBase([NBT_OUT, 'minecraft:amethyst_shard'], 'gtceu:duranium_hammer'),
11
+ true,
12
+ );
13
+ assert.equal(
14
+ refsMatchBase([NBT_IN], 'gtceu:duranium_hammer'),
15
+ true,
16
+ );
17
+ });
18
+
19
+ test('base, plain and unrelated ids behave as expected', () => {
20
+ assert.equal(
21
+ refsMatchBase(['gtceu:duranium_hammer'], 'gtceu:duranium_hammer'),
22
+ true,
23
+ );
24
+ assert.equal(
25
+ refsMatchBase([NBT_OUT], 'gtceu:copper_hammer'),
26
+ false,
27
+ );
28
+ assert.equal(
29
+ refsMatchBase(['#forge:tools/hammers'], 'gtceu:duranium_hammer'),
30
+ false,
31
+ );
32
+ assert.equal(refsMatchBase([], 'gtceu:duranium_hammer'), false);
33
+ assert.equal(refsMatchBase(undefined, 'gtceu:duranium_hammer'), false);
34
+ });
@@ -0,0 +1,8 @@
1
+ import { stackIdBase } from '@terrafirmagreg-team/dump/lib/dump/contract/ref';
2
+
3
+ export function refsMatchBase(
4
+ refs: readonly string[] | undefined,
5
+ base: string,
6
+ ): boolean {
7
+ return !!refs?.some((ref) => stackIdBase(ref) === base);
8
+ }
@@ -35,8 +35,9 @@ export type CalcFlowData = {
35
35
  recipeBody: (recipeId: string) => Recipe | undefined;
36
36
  onSelectRecipe: (cardId: string, recipeId: string | null) => void;
37
37
  onSelectTagMember: (tagId: string, memberId: string) => void;
38
+ tagSelections: Record<string, string>;
38
39
  onRequestPicker: (node: CalcNode) => void;
39
- onRequestMemberPicker: (node: CalcNode) => void;
40
+ onRequestMemberPicker: (node: CalcNode, input?: number) => void;
40
41
  onRequestSupply: (node: CalcNode, input: number) => void;
41
42
  onRequestDemand: (node: CalcNode, output: number) => void;
42
43
  onSupplyInput: (
@@ -228,6 +229,7 @@ function sameFlowData(a: CalcFlowData, b: CalcFlowData): boolean {
228
229
  a.recipeBody === b.recipeBody &&
229
230
  a.onSelectRecipe === b.onSelectRecipe &&
230
231
  a.onSelectTagMember === b.onSelectTagMember &&
232
+ a.tagSelections === b.tagSelections &&
231
233
  a.onRequestPicker === b.onRequestPicker &&
232
234
  a.onRequestMemberPicker === b.onRequestMemberPicker &&
233
235
  a.onRequestSupply === b.onRequestSupply &&
@@ -0,0 +1,178 @@
1
+ import assert from 'node:assert/strict';
2
+ import test from 'node:test';
3
+ import type { Recipe, RecipeSlotWidget } from '@terrafirmagreg-team/recipe/lib/data/dto';
4
+ import type { CalcNode } from '@terrafirmagreg-team/recipe/types/calc';
5
+ import { pinnedRecipe } from './member';
6
+
7
+ function tagSlot(over: Partial<RecipeSlotWidget> = {}): RecipeSlotWidget {
8
+ return {
9
+ type: 'slot',
10
+ x: 0,
11
+ y: 0,
12
+ w: 16,
13
+ h: 16,
14
+ role: 'input',
15
+ kind: 'tag',
16
+ id: 'forge:rods/amethyst',
17
+ alternatives: ['minecraft:amethyst_shard', 'gtceu:amethyst_rod'],
18
+ ...over,
19
+ };
20
+ }
21
+
22
+ function recipe(widgets: Recipe['widgets']): Recipe {
23
+ return {
24
+ id: 'gtceu:lathe/lathe_amethyst_to_rod',
25
+ type: 'gtceu:lathe',
26
+ category: 'gtceu:lathe',
27
+ modId: 'gtceu',
28
+ slots: {},
29
+ properties: {},
30
+ inputs: [],
31
+ outputs: [],
32
+ widgets,
33
+ bodyUrl: '',
34
+ extra: {},
35
+ } as Recipe;
36
+ }
37
+
38
+ function node(inputs: CalcNode['inputs']): CalcNode {
39
+ return {
40
+ id: 'n1',
41
+ materialId: 'gtceu:amethyst_rod',
42
+ kind: 'item',
43
+ crafts: 1,
44
+ produced: 2,
45
+ allocated: 0,
46
+ remaining: 2,
47
+ outputs: [],
48
+ recipe: null,
49
+ inputs,
50
+ availableRecipes: [],
51
+ cycle: false,
52
+ products: false,
53
+ };
54
+ }
55
+
56
+ test('pinnedRecipe pins a tag slot to the selected member', () => {
57
+ const src = recipe([tagSlot()]);
58
+ const target = node([
59
+ {
60
+ id: 'gtceu:amethyst_rod',
61
+ kind: 'item',
62
+ amount: 1,
63
+ catalyst: false,
64
+ tagId: 'forge:rods/amethyst',
65
+ members: ['minecraft:amethyst_shard', 'gtceu:amethyst_rod'],
66
+ wired: false,
67
+ covered: 0,
68
+ },
69
+ ]);
70
+ const out = pinnedRecipe(src, target, {
71
+ 'forge:rods/amethyst': 'gtceu:amethyst_rod',
72
+ });
73
+ const slot = out.widgets[0] as RecipeSlotWidget;
74
+ assert.deepEqual(slot.alternatives, ['gtceu:amethyst_rod']);
75
+ });
76
+
77
+ test('pinnedRecipe matches hash-prefixed selections and widget ids', () => {
78
+ const src = recipe([tagSlot({ id: '#forge:rods/amethyst' })]);
79
+ const target = node([
80
+ {
81
+ id: 'gtceu:amethyst_rod',
82
+ kind: 'item',
83
+ amount: 1,
84
+ catalyst: false,
85
+ tagId: '#forge:rods/amethyst',
86
+ wired: false,
87
+ covered: 0,
88
+ },
89
+ ]);
90
+ const out = pinnedRecipe(src, target, {
91
+ 'forge:rods/amethyst': 'gtceu:amethyst_rod',
92
+ });
93
+ const slot = out.widgets[0] as RecipeSlotWidget;
94
+ assert.deepEqual(slot.alternatives, ['gtceu:amethyst_rod']);
95
+ });
96
+
97
+ test('pinnedRecipe keeps cycling when no selection exists', () => {
98
+ const src = recipe([tagSlot()]);
99
+ const target = node([
100
+ {
101
+ id: 'minecraft:amethyst_shard',
102
+ kind: 'item',
103
+ amount: 1,
104
+ catalyst: false,
105
+ tagId: 'forge:rods/amethyst',
106
+ members: ['minecraft:amethyst_shard', 'gtceu:amethyst_rod'],
107
+ wired: false,
108
+ covered: 0,
109
+ },
110
+ ]);
111
+ const out = pinnedRecipe(src, target, {});
112
+ assert.equal(out, src);
113
+ });
114
+
115
+ test('pinnedRecipe matches members by base id against NBT alternatives', () => {
116
+ const src = recipe([
117
+ tagSlot({
118
+ id: '#forge:tools/hammers',
119
+ alternatives: [
120
+ 'gtceu:stone_hammer{Damage:0,GT.Tool:{}}',
121
+ 'gtceu:copper_hammer{Damage:0,GT.Tool:{}}',
122
+ ],
123
+ }),
124
+ ]);
125
+ const target = node([
126
+ {
127
+ id: 'gtceu:copper_hammer',
128
+ kind: 'item',
129
+ amount: 1,
130
+ catalyst: false,
131
+ tagId: '#forge:tools/hammers',
132
+ wired: false,
133
+ covered: 0,
134
+ },
135
+ ]);
136
+ const out = pinnedRecipe(src, target, {
137
+ 'forge:tools/hammers': 'gtceu:copper_hammer',
138
+ });
139
+ const slot = out.widgets[0] as RecipeSlotWidget;
140
+ assert.deepEqual(slot.alternatives, [
141
+ 'gtceu:copper_hammer{Damage:0,GT.Tool:{}}',
142
+ ]);
143
+ });
144
+
145
+ test('pinnedRecipe pins the picked member outside alternatives and skips non-tag widgets', () => {
146
+ const src = recipe([
147
+ tagSlot(),
148
+ {
149
+ type: 'slot',
150
+ x: 0,
151
+ y: 0,
152
+ w: 16,
153
+ h: 16,
154
+ role: 'input',
155
+ kind: 'item',
156
+ id: 'minecraft:stick',
157
+ },
158
+ ]);
159
+ const target = node([
160
+ {
161
+ id: 'minecraft:planks',
162
+ kind: 'item',
163
+ amount: 1,
164
+ catalyst: false,
165
+ tagId: 'forge:rods/amethyst',
166
+ wired: false,
167
+ covered: 0,
168
+ },
169
+ ]);
170
+ const out = pinnedRecipe(src, target, {
171
+ 'forge:rods/amethyst': 'minecraft:planks',
172
+ });
173
+ const tag = out.widgets[0] as RecipeSlotWidget;
174
+ const item = out.widgets[1] as RecipeSlotWidget;
175
+ assert.deepEqual(tag.alternatives, ['minecraft:planks']);
176
+ assert.equal(item.id, 'minecraft:stick');
177
+ assert.equal(item.alternatives, undefined);
178
+ });
@@ -0,0 +1,90 @@
1
+ import { stackIdBase } from '@terrafirmagreg-team/dump/lib/dump/contract/ref';
2
+ import type {
3
+ CalcKind,
4
+ CalcNode,
5
+ } from '@terrafirmagreg-team/recipe/types/calc';
6
+ import type {
7
+ Recipe,
8
+ RecipeWidget,
9
+ } from '@terrafirmagreg-team/recipe/lib/data/dto';
10
+
11
+ export type MemberRequest = { node: CalcNode; input?: number };
12
+
13
+ export type MemberTarget = {
14
+ tagId: string;
15
+ members: string[];
16
+ selected: string | undefined;
17
+ kind: CalcKind;
18
+ };
19
+
20
+ export function memberTarget(
21
+ req: MemberRequest,
22
+ selections: Record<string, string> = {},
23
+ ): MemberTarget | undefined {
24
+ const { node, input } = req;
25
+ if (input == null) {
26
+ if (!node.tagId || !node.members?.length) return undefined;
27
+ const picked = selectionFor(node.tagId, selections);
28
+ return {
29
+ tagId: node.tagId,
30
+ members: node.members,
31
+ selected:
32
+ (picked
33
+ ? node.members.find(
34
+ (m) => stackIdBase(m) === stackIdBase(picked),
35
+ )
36
+ : undefined) ?? node.materialId,
37
+ kind: node.kind,
38
+ };
39
+ }
40
+ const slot = node.inputs[input];
41
+ if (!slot?.tagId || !slot.members?.length) return undefined;
42
+ return {
43
+ tagId: slot.tagId,
44
+ members: slot.members,
45
+ selected: slot.id,
46
+ kind: slot.kind,
47
+ };
48
+ }
49
+
50
+ function selectionFor(
51
+ tagId: string,
52
+ selections: Record<string, string>,
53
+ ): string | undefined {
54
+ const key = tagId.replace(/^#+/, '');
55
+ return selections[key] ?? selections[tagId] ?? selections[`#${key}`];
56
+ }
57
+
58
+ export function pinnedRecipe(
59
+ recipe: Recipe,
60
+ node: CalcNode,
61
+ selections: Record<string, string>,
62
+ ): Recipe {
63
+ const picked = new Map<string, string>();
64
+ for (const input of node.inputs) {
65
+ if (!input.tagId) continue;
66
+ const member = selectionFor(input.tagId, selections);
67
+ if (member) picked.set(input.tagId, member);
68
+ }
69
+ if (!picked.size) return recipe;
70
+ let changed = false;
71
+ const source: RecipeWidget[] = recipe.widgets;
72
+ const widgets = source.map((widget) => {
73
+ if (widget.type !== 'slot' || widget.kind !== 'tag') return widget;
74
+ const member =
75
+ picked.get(widget.id) ??
76
+ picked.get(`#${widget.id.replace(/^#+/, '')}`);
77
+ if (!member) return widget;
78
+ const memberBase = stackIdBase(member);
79
+ const pinned =
80
+ widget.alternatives?.find(
81
+ (alt) => stackIdBase(alt) === memberBase,
82
+ ) ?? member;
83
+ if (widget.alternatives?.length === 1 && widget.alternatives[0] === pinned) {
84
+ return widget;
85
+ }
86
+ changed = true;
87
+ return { ...widget, alternatives: [pinned] };
88
+ });
89
+ return changed ? { ...recipe, widgets } : recipe;
90
+ }
@@ -0,0 +1,213 @@
1
+ import assert from 'node:assert/strict';
2
+ import { test } from 'node:test';
3
+ import { buildScheme, type SchemeContext } from './scheme';
4
+ import { memberTarget } from './member';
5
+ import type { CalcCard, CalcRecipe } from '@terrafirmagreg-team/recipe/types/calc';
6
+
7
+ const RODS = [
8
+ 'gtceu:amethyst_rod',
9
+ 'gtceu:opal_rod',
10
+ 'gtceu:ruby_rod',
11
+ ];
12
+ const TAG = 'tfg:precision_fabricator_holder_rods';
13
+
14
+ const RECIPE: CalcRecipe = {
15
+ recipeId: 'gtceu:high_temperature_precision_fabricator/x',
16
+ category: 'gtceu:high_temperature_precision_fabricator',
17
+ inputs: [
18
+ { id: 'tfg:ingot', kind: 'item', amount: 1, catalyst: false },
19
+ {
20
+ id: TAG,
21
+ kind: 'item',
22
+ amount: 1,
23
+ catalyst: false,
24
+ tagId: TAG,
25
+ },
26
+ ],
27
+ outputs: [{ id: 'tfg:tipped_ingot', kind: 'item', amount: 1 }],
28
+ };
29
+
30
+ const CARD: CalcCard = {
31
+ id: 'c1',
32
+ materialId: 'tfg:tipped_ingot',
33
+ kind: 'item',
34
+ recipeId: RECIPE.recipeId,
35
+ crafts: 1,
36
+ };
37
+
38
+ function ctx(tagSelections: Record<string, string>): SchemeContext {
39
+ return {
40
+ recipeMap: new Map([[RECIPE.recipeId, RECIPE]]),
41
+ getRecipesForItem: () => [],
42
+ tagMembers: (tagId) =>
43
+ tagId === TAG || tagId === `#${TAG}`
44
+ ? { members: RODS, kind: 'item' }
45
+ : undefined,
46
+ tagSelections,
47
+ recipesResolved: () => true,
48
+ deadIds: new Set(),
49
+ };
50
+ }
51
+
52
+ function tagInput(tagSelections: Record<string, string>) {
53
+ const { nodes } = buildScheme({ cards: [CARD], wires: [], ctx: ctx(tagSelections) });
54
+ const node = nodes[0];
55
+ return node?.inputs[1];
56
+ }
57
+
58
+ test('tag input resolves to first member and keeps members for picking', () => {
59
+ const input = tagInput({});
60
+ assert.equal(input?.id, 'gtceu:amethyst_rod');
61
+ assert.equal(input?.tagId, TAG);
62
+ assert.deepEqual(input?.members, RODS);
63
+ });
64
+
65
+ test('tag input honors member selection for its tagId', () => {
66
+ const input = tagInput({ [TAG]: 'gtceu:ruby_rod' });
67
+ assert.equal(input?.id, 'gtceu:ruby_rod');
68
+ });
69
+
70
+ test('tag input honors selection written under the #-prefixed card tagId', () => {
71
+ const input = tagInput({ [`#${TAG}`]: 'gtceu:opal_rod' });
72
+ assert.equal(input?.id, 'gtceu:opal_rod');
73
+ });
74
+
75
+ test('stale selection not in members falls back to first member', () => {
76
+ const input = tagInput({ [TAG]: 'gtceu:removed_rod' });
77
+ assert.equal(input?.id, 'gtceu:amethyst_rod');
78
+ });
79
+
80
+ const NBT_RODS = [
81
+ 'gtceu:amethyst_rod{Damage:0}',
82
+ 'gtceu:opal_rod{Damage:0}',
83
+ 'gtceu:ruby_rod{Damage:0}',
84
+ ];
85
+
86
+ function nbtCtx(tagSelections: Record<string, string>): SchemeContext {
87
+ return {
88
+ ...ctx(tagSelections),
89
+ tagMembers: (tagId) =>
90
+ tagId === TAG || tagId === `#${TAG}`
91
+ ? { members: NBT_RODS, kind: 'item' }
92
+ : undefined,
93
+ };
94
+ }
95
+
96
+ function nbtTagInput(tagSelections: Record<string, string>) {
97
+ const { nodes } = buildScheme({
98
+ cards: [CARD],
99
+ wires: [],
100
+ ctx: nbtCtx(tagSelections),
101
+ });
102
+ return nodes[0]?.inputs[1];
103
+ }
104
+
105
+ test('tag input resolves a base-id selection against NBT members', () => {
106
+ const input = nbtTagInput({ [TAG]: 'gtceu:ruby_rod' });
107
+ assert.equal(input?.id, 'gtceu:ruby_rod');
108
+ });
109
+
110
+ test('tag input normalizes an NBT selection to its base id', () => {
111
+ const input = nbtTagInput({ [TAG]: 'gtceu:opal_rod{Damage:0}' });
112
+ assert.equal(input?.id, 'gtceu:opal_rod');
113
+ });
114
+
115
+ test('memberTarget marks the picked member on a tag card', () => {
116
+ const { nodes } = buildScheme({
117
+ cards: [{ ...CARD, id: 't1', materialId: `#${TAG}`, recipeId: null }],
118
+ wires: [],
119
+ ctx: ctx({}),
120
+ });
121
+ const target = memberTarget(
122
+ { node: nodes[0]! },
123
+ { [`#${TAG}`]: 'gtceu:ruby_rod' },
124
+ );
125
+ assert.equal(target?.selected, 'gtceu:ruby_rod');
126
+ });
127
+
128
+ test('memberTarget resolves node-level tag cards', () => {
129
+ const { nodes } = buildScheme({
130
+ cards: [{ ...CARD, id: 't1', materialId: `#${TAG}`, recipeId: null }],
131
+ wires: [],
132
+ ctx: ctx({}),
133
+ });
134
+ const target = memberTarget({ node: nodes[0]! });
135
+ assert.equal(target?.tagId, `#${TAG}`);
136
+ assert.deepEqual(target?.members, RODS);
137
+ assert.equal(target?.selected, `#${TAG}`);
138
+ assert.equal(target?.kind, 'item');
139
+ });
140
+
141
+ test('memberTarget resolves a tag input on a recipe node', () => {
142
+ const { nodes } = buildScheme({ cards: [CARD], wires: [], ctx: ctx({}) });
143
+ const target = memberTarget({ node: nodes[0]!, input: 1 });
144
+ assert.equal(target?.tagId, TAG);
145
+ assert.deepEqual(target?.members, RODS);
146
+ assert.equal(target?.selected, 'gtceu:amethyst_rod');
147
+ assert.equal(target?.kind, 'item');
148
+ });
149
+
150
+ test('memberTarget is empty for plain inputs and missing slots', () => {
151
+ const { nodes } = buildScheme({ cards: [CARD], wires: [], ctx: ctx({}) });
152
+ assert.equal(memberTarget({ node: nodes[0]!, input: 0 }), undefined);
153
+ assert.equal(memberTarget({ node: nodes[0]!, input: 9 }), undefined);
154
+ });
155
+
156
+ const FLUID_RECIPE: CalcRecipe = {
157
+ recipeId: 'gtceu:distiller/distill_oil',
158
+ category: 'gtceu:distiller',
159
+ inputs: [{ id: 'gtceu:oil', kind: 'fluid', amount: 100, catalyst: false }],
160
+ outputs: [{ id: 'gtceu:sulfuric_gas', kind: 'fluid', amount: 50 }],
161
+ };
162
+
163
+ const CONSUME_RECIPE: CalcRecipe = {
164
+ recipeId: 'gtceu:mixer/mix_gas',
165
+ category: 'gtceu:mixer',
166
+ inputs: [
167
+ { id: 'gtceu:sulfuric_gas', kind: 'fluid', amount: 50, catalyst: false },
168
+ ],
169
+ outputs: [{ id: 'gtceu:mixed_gas', kind: 'fluid', amount: 60 }],
170
+ };
171
+
172
+ function fluidCtx(recipes: CalcRecipe[]): SchemeContext {
173
+ return {
174
+ recipeMap: new Map(recipes.map((r) => [r.recipeId, r])),
175
+ getRecipesForItem: () => [],
176
+ tagMembers: () => undefined,
177
+ tagSelections: {},
178
+ recipesResolved: () => true,
179
+ deadIds: new Set(),
180
+ };
181
+ }
182
+
183
+ test('fluid-only recipe produces its fluid output and feeds a consumer', () => {
184
+ const { nodes, flows } = buildScheme({
185
+ cards: [
186
+ {
187
+ id: 'src',
188
+ materialId: 'gtceu:sulfuric_gas',
189
+ kind: 'fluid',
190
+ recipeId: FLUID_RECIPE.recipeId,
191
+ crafts: 2,
192
+ },
193
+ {
194
+ id: 'dst',
195
+ materialId: 'gtceu:mixed_gas',
196
+ kind: 'fluid',
197
+ recipeId: CONSUME_RECIPE.recipeId,
198
+ crafts: 1,
199
+ },
200
+ ],
201
+ wires: [{ from: 'src', to: 'dst', input: 0 }],
202
+ ctx: fluidCtx([FLUID_RECIPE, CONSUME_RECIPE]),
203
+ });
204
+ const [src, dst] = nodes;
205
+ assert.equal(src?.produced, 100);
206
+ assert.equal(src?.outputs[0]?.id, 'gtceu:sulfuric_gas');
207
+ assert.equal(src?.outputs[0]?.kind, 'fluid');
208
+ assert.equal(src?.inputs[0]?.id, 'gtceu:oil');
209
+ assert.equal(src?.inputs[0]?.amount, 200);
210
+ assert.equal(dst?.inputs[0]?.covered, 50);
211
+ assert.deepEqual(flows, [50]);
212
+ assert.equal(src?.remaining, 50);
213
+ });
@@ -10,6 +10,7 @@ import type {
10
10
  CalcWire,
11
11
  TagResolution,
12
12
  } from '@terrafirmagreg-team/recipe/types/calc';
13
+ import { stackIdBase } from '@terrafirmagreg-team/dump/lib/dump/contract/ref';
13
14
  import { mergeAmounts } from './tree/materials';
14
15
  import { resolveWireEnds } from './wire';
15
16
 
@@ -37,13 +38,17 @@ function inputMember(
37
38
  ctx: SchemeContext,
38
39
  ): { id?: string; kind: CalcKind; members?: string[] } {
39
40
  if (!input.tagId) return { id: input.id, kind: input.kind };
40
- const picked = ctx.tagSelections[input.tagId];
41
+ const key = input.tagId.replace(/^#+/, '');
42
+ const picked = ctx.tagSelections[key] ?? ctx.tagSelections[`#${key}`];
41
43
  const resolution = ctx.tagMembers(input.tagId);
42
44
  const members = resolution?.members ?? [];
45
+ const pickedBase = picked ? stackIdBase(picked) : undefined;
43
46
  const memberId =
44
- picked && members.includes(picked) ? picked : members[0];
47
+ (pickedBase
48
+ ? members.find((m) => stackIdBase(m) === pickedBase)
49
+ : undefined) ?? members[0];
45
50
  return {
46
- id: memberId,
51
+ id: memberId ? stackIdBase(memberId) : undefined,
47
52
  kind: resolution?.kind ?? input.kind,
48
53
  members: members.length ? members : undefined,
49
54
  };
@@ -1,4 +1,8 @@
1
1
  export { mergeAmounts } from './materials';
2
- export { recipeDivisor, toCalcRecipe } from './recipe';
2
+ export {
3
+ recipeDivisor,
4
+ resolveRecipeAmount,
5
+ toCalcRecipe,
6
+ } from './recipe';
3
7
  export { decodeCalcState, encodeCalcState } from './share';
4
8
 
@@ -0,0 +1,88 @@
1
+ import assert from 'node:assert/strict';
2
+ import { test } from 'node:test';
3
+ import { resolveRecipeAmount } from './recipe';
4
+ import type { Recipe } from '@terrafirmagreg-team/recipe/lib/data/dto';
5
+
6
+ const FLUID_BODY = {
7
+ id: 'gtceu:distillery/distill_oil',
8
+ type: 'gtceu:distillery',
9
+ category: 'gtceu:distillery',
10
+ modId: 'gtceu',
11
+ slots: {},
12
+ properties: {},
13
+ inputs: [
14
+ { kind: 'fluid', id: 'gtceu:oil', count: 100 },
15
+ ],
16
+ outputs: [
17
+ { kind: 'fluid', id: 'gtceu:sulfuric_gas', count: 1000 },
18
+ { kind: 'item', id: 'gtceu:sulfur_dust', count: 1 },
19
+ ],
20
+ widgets: [],
21
+ bodyUrl: '',
22
+ extra: {},
23
+ } as Recipe;
24
+
25
+ test('fluid output amount comes from the loaded body, not the hint', async () => {
26
+ const amount = await resolveRecipeAmount(
27
+ 'gtceu:distillery/distill_oil',
28
+ 'gtceu:sulfuric_gas',
29
+ 'fluid',
30
+ async () => FLUID_BODY,
31
+ 1,
32
+ );
33
+ assert.equal(amount, 1000);
34
+ });
35
+
36
+ test('item output in a mixed recipe resolves by kind', async () => {
37
+ const amount = await resolveRecipeAmount(
38
+ 'gtceu:distillery/distill_oil',
39
+ 'gtceu:sulfur_dust',
40
+ 'item',
41
+ async () => FLUID_BODY,
42
+ 1,
43
+ );
44
+ assert.equal(amount, 1);
45
+ });
46
+
47
+ test('missing body falls back to the hint', async () => {
48
+ const amount = await resolveRecipeAmount(
49
+ 'gtceu:gone',
50
+ 'gtceu:sulfuric_gas',
51
+ 'fluid',
52
+ async () => undefined,
53
+ 1,
54
+ );
55
+ assert.equal(amount, 1);
56
+ });
57
+
58
+ test('body without the material falls back to the hint', async () => {
59
+ const amount = await resolveRecipeAmount(
60
+ 'gtceu:distillery/distill_oil',
61
+ 'minecraft:diamond',
62
+ 'item',
63
+ async () => FLUID_BODY,
64
+ 1,
65
+ );
66
+ assert.equal(amount, 1);
67
+ });
68
+
69
+ test('NBT-carrying output matches the base material id', async () => {
70
+ const body = {
71
+ ...FLUID_BODY,
72
+ outputs: [
73
+ {
74
+ kind: 'item',
75
+ id: 'gtceu:duranium_hammer{"Damage":0,"GT.Tool":{}}',
76
+ count: 1,
77
+ },
78
+ ],
79
+ } as Recipe;
80
+ const amount = await resolveRecipeAmount(
81
+ 'gtceu:shaped/hammer_duranium',
82
+ 'gtceu:duranium_hammer',
83
+ 'item',
84
+ async () => body,
85
+ 1,
86
+ );
87
+ assert.equal(amount, 1);
88
+ });