Skip to content

Commit e2d33d6

Browse files
committed
correctly resolve types of forge:conditional recipes
1 parent 66c47c7 commit e2d33d6

File tree

5 files changed

+58
-9
lines changed

5 files changed

+58
-9
lines changed

src/emit/rule/recipe.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import { exists } from '@pssbletrngle/pack-resolver'
2+
import { Id, createId } from '../../common/id.js'
13
import { IngredientInput, Predicate } from '../../common/ingredient.js'
2-
import { Recipe } from '../../parser/recipe/index.js'
3-
import { createId, Id } from '../../common/id.js'
44
import { Logger } from '../../logger.js'
5+
import { Recipe } from '../../parser/recipe/index.js'
56
import Rule, { Modifier } from './index.js'
6-
import { exists } from '@pssbletrngle/pack-resolver'
77

88
export default class RecipeRule extends Rule<Recipe> {
99
constructor(
@@ -18,10 +18,10 @@ export default class RecipeRule extends Rule<Recipe> {
1818
}
1919

2020
matches(id: Id, recipe: Recipe, logger: Logger): boolean {
21-
const type = createId(recipe.toJSON().type)
21+
const types = recipe.getTypes().map(createId)
2222
return (
2323
this.idsTests.every(test => test(id, logger)) &&
24-
this.typeTests.every(test => test(type, logger)) &&
24+
this.typeTests.every(test => types.some(it => test(it))) &&
2525
this.ingredientTests.every(test => recipe.getIngredients().some(it => test(it, logger))) &&
2626
this.resultTests.every(test => recipe.getResults().some(it => test(it, logger)))
2727
)

src/parser/recipe/forge/conditional.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import RecipeParser, { InlineRecipeParser, Recipe, Replacer } from '../index.js'
21
import { Ingredient, IngredientInput } from '../../../common/ingredient.js'
3-
import { RecipeDefinition } from '../../../schema/data/recipe.js'
42
import { Result, ResultInput } from '../../../common/result.js'
3+
import { RecipeDefinition } from '../../../schema/data/recipe.js'
4+
import RecipeParser, { InlineRecipeParser, Recipe, Replacer } from '../index.js'
55

66
type WithConditions<T> = {
77
conditions: unknown[]
@@ -48,6 +48,10 @@ export class ForgeConditionalRecipe extends Recipe<ForgeConditionalRecipeDefinit
4848
this.recipes.map(it => ({ ...it, recipe: it.recipe.replaceResult(replace) }))
4949
)
5050
}
51+
52+
getTypes() {
53+
return this.definition.recipes.map(it => it.recipe.type)
54+
}
5155
}
5256

5357
export default class ForgeConditionalRecipeParser extends RecipeParser<

src/parser/recipe/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Ingredient, IngredientInput, Predicate } from '../../common/ingredient.js'
2-
import { RecipeDefinition } from '../../schema/data/recipe.js'
32
import { Result, ResultInput } from '../../common/result.js'
3+
import { RecipeDefinition } from '../../schema/data/recipe.js'
44

55
export type Replacer<T> = (value: T) => T
66

@@ -25,6 +25,10 @@ export abstract class Recipe<TDefinition extends RecipeDefinition = RecipeDefini
2525
toJSON(): TDefinition {
2626
return this.definition
2727
}
28+
29+
getTypes() {
30+
return [this.toJSON().type]
31+
}
2832
}
2933

3034
export type InlineRecipeParser = <TDefinition extends RecipeDefinition>(definition: TDefinition) => Recipe<TDefinition>

test/recipe.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { EMPTY_RECIPE, RecipeTest } from '../src/emit/data/recipe.js'
2+
import { NormalizedId } from '../src/index.js'
23
import { ShapedRecipeDefinition } from '../src/parser/recipe/vanilla/shaped.js'
34
import createTestAcceptor from './mock/TestAcceptor.js'
45
import setupLoader from './shared/loaderSetup.js'
5-
import { NormalizedId } from '../src/index.js'
66

77
const { logger, loader } = setupLoader({ include: ['data/**/*.json'] })
88

@@ -77,6 +77,16 @@ describe('recipe ingredient replacement', () => {
7777
'modified create:zinc_ingot_from_raw_ore recipe'
7878
)
7979
})
80+
81+
it('matches recipes wrapped in forge:conditional', async () => {
82+
const acceptor = createTestAcceptor()
83+
84+
loader.recipes.remove({ input: { item: 'biomesoplenty:violet' }, type: 'farmersdelight:cutting' })
85+
86+
await loader.emit(acceptor)
87+
88+
expect(acceptor.jsonAt('data/custom/recipes/conditional.json')).toMatchObject(EMPTY_RECIPE)
89+
})
8090
})
8191

8292
describe('recipe removal', () => {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"type": "forge:conditional",
3+
"recipes": [
4+
{
5+
"conditions": [
6+
{
7+
"type": "forge:mod_loaded",
8+
"modid": "farmersdelight"
9+
}
10+
],
11+
"recipe": {
12+
"type": "farmersdelight:cutting",
13+
"ingredients": [
14+
{
15+
"item": "biomesoplenty:violet"
16+
}
17+
],
18+
"result": [
19+
{
20+
"count": 2,
21+
"item": "minecraft:purple_dye"
22+
}
23+
],
24+
"sound": "farmersdelight:block.cutting_board.knife",
25+
"tool": {
26+
"tag": "forge:tools/knives"
27+
}
28+
}
29+
}
30+
]
31+
}

0 commit comments

Comments
 (0)