Skip to content

Commit dee7bd4

Browse files
committed
fix: avoid rounding for liquid/gas ingredients
1 parent 1b83cb2 commit dee7bd4

6 files changed

Lines changed: 27 additions & 2 deletions

File tree

src/codex/items/CodexItemDetail.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,12 @@ function RecipeTable({
227227
const baseAmount = relevantPart ? relevantPart.amount : 0;
228228
const effectiveAmount =
229229
type === 'ingredient' && relevantPart
230-
? applyRecipeMultiplier(baseAmount, recipeMultiplier, recipe)
230+
? applyRecipeMultiplier(
231+
baseAmount,
232+
recipeMultiplier,
233+
recipe,
234+
AllFactoryItemsMap[highlightResource]?.form,
235+
)
231236
: baseAmount;
232237
const rate = relevantPart ? (effectiveAmount * 60) / recipe.time : 0;
233238

src/codex/recipes/CodexRecipeDetail.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,13 @@ export function CodexRecipeDetail() {
154154
ing.amount,
155155
recipeMultiplier,
156156
recipe,
157+
item?.form,
157158
);
158159
const effectiveDisplayAmount = applyRecipeMultiplier(
159160
ing.displayAmount,
160161
recipeMultiplier,
161162
recipe,
163+
item?.form,
162164
);
163165
const rate = (effectiveAmount * 60) / recipe.time;
164166
const isModified = effectiveDisplayAmount !== ing.displayAmount;

src/recipes/recipeMultiplier.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
11
const PACKAGER_BUILDING_ID = 'Build_Packager_C';
22

3+
/**
4+
* Applies the Satisfactory 1.2 "Recipe Parts Cost Multiplier" to a
5+
* single ingredient amount. Three rules govern the result:
6+
*
7+
* 1. Packager recipes are exempt: the game never scales packaging or
8+
* unpackaging ingredients regardless of the multiplier.
9+
* 2. Fluids and gases are scaled without rounding (e.g. 3 * 0.25 = 0.75 m3),
10+
* because fractional fluid amounts are valid in-game.
11+
* 3. Solids are rounded to the nearest integer with a floor of 1, because
12+
* handcrafting requires whole items and zero-cost ingredients would break
13+
* recipes (e.g. 1 * 0.25 = 0.25, rounded to 0, floored to 1).
14+
*/
315
export function applyRecipeMultiplier(
416
baseAmount: number,
517
multiplier: number,
618
recipe?: { producedIn: string },
19+
itemForm?: string,
720
): number {
821
if (multiplier === 1) return baseAmount;
922
if (recipe?.producedIn === PACKAGER_BUILDING_ID) return baseAmount;
10-
return Math.max(1, Math.round(baseAmount * multiplier));
23+
const scaled = baseAmount * multiplier;
24+
if (itemForm === 'Liquid' || itemForm === 'Gas') return scaled;
25+
return Math.max(1, Math.round(scaled));
1126
}
1227

1328
export function isPackagerRecipe(recipe: { producedIn: string }): boolean {

src/recipes/ui/RecipeTooltip.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export function RecipeTooltip(props: IRecipeTooltipProps) {
4646
ingredient.displayAmount,
4747
recipeMultiplier,
4848
recipe,
49+
AllFactoryItemsMap[ingredient.resource].form,
4950
) *
5051
60) /
5152
recipe.time

src/solver/algorithm/compute/computeProductionConstraints.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ export function computeProductionConstraints(
192192
ingredient.amount,
193193
ctx.request.recipeMultiplier ?? 1,
194194
recipe,
195+
ingredientItem.form,
195196
);
196197
const ingredientAmount = (multipliedAmount * 60) / recipe.time;
197198
const factor = productAmount / ingredientAmount;

src/solver/layout/nodes/machine-node/RecipeIngredientRow.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export const RecipeIngredientRow = ({
3636
ingredient.displayAmount,
3737
recipeMultiplier,
3838
recipe,
39+
item.form,
3940
)
4041
: ingredient.displayAmount;
4142
const baseRate = (effectiveAmount * 60) / recipe.time;

0 commit comments

Comments
 (0)