Skip to content

Commit

Permalink
farmers delight compat
Browse files Browse the repository at this point in the history
  • Loading branch information
PssbleTrngle committed Oct 6, 2023
1 parent d8d0dec commit 5d74f9c
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 9 deletions.
Binary file added example/FarmersDelight-1.19.2-1.2.3.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions src/loader/recipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import SmeltingParser from '../parser/recipe/vanilla/smelting'
import SmithingParser from '../parser/recipe/vanilla/smithing'
import AssemblyRecipeParser from '../parser/recipe/create/assembly'
import StonecuttingParser from '../parser/recipe/vanilla/stonecutting'
import CuttingRecipeParser from '../parser/recipe/farmersdelight/cutting'
import CookingRecipeParser from '../parser/recipe/farmersdelight/cooking'

export interface RecipeRegistry {
forEach(consumer: (recipe: Recipe, id: Id) => void): void
Expand Down Expand Up @@ -53,6 +55,9 @@ export default class RecipeLoader implements RecipeRegistry {
this.registerParser('create:haunting', new ProcessingRecipeParser())
this.registerParser('create:mechanical_crafting', new ShapedParser())
this.registerParser('create:sequenced_assembly', new AssemblyRecipeParser())

this.registerParser('farmersdelight:cooking', new CookingRecipeParser())
this.registerParser('farmersdelight:cutting', new CuttingRecipeParser())
}

registerParser(recipeType: string, parser: RecipeParser<RecipeDefinition, Recipe>) {
Expand Down
45 changes: 45 additions & 0 deletions src/parser/recipe/farmersdelight/cooking.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import RecipeParser, { Recipe, replace } from '..'
import { Ingredient, Predicate, Result } from '../../../common/ingredient'
import { RecipeDefinition } from '../../../schema/recipe'
import { exists } from '@pssbletrngle/pack-resolver'

export type CookingRecipeDefinition = RecipeDefinition &
Readonly<{
ingredients: Ingredient[]
container?: Ingredient
result: Result
cookingTime?: number
experience?: number
recipe_book_tab?: string
}>

export class CookingRecipe extends Recipe<CookingRecipeDefinition> {
getIngredients(): Ingredient[] {
return [this.definition.container, ...this.definition.ingredients].filter(exists)
}

getResults(): Result[] {
return [this.definition.result]
}

replaceIngredient(from: Predicate<Ingredient>, to: Ingredient): CookingRecipe {
return new CookingRecipe({
...this.definition,
container: this.definition.container && replace(from, to)(this.definition.container),
ingredients: this.definition.ingredients.map(replace(from, to)),
})
}

replaceResult(from: Predicate<Ingredient>, to: Result): CookingRecipe {
return new CookingRecipe({
...this.definition,
result: to,
})
}
}

export default class CookingRecipeParser extends RecipeParser<CookingRecipeDefinition, CookingRecipe> {
create(definition: CookingRecipeDefinition): CookingRecipe {
return new CookingRecipe(definition)
}
}
40 changes: 40 additions & 0 deletions src/parser/recipe/farmersdelight/cutting.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import RecipeParser, { Recipe, replace } from '..'
import { Ingredient, Predicate, Result } from '../../../common/ingredient'
import { RecipeDefinition } from '../../../schema/recipe'

export type CuttingRecipeDefinition = RecipeDefinition &
Readonly<{
ingredients: Ingredient[]
result: Result[]
tool: unknown
}>

export class CuttingRecipe extends Recipe<CuttingRecipeDefinition> {
getIngredients(): Ingredient[] {
return this.definition.ingredients
}

getResults(): Result[] {
return this.definition.result
}

replaceIngredient(from: Predicate<Ingredient>, to: Ingredient): CuttingRecipe {
return new CuttingRecipe({
...this.definition,
ingredients: this.definition.ingredients.map(replace(from, to)),
})
}

replaceResult(from: Predicate<Ingredient>, to: Result): CuttingRecipe {
return new CuttingRecipe({
...this.definition,
result: this.definition.result.map(replace(from, to)),
})
}
}

export default class CuttingRecipeParser extends RecipeParser<CuttingRecipeDefinition, CuttingRecipe> {
create(definition: CuttingRecipeDefinition): CuttingRecipe {
return new CuttingRecipe(definition)
}
}
12 changes: 6 additions & 6 deletions test/mock/TestLogger.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Logger, wrapLogMethods } from '../../src/logger'

export interface TestLogger extends Logger {
hasError(): boolean
hasWarning(): boolean
hasInfo(): boolean
errors(): ReadonlyArray<unknown>
warnings(): ReadonlyArray<unknown>
infoMessages(): ReadonlyArray<unknown>
}

export default function createTestLogger(): TestLogger {
Expand All @@ -17,9 +17,9 @@ export default function createTestLogger(): TestLogger {
info: (...args) => infoMessages.push(args),
}) as TestLogger

logger.hasError = () => !!errors.length
logger.hasWarning = () => !!warnings.length
logger.hasInfo = () => !!infoMessages.length
logger.errors = () => errors
logger.warnings = () => warnings
logger.infoMessages = () => infoMessages

return logger
}
6 changes: 3 additions & 3 deletions test/recipeReplacer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ afterEach(() => {
})

test('has no unknown recipe loaders', () => {
expect(logger.hasWarning()).toBeFalsy()
expect(logger.hasError()).toBeFalsy()
expect(logger.warnings()).toBe([])
expect(logger.errors()).toBe([])
})

test('replaces ingredients', async () => {
Expand All @@ -29,7 +29,7 @@ test('replaces ingredients', async () => {

await loader.emit(acceptor)

expect(acceptor.paths().length).toBe(14)
expect(acceptor.paths().length).toBe(34)

expect(acceptor.jsonAt('data/minecraft/recipe/piston.json')).toMatchSnapshot()
expect(acceptor.jsonAt('data/minecraft/recipe/compass.json')).toMatchSnapshot()
Expand Down

0 comments on commit 5d74f9c

Please sign in to comment.