Skip to content

Commit

Permalink
stonecutting & ordered tags
Browse files Browse the repository at this point in the history
  • Loading branch information
PssbleTrngle committed Oct 5, 2023
1 parent 85e3f7d commit 2bcc279
Show file tree
Hide file tree
Showing 4 changed files with 801 additions and 753 deletions.
2 changes: 2 additions & 0 deletions src/loader/recipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { fromJson, toJson } from '../textHelper'
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'

export default class RecipeLoader {
private readonly recipeParsers = new Map<string, RecipeParser<RecipeDefinition, Recipe>>()
Expand All @@ -31,6 +32,7 @@ export default class RecipeLoader {
this.registerParser('minecraft:blasting', new SmeltingParser())
this.registerParser('minecraft:campfire_cooking', new SmeltingParser())
this.registerParser('minecraft:smithing', new SmithingParser())
this.registerParser('minecraft:stonecutting', new StonecuttingParser())

this.registerParser('create:mixing', new ProcessingRecipeParser())
this.registerParser('create:pressing', new ProcessingRecipeParser())
Expand Down
7 changes: 5 additions & 2 deletions src/loader/tags.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Acceptor } from '@pssbletrngle/pack-resolver'
import { uniqBy } from 'lodash-es'
import { orderBy, uniqBy } from 'lodash-es'
import { Logger } from '../logger'
import { TagDefinition, TagEntry } from '../schema/tag'
import { fromJson } from '../textHelper'
Expand All @@ -26,7 +26,10 @@ export class TagRegistry {

const slicedId = this.parseId(id)
const existingEntries = this.entries.get(slicedId) ?? []
const unique = uniqBy([...existingEntries, ...definition.values], it => entryId(it))
const unique = orderBy(
uniqBy([...existingEntries, ...definition.values], it => entryId(it)),
it => entryId(it)
)
this.entries.set(slicedId, unique)
}

Expand Down
43 changes: 43 additions & 0 deletions src/parser/recipe/vanilla/stonecutting.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import RecipeParser, { Recipe } from '..'
import { Ingredient, Predicate, Result } from '../../../common/ingredient'
import { RecipeDefinition } from '../../../schema/recipe'

type StonecuttingRecipeDefinition = RecipeDefinition &
Readonly<{
ingredient: Ingredient
result: string
count?: number
}>

class StonecuttingRecipe extends Recipe<StonecuttingRecipeDefinition> {
getIngredients(): Ingredient[] {
return [this.definition.ingredient]
}

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

replaceIngredient(from: Predicate<Ingredient>, to: Ingredient): Recipe {
return new StonecuttingRecipe({
...this.definition,
ingredient: to,
})
}

replaceResult(from: Predicate<Ingredient>, to: Result): Recipe {
if (!('item' in to)) throw new Error('stonecutting does only support item results')

return new StonecuttingRecipe({
...this.definition,
result: to.item,
count: to.count ?? 1,
})
}
}

export default class StonecuttingParser extends RecipeParser<StonecuttingRecipeDefinition, StonecuttingRecipe> {
create(definition: StonecuttingRecipeDefinition): StonecuttingRecipe {
return new StonecuttingRecipe(definition)
}
}
Loading

0 comments on commit 2bcc279

Please sign in to comment.