@adeficior/data-modifier-recipes 2.0.0-rc.20260814115618

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 (99) hide show
  1. package/.turbo/turbo-build.log +1 -0
  2. package/.turbo/turbo-check.log +1 -0
  3. package/.turbo/turbo-lint.log +1 -0
  4. package/@types/modules.d.ts +15 -0
  5. package/@types/registry.d.ts +20 -0
  6. package/CHANGELOG.md +14 -0
  7. package/dist/emitter.d.ts +48 -0
  8. package/dist/emitter.js +116 -0
  9. package/dist/emitter.js.map +1 -0
  10. package/dist/hooks.d.ts +6 -0
  11. package/dist/hooks.js +4 -0
  12. package/dist/hooks.js.map +1 -0
  13. package/dist/index.d.ts +18 -0
  14. package/dist/index.js +14 -0
  15. package/dist/index.js.map +1 -0
  16. package/dist/loader.d.ts +27 -0
  17. package/dist/loader.js +141 -0
  18. package/dist/loader.js.map +1 -0
  19. package/dist/module.d.ts +15 -0
  20. package/dist/module.js +38 -0
  21. package/dist/module.js.map +1 -0
  22. package/dist/rule.d.ts +15 -0
  23. package/dist/rule.js +31 -0
  24. package/dist/rule.js.map +1 -0
  25. package/dist/schema.d.ts +7 -0
  26. package/dist/schema.js +14 -0
  27. package/dist/schema.js.map +1 -0
  28. package/dist/serializer/abstract.d.ts +17 -0
  29. package/dist/serializer/abstract.js +19 -0
  30. package/dist/serializer/abstract.js.map +1 -0
  31. package/dist/serializer/context.d.ts +12 -0
  32. package/dist/serializer/context.js +4 -0
  33. package/dist/serializer/context.js.map +1 -0
  34. package/dist/serializer/forge/conditional.d.ts +25 -0
  35. package/dist/serializer/forge/conditional.js +45 -0
  36. package/dist/serializer/forge/conditional.js.map +1 -0
  37. package/dist/serializer/holder.d.ts +25 -0
  38. package/dist/serializer/holder.js +52 -0
  39. package/dist/serializer/holder.js.map +1 -0
  40. package/dist/serializer/manyToMany.d.ts +21 -0
  41. package/dist/serializer/manyToMany.js +37 -0
  42. package/dist/serializer/manyToMany.js.map +1 -0
  43. package/dist/serializer/manyToOne.d.ts +21 -0
  44. package/dist/serializer/manyToOne.js +37 -0
  45. package/dist/serializer/manyToOne.js.map +1 -0
  46. package/dist/serializer/modifier.d.ts +6 -0
  47. package/dist/serializer/modifier.js +3 -0
  48. package/dist/serializer/modifier.js.map +1 -0
  49. package/dist/serializer/oneToOne.d.ts +21 -0
  50. package/dist/serializer/oneToOne.js +37 -0
  51. package/dist/serializer/oneToOne.js.map +1 -0
  52. package/dist/serializer/vanilla/shaped.d.ts +22 -0
  53. package/dist/serializer/vanilla/shaped.js +37 -0
  54. package/dist/serializer/vanilla/shaped.js.map +1 -0
  55. package/dist/serializer/vanilla/shapeless.d.ts +4 -0
  56. package/dist/serializer/vanilla/shapeless.js +4 -0
  57. package/dist/serializer/vanilla/shapeless.js.map +1 -0
  58. package/dist/serializer/vanilla/smelting.d.ts +22 -0
  59. package/dist/serializer/vanilla/smelting.js +37 -0
  60. package/dist/serializer/vanilla/smelting.js.map +1 -0
  61. package/dist/serializer/vanilla/smithing.d.ts +25 -0
  62. package/dist/serializer/vanilla/smithing.js +46 -0
  63. package/dist/serializer/vanilla/smithing.js.map +1 -0
  64. package/dist/serializer/vanilla/stonecutting.d.ts +22 -0
  65. package/dist/serializer/vanilla/stonecutting.js +38 -0
  66. package/dist/serializer/vanilla/stonecutting.js.map +1 -0
  67. package/eslint.config.js +8 -0
  68. package/package.json +42 -0
  69. package/src/emitter.ts +239 -0
  70. package/src/hooks.ts +10 -0
  71. package/src/index.ts +18 -0
  72. package/src/loader.ts +219 -0
  73. package/src/module.ts +70 -0
  74. package/src/rule.ts +45 -0
  75. package/src/schema.ts +30 -0
  76. package/src/serializer/abstract.ts +41 -0
  77. package/src/serializer/context.ts +17 -0
  78. package/src/serializer/forge/conditional.ts +72 -0
  79. package/src/serializer/holder.ts +63 -0
  80. package/src/serializer/manyToMany.ts +62 -0
  81. package/src/serializer/manyToOne.ts +62 -0
  82. package/src/serializer/modifier.ts +10 -0
  83. package/src/serializer/oneToOne.ts +60 -0
  84. package/src/serializer/vanilla/shaped.ts +65 -0
  85. package/src/serializer/vanilla/shapeless.ts +8 -0
  86. package/src/serializer/vanilla/smelting.ts +62 -0
  87. package/src/serializer/vanilla/smithing.ts +74 -0
  88. package/src/serializer/vanilla/stonecutting.ts +63 -0
  89. package/src/testing/index.ts +1 -0
  90. package/src/testing/setup.ts +85 -0
  91. package/test/1.20.1/__snapshots__/emitter.test.ts.snap +122 -0
  92. package/test/1.20.1/__snapshots__/loader.test.ts.snap +215 -0
  93. package/test/1.20.1/emitter.test.ts +222 -0
  94. package/test/1.20.1/loader.test.ts +17 -0
  95. package/test/1.21.1/loader.test.ts +17 -0
  96. package/test/1.21.1/packFormat.test.ts +52 -0
  97. package/test/resources/1.20.1/default/custom/data/custom/recipes/conditional.json +25 -0
  98. package/tsconfig.build.json +14 -0
  99. package/tsconfig.json +34 -0
@@ -0,0 +1 @@
1
+ $ tsc --project tsconfig.build.json
@@ -0,0 +1 @@
1
+ $ tsc --noEmit
@@ -0,0 +1 @@
1
+ $ eslint {src,test} --fix
@@ -0,0 +1,15 @@
1
+ declare module "@adeficior/data-modifier-core/generated" {
2
+ export type Services<T extends ModuleTypes> = {
3
+ "serializer:results": import("@adeficior/data-modifier-ingredients").ResultSerializer;
4
+ "serializer:ingredients": import("@adeficior/data-modifier-ingredients").IngredientSerializer;
5
+ predicates: import("@adeficior/data-modifier-ingredients").Predicates;
6
+ "loader:tags": import("@adeficior/data-modifier-tags").TagRegistryHolder;
7
+ "emitter:tags": import("@adeficior/data-modifier-tags").TagRules;
8
+ registries: import("@adeficior/data-modifier-core").RegistryLookup;
9
+ logger: import("@adeficior/pack-resolver").Logger;
10
+ };
11
+
12
+ export type Hooks<T extends ModuleTypes> = {
13
+ "setup:after": import("@adeficior/data-modifier-core").AfterSetupEvent<T>;
14
+ };
15
+ }
@@ -0,0 +1,20 @@
1
+ declare module "@adeficior/data-modifier/generated" {
2
+ type StubId = string;
3
+
4
+ export type RegistryId = StubId;
5
+
6
+ export type CreativeModeTabId = StubId;
7
+
8
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
9
+ export type InferIds<T extends RegistryId> = StubId;
10
+
11
+ export type ItemId = StubId;
12
+
13
+ export type BlockId = StubId;
14
+
15
+ export type FluidId = StubId;
16
+
17
+ export type RecipeSerializerId = StubId;
18
+
19
+ export type EntityTypeId = StubId;
20
+ }
package/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # @adeficior/data-modifier-recipes
2
+
3
+ ## 2.0.0-rc.20260814115618
4
+
5
+ ### Major Changes
6
+
7
+ - 17a98c9: refactor into modular system
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [17a98c9]
12
+ - @adeficior/data-modifier-ingredients@2.0.0-rc.20260814115618
13
+ - @adeficior/data-modifier-tags@2.0.0-rc.20260814115618
14
+ - @adeficior/data-modifier-core@2.0.0-rc.20260814115618
@@ -0,0 +1,48 @@
1
+ import { type ClearableEmitter, type IdInput, type LoaderContext, type NormalizedId, type RegistryProvider, type SemVerInput } from "@adeficior/data-modifier-core";
2
+ import { type CommonFilter } from "@adeficior/data-modifier-core/serializer";
3
+ import { type IngredientFilter, type IngredientInput, type IngredientSerializer, type Predicates, type ResultInput, type ResultSerializer } from "@adeficior/data-modifier-ingredients";
4
+ import { type RecipeSerializerId } from "@adeficior/data-modifier/generated";
5
+ import { type Logger } from "@adeficior/pack-resolver";
6
+ import { type RecipeDefinition } from "./schema";
7
+ import { type Recipe } from "./serializer/abstract";
8
+ import { type RecipeSerializer } from "./serializer/context";
9
+ import { RecipeHolder } from "./serializer/holder";
10
+ export type RecipeTest = Readonly<{
11
+ id?: CommonFilter<NormalizedId>;
12
+ type?: CommonFilter<NormalizedId<RecipeSerializerId>>;
13
+ namespace?: string;
14
+ output?: IngredientFilter;
15
+ input?: IngredientFilter;
16
+ optional?: boolean;
17
+ }>;
18
+ export interface RecipeRules {
19
+ replaceResult(test: IngredientFilter, value: ResultInput, additionalTests?: RecipeTest): void;
20
+ replaceIngredient(test: IngredientFilter, value: IngredientInput, additionalTests?: RecipeTest): void;
21
+ add(id: IdInput, value: RecipeDefinition): void;
22
+ add(id: IdInput, value: RecipeHolder): void;
23
+ add(id: IdInput, type: NormalizedId<RecipeSerializerId>, value: Recipe): void;
24
+ remove(test: RecipeTest): void;
25
+ }
26
+ export declare const EMPTY_RECIPE: RecipeDefinition;
27
+ export declare class RecipeEmitter implements RecipeRules, ClearableEmitter {
28
+ private readonly logger;
29
+ private readonly packFormat;
30
+ private readonly registry;
31
+ private readonly resultSerializer;
32
+ private readonly ingredientSerializer;
33
+ private readonly predicates;
34
+ private readonly serializer;
35
+ private readonly custom;
36
+ private readonly ruled;
37
+ constructor(logger: Logger, packFormat: SemVerInput, registry: RegistryProvider<RecipeHolder>, resultSerializer: ResultSerializer, ingredientSerializer: IngredientSerializer, predicates: Predicates, serializer: RecipeSerializer);
38
+ resolver(context: LoaderContext): import("@adeficior/pack-resolver").Resolver<import("@adeficior/pack-resolver").Acceptable, import("@adeficior/pack-resolver").BaseContext>;
39
+ private createIngredientPredicate;
40
+ private createResultPredicate;
41
+ private resolveRecipeTest;
42
+ add(id: IdInput, arg: RecipeDefinition | RecipeHolder | NormalizedId<RecipeSerializerId>, arg2?: Recipe): void;
43
+ private addRule;
44
+ remove(test: RecipeTest): void;
45
+ replaceResult(test: IngredientFilter, input: ResultInput, additionalTest?: RecipeTest): void;
46
+ replaceIngredient(test: IngredientFilter, input: IngredientInput, additionalTest?: RecipeTest): void;
47
+ clear(): void;
48
+ }
@@ -0,0 +1,116 @@
1
+ import { CustomEmitter, encodeId, RuledEmitter, withDisabledConditions, } from "@adeficior/data-modifier-core";
2
+ import { createReplacer, resolveIdTest, } from "@adeficior/data-modifier-core/serializer";
3
+ import {} from "@adeficior/data-modifier-ingredients";
4
+ import {} from "@adeficior/data-modifier/generated";
5
+ import { combineResolvers, notNull, } from "@adeficior/pack-resolver";
6
+ import { RecipeRule } from "./rule";
7
+ import { recipePath } from "./schema";
8
+ import {} from "./serializer/abstract";
9
+ import {} from "./serializer/context";
10
+ import { RecipeHolder } from "./serializer/holder";
11
+ export const EMPTY_RECIPE = withDisabledConditions({
12
+ type: "minecraft:disabled",
13
+ });
14
+ export class RecipeEmitter {
15
+ logger;
16
+ packFormat;
17
+ registry;
18
+ resultSerializer;
19
+ ingredientSerializer;
20
+ predicates;
21
+ serializer;
22
+ custom = new CustomEmitter((it) => recipePath(this.packFormat, it));
23
+ ruled;
24
+ constructor(
25
+ // TODO inject
26
+ logger, packFormat, registry, resultSerializer, ingredientSerializer, predicates, serializer) {
27
+ this.logger = logger;
28
+ this.packFormat = packFormat;
29
+ this.registry = registry;
30
+ this.resultSerializer = resultSerializer;
31
+ this.ingredientSerializer = ingredientSerializer;
32
+ this.predicates = predicates;
33
+ this.serializer = serializer;
34
+ this.ruled = new RuledEmitter(this.registry, (id) => recipePath(packFormat, id), EMPTY_RECIPE, (it) => this.serializer.serialize(it), (id) => this.custom.has(id));
35
+ }
36
+ resolver(context) {
37
+ return combineResolvers([this.ruled.resolver(context), this.custom.resolver(context)], { async: true });
38
+ }
39
+ createIngredientPredicate(filter) {
40
+ if (!filter)
41
+ return () => true;
42
+ return this.predicates.ingredient(filter);
43
+ }
44
+ createResultPredicate(filter) {
45
+ if (!filter)
46
+ return () => true;
47
+ return this.predicates.result(filter);
48
+ }
49
+ resolveRecipeTest(test) {
50
+ const id = [];
51
+ const type = [];
52
+ const ingredient = [];
53
+ const result = [];
54
+ if (test.id)
55
+ id.push(resolveIdTest(test.id));
56
+ if (test.type)
57
+ type.push(resolveIdTest(test.type));
58
+ if (test.namespace)
59
+ id.push((id) => id.namespace === test.namespace);
60
+ if (test.output)
61
+ result.push(this.createResultPredicate(test.output));
62
+ if (test.input)
63
+ ingredient.push(this.createIngredientPredicate(test.input));
64
+ return { id, type, ingredient, result };
65
+ }
66
+ add(id, arg, arg2) {
67
+ if (typeof arg === "string") {
68
+ const type = arg;
69
+ const recipe = arg2;
70
+ this.add(id, new RecipeHolder({ type }, recipe));
71
+ }
72
+ else {
73
+ const value = arg;
74
+ if (this.custom.has(id))
75
+ this.logger.error(`Overwriting custom recipe with ID ${encodeId(id)}`);
76
+ if (value instanceof RecipeHolder)
77
+ this.custom.add(id, this.serializer.serialize(value));
78
+ else
79
+ this.custom.add(id, value);
80
+ }
81
+ }
82
+ addRule(context, modifier, recipeTest = {}, ingredientTests = {}) {
83
+ const recipePredicates = this.resolveRecipeTest(recipeTest ?? {});
84
+ this.ruled.addRule(new RecipeRule(context, recipePredicates.id, recipePredicates.type, [ingredientTests.ingredient, ...recipePredicates.ingredient].filter(notNull), [ingredientTests.result, ...recipePredicates.result].filter(notNull), modifier), recipeTest.optional !== true);
85
+ }
86
+ remove(test) {
87
+ this.addRule({ operation: "remove", test }, () => null, test);
88
+ }
89
+ replaceResult(test, input, additionalTest) {
90
+ const predicate = this.createResultPredicate(test);
91
+ const value = this.resultSerializer.deserialize(input);
92
+ const replace = createReplacer(predicate, value);
93
+ this.addRule({
94
+ operation: "replace result",
95
+ from: test,
96
+ to: value,
97
+ test: additionalTest,
98
+ }, (recipe) => recipe.replaceResult(replace), additionalTest, { result: predicate });
99
+ }
100
+ replaceIngredient(test, input, additionalTest) {
101
+ const predicate = this.createIngredientPredicate(test);
102
+ const value = this.ingredientSerializer.deserialize(input);
103
+ const replace = createReplacer(predicate, value);
104
+ this.addRule({
105
+ operation: "replace ingredient",
106
+ from: test,
107
+ to: value,
108
+ test: additionalTest,
109
+ }, (recipe) => recipe.replaceIngredient(replace), additionalTest, { ingredient: predicate });
110
+ }
111
+ clear() {
112
+ this.custom.clear();
113
+ this.ruled.clear();
114
+ }
115
+ }
116
+ //# sourceMappingURL=emitter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emitter.js","sourceRoot":"","sources":["../src/emitter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,QAAQ,EACR,YAAY,EACZ,sBAAsB,GASvB,MAAM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EACtB,cAA2B;QAE3B,MAAM,SAAS,GAAG,IAAI,CAAC,yBAAyB,CAAC,IAAI,CAAC,CAAC;QAEvD,MAAM,KAAK,GAAG,IAAI,CAAC,oBAAoB,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QAE3D,MAAM,OAAO,GAAG,cAAc,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QAEjD,IAAI,CAAC,OAAO,CACV;YACE,SAAS,EAAE,oBAAoB;YAC/B,IAAI,EAAE,IAAI;YACV,EAAE,EAAE,KAAK;YACT,IAAI,EAAE,cAAc;SACrB,EACD,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAC7C,cAAc,EACd,EAAE,UAAU,EAAE,SAAS,EAAE,CAC1B,CAAC;IACJ,CAAC;IAED,KAAK;QACH,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QACpB,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ import { type RecipeSerializerId } from "@adeficior/data-modifier/generated";
2
+ import { type RecipeDefinition } from "./schema";
3
+ import { type Recipe, type RecipeParser } from "./serializer/abstract";
4
+ export type RegisterRecipeParser = {
5
+ register(recipeType: RecipeSerializerId, parser: RecipeParser<RecipeDefinition, Recipe>): void;
6
+ };
package/dist/hooks.js ADDED
@@ -0,0 +1,4 @@
1
+ import {} from "@adeficior/data-modifier/generated";
2
+ import {} from "./schema";
3
+ import {} from "./serializer/abstract";
4
+ //# sourceMappingURL=hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,MAAM,oCAAoC,CAAC;AAC7E,OAAO,EAAyB,MAAM,UAAU,CAAC;AACjD,OAAO,EAAkC,MAAM,uBAAuB,CAAC"}
@@ -0,0 +1,18 @@
1
+ export { EMPTY_RECIPE, type RecipeRules, type RecipeTest } from "./emitter";
2
+ export type * from "./hooks";
3
+ export type { RecipeLoaderAccessor } from "./loader";
4
+ export { default } from "./module";
5
+ export * from "./schema";
6
+ export * from "./serializer/abstract";
7
+ export type * from "./serializer/context";
8
+ export * from "./serializer/forge/conditional";
9
+ export type * from "./serializer/holder";
10
+ export * from "./serializer/manyToMany";
11
+ export * from "./serializer/manyToOne";
12
+ export type * from "./serializer/modifier";
13
+ export * from "./serializer/oneToOne";
14
+ export * from "./serializer/vanilla/shaped";
15
+ export * from "./serializer/vanilla/shapeless";
16
+ export * from "./serializer/vanilla/smelting";
17
+ export * from "./serializer/vanilla/smithing";
18
+ export * from "./serializer/vanilla/stonecutting";
package/dist/index.js ADDED
@@ -0,0 +1,14 @@
1
+ export { EMPTY_RECIPE } from "./emitter";
2
+ export { default } from "./module";
3
+ export * from "./schema";
4
+ export * from "./serializer/abstract";
5
+ export * from "./serializer/forge/conditional";
6
+ export * from "./serializer/manyToMany";
7
+ export * from "./serializer/manyToOne";
8
+ export * from "./serializer/oneToOne";
9
+ export * from "./serializer/vanilla/shaped";
10
+ export * from "./serializer/vanilla/shapeless";
11
+ export * from "./serializer/vanilla/smelting";
12
+ export * from "./serializer/vanilla/smithing";
13
+ export * from "./serializer/vanilla/stonecutting";
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAqC,MAAM,WAAW,CAAC;AAG5E,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,cAAc,UAAU,CAAC;AACzB,cAAc,uBAAuB,CAAC;AAEtC,cAAc,gCAAgC,CAAC;AAE/C,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AAEvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,mCAAmC,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { JsonLoader, type ConditionContext } from "@adeficior/data-modifier-core";
2
+ import { type IngredientSerializer, type ResultSerializer } from "@adeficior/data-modifier-ingredients";
3
+ import { type RecipeDefinition } from "./schema";
4
+ import { type Recipe, type RecipeParser } from "./serializer/abstract";
5
+ import { type RecipeSerializer } from "./serializer/context";
6
+ import { RecipeHolder } from "./serializer/holder";
7
+ export interface RecipeLoaderAccessor {
8
+ unknownRecipeTypes(): RecipeDefinition[];
9
+ registerParser(recipeType: string, parser: RecipeParser<RecipeDefinition, Recipe>): void;
10
+ ignoreType(recipeType: string): void;
11
+ }
12
+ export declare class RecipeLoader extends JsonLoader<RecipeHolder> implements RecipeLoaderAccessor, RecipeSerializer {
13
+ private readonly resultSerializer;
14
+ private readonly ingredientSerializer;
15
+ private readonly recipeParsers;
16
+ private readonly ignoredRecipeTypePatterns;
17
+ private readonly _unknownRecipeTypes;
18
+ constructor(resultSerializer: ResultSerializer, ingredientSerializer: IngredientSerializer, context?: ConditionContext);
19
+ ignoreType(pattern: string): void;
20
+ unknownRecipeTypes(): RecipeDefinition[];
21
+ private recipeParseContext;
22
+ serialize(recipe: RecipeHolder): RecipeDefinition;
23
+ deserialize(definition: RecipeDefinition): RecipeHolder;
24
+ parse(definition: RecipeDefinition): RecipeHolder | null;
25
+ registerParser(recipeType: string, parser: RecipeParser<RecipeDefinition, Recipe>): void;
26
+ clear(): void;
27
+ }
package/dist/loader.js ADDED
@@ -0,0 +1,141 @@
1
+ import { encodeId, IllegalShapeError, JsonLoader, } from "@adeficior/data-modifier-core";
2
+ import {} from "@adeficior/data-modifier-ingredients";
3
+ import { omit } from "lodash-es";
4
+ import { minimatch } from "minimatch";
5
+ import {} from "./schema";
6
+ import {} from "./serializer/abstract";
7
+ import {} from "./serializer/context";
8
+ import { ForgeConditionalRecipeParser } from "./serializer/forge/conditional";
9
+ import { RecipeHolder } from "./serializer/holder";
10
+ import { ShapedParser } from "./serializer/vanilla/shaped";
11
+ import { ShapelessParser } from "./serializer/vanilla/shapeless";
12
+ import { SmeltingParser } from "./serializer/vanilla/smelting";
13
+ import { SmithingParser } from "./serializer/vanilla/smithing";
14
+ import { StonecuttingParser } from "./serializer/vanilla/stonecutting";
15
+ // Split serializer into seperate class
16
+ export class RecipeLoader extends JsonLoader {
17
+ resultSerializer;
18
+ ingredientSerializer;
19
+ recipeParsers = new Map();
20
+ ignoredRecipeTypePatterns = [];
21
+ _unknownRecipeTypes = new Map();
22
+ constructor(resultSerializer, ingredientSerializer, context) {
23
+ super(context);
24
+ this.resultSerializer = resultSerializer;
25
+ this.ingredientSerializer = ingredientSerializer;
26
+ this.registerParser("minecraft:crafting_shaped", new ShapedParser());
27
+ this.registerParser("minecraft:crafting_shapeless", new ShapelessParser());
28
+ this.registerParser("minecraft:smelting", new SmeltingParser());
29
+ this.registerParser("minecraft:smoking", new SmeltingParser());
30
+ this.registerParser("minecraft:blasting", new SmeltingParser());
31
+ this.registerParser("minecraft:campfire_cooking", new SmeltingParser());
32
+ this.registerParser("minecraft:smithing", new SmithingParser());
33
+ this.registerParser("minecraft:smithing_trim", new SmithingParser());
34
+ this.registerParser("minecraft:smithing_transform", new SmithingParser());
35
+ this.registerParser("minecraft:stonecutting", new StonecuttingParser());
36
+ this.registerParser("theoneprobe:probe_helmet", new ShapedParser());
37
+ this.registerParser("forge:conditional", new ForgeConditionalRecipeParser());
38
+ /*
39
+ TODO move to seperate modules
40
+
41
+ this.registerParser(
42
+ "sullysmod:grindstone_polishing",
43
+ new GrindstonePolishingParser(),
44
+ );
45
+
46
+ this.registerParser("ad_astra:hammering", new HammeringRecipeParser());
47
+ this.registerParser(
48
+ "ad_astra:cryo_fuel_conversion",
49
+ new FluidConversionRecipeParser(),
50
+ );
51
+ this.registerParser(
52
+ "ad_astra:fuel_conversion",
53
+ new FluidConversionRecipeParser(),
54
+ );
55
+ this.registerParser(
56
+ "ad_astra:oxygen_conversion",
57
+ new FluidConversionRecipeParser(),
58
+ );
59
+ this.registerParser("ad_astra:compressing", new InputOutputRecipeParser());
60
+ this.registerParser(
61
+ "ad_astra:crafting_shaped_space_suit",
62
+ new ShapedParser(),
63
+ );
64
+ this.registerParser(
65
+ "ad_astra:nasa_workbench",
66
+ new NasaWorkbenchRecipeParser(),
67
+ );
68
+ this.registerParser(
69
+ "ad_astra:space_station",
70
+ new SpaceStationRecipeParser(),
71
+ );
72
+
73
+ this.registerParser(
74
+ "patchouli:shapeless_book_recipe",
75
+ new ShapelessParser(),
76
+ );
77
+
78
+ this.registerParser("cofh_core:crafting_shaped_potion", new ShapedParser());
79
+
80
+ this.registerParser(
81
+ "rootsclassic:component",
82
+ new RootComponentRecipeParser(),
83
+ );
84
+ this.registerParser("rootsclassic:ritual", new RootRitualRecipeParser());
85
+
86
+ this.ignoreType("jeed:*");
87
+ this.ignoreType("immersiveengineering:*");
88
+ */
89
+ }
90
+ ignoreType(pattern) {
91
+ this.ignoredRecipeTypePatterns.push(pattern);
92
+ }
93
+ unknownRecipeTypes() {
94
+ return [...this._unknownRecipeTypes.values()];
95
+ }
96
+ recipeParseContext(parser) {
97
+ return {
98
+ recipes: this,
99
+ ingredients: this.ingredientSerializer.selectModule(parser.ingredientModules()),
100
+ results: this.resultSerializer.selectModule(parser.resultModules()),
101
+ };
102
+ }
103
+ serialize(recipe) {
104
+ const parser = this.recipeParsers.get(recipe.serializerType);
105
+ if (!parser)
106
+ throw new Error(`Unable to find parser for type '${recipe.serializerType}'`);
107
+ const context = this.recipeParseContext(parser);
108
+ return recipe.serialize(context);
109
+ }
110
+ deserialize(definition) {
111
+ if (!definition.type)
112
+ throw new IllegalShapeError(`no recipe type set`, definition);
113
+ const parser = this.recipeParsers.get(encodeId(definition.type));
114
+ if (!("type" in definition))
115
+ throw new IllegalShapeError("recipe type missing");
116
+ if (!parser) {
117
+ if (!this._unknownRecipeTypes.has(definition.type)) {
118
+ this._unknownRecipeTypes.set(definition.type, definition);
119
+ }
120
+ throw new IllegalShapeError(`unknown recipe type: '${definition.type}'`, definition);
121
+ }
122
+ const parsed = parser.deserialize(definition, this.recipeParseContext(parser));
123
+ return new RecipeHolder(definition, parsed);
124
+ }
125
+ parse(definition) {
126
+ if (this.ignoredRecipeTypePatterns.some((it) => minimatch(definition.type, it)))
127
+ return null;
128
+ // TODO only print unknown recipe types once in the end
129
+ const importantData = omit(definition, "type", "category", "conditions", "fabric:load_conditions", "neoforge:conditions");
130
+ if (Object.keys(importantData).length === 0)
131
+ return null;
132
+ return this.deserialize(definition);
133
+ }
134
+ registerParser(recipeType, parser) {
135
+ this.recipeParsers.set(recipeType, parser);
136
+ }
137
+ clear() {
138
+ this._unknownRecipeTypes.clear();
139
+ }
140
+ }
141
+ //# sourceMappingURL=loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,iBAAiB,EACjB,UAAU,GAEX,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAIN,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAyB,MAAM,UAAU,CAAC;AACjD,OAAO,EAAkC,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAGN,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAA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C,KAAK,EAAE,CAAC;IACnC,CAAC;CACF"}
@@ -0,0 +1,15 @@
1
+ import { type RecipeRules } from "./emitter";
2
+ import { type RegisterRecipeParser } from "./hooks";
3
+ import { type RecipeLoaderAccessor } from "./loader";
4
+ declare const _default: import("@adeficior/data-modifier-core").ModuleConfig<{
5
+ hooks: {
6
+ "recipes:register-parser": RegisterRecipeParser;
7
+ };
8
+ emitters: {
9
+ recipes: RecipeRules;
10
+ };
11
+ loaders: {
12
+ recipes: RecipeLoaderAccessor;
13
+ };
14
+ }>;
15
+ export default _default;
package/dist/module.js ADDED
@@ -0,0 +1,38 @@
1
+ import { defineModule } from "@adeficior/data-modifier-core";
2
+ import { name } from "../package.json";
3
+ import { RecipeEmitter } from "./emitter";
4
+ import {} from "./hooks";
5
+ import { RecipeLoader } from "./loader";
6
+ import { recipePattern } from "./schema";
7
+ export default defineModule({
8
+ importModule: name,
9
+ dependencies: {
10
+ "@adeficior/data-modifier-ingredients": "required",
11
+ // TODO make optional?
12
+ "@adeficior/data-modifier-tags": "required",
13
+ },
14
+ types: {
15
+ hooks: {
16
+ "recipes:register-parser": { name: "RegisterRecipeParser" },
17
+ },
18
+ emitters: {
19
+ recipes: "RecipeLoaderAccessor",
20
+ },
21
+ loaders: {
22
+ recipes: "RecipeRules",
23
+ },
24
+ },
25
+ setup: (pack) => {
26
+ const loader = pack.loader("recipes", (container) => new RecipeLoader(container.get("serializer:results"), container.get("serializer:ingredients")), recipePattern(pack.options.packFormat));
27
+ pack.emitter("recipes", (container) => new RecipeEmitter(container.get("logger"), pack.options.packFormat, loader(), container.get("serializer:results"), container.get("serializer:ingredients"), container.get("predicates"), loader()));
28
+ pack.hook("setup:after", ({ callHook }) => {
29
+ const serializer = loader();
30
+ callHook("recipes:register-parser", {
31
+ register: (type, parser) => {
32
+ serializer.registerParser(type, parser);
33
+ },
34
+ });
35
+ });
36
+ },
37
+ });
38
+ //# sourceMappingURL=module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":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,EACvC,SAAS,CAAC,GAAG,CAAC,YAAY,CAAC,EAC3B,MAAM,EAAE,CACT,CACJ,CAAC;QAEF,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;YACxC,MAAM,UAAU,GAAG,MAAM,EAAE,CAAC;YAC5B,QAAQ,CAAC,yBAAyB,EAAE;gBAClC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE;oBACzB,UAAU,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;gBAC1C,CAAC;aACF,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAC,CAAC"}
package/dist/rule.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { Rule, type Id, type Modifier } from "@adeficior/data-modifier-core";
2
+ import { type Predicate } from "@adeficior/data-modifier-core/serializer";
3
+ import { type Ingredient, type Result } from "@adeficior/data-modifier-ingredients";
4
+ import { type ContextLike, type Logger } from "@adeficior/pack-resolver";
5
+ import { type RecipeHolder } from "./serializer/holder";
6
+ export declare class RecipeRule extends Rule<RecipeHolder> {
7
+ private readonly context;
8
+ private readonly idsTests;
9
+ private readonly typeTests;
10
+ private readonly ingredientTests;
11
+ private readonly resultTests;
12
+ constructor(context: ContextLike, idsTests: Predicate<Id>[], typeTests: Predicate<Id>[], ingredientTests: Predicate<Ingredient>[], resultTests: Predicate<Result>[], modifier: Modifier<RecipeHolder>);
13
+ matches(id: Id, recipe: RecipeHolder): boolean;
14
+ printWarning(logger: Logger): void;
15
+ }
package/dist/rule.js ADDED
@@ -0,0 +1,31 @@
1
+ import { createId, Rule, } from "@adeficior/data-modifier-core";
2
+ import {} from "@adeficior/data-modifier-core/serializer";
3
+ import {} from "@adeficior/data-modifier-ingredients";
4
+ import {} from "@adeficior/pack-resolver";
5
+ import {} from "./serializer/holder";
6
+ export class RecipeRule extends Rule {
7
+ context;
8
+ idsTests;
9
+ typeTests;
10
+ ingredientTests;
11
+ resultTests;
12
+ constructor(context, idsTests, typeTests, ingredientTests, resultTests, modifier) {
13
+ super(modifier);
14
+ this.context = context;
15
+ this.idsTests = idsTests;
16
+ this.typeTests = typeTests;
17
+ this.ingredientTests = ingredientTests;
18
+ this.resultTests = resultTests;
19
+ }
20
+ matches(id, recipe) {
21
+ const types = recipe.getTypes().map(createId);
22
+ return (this.idsTests.every((test) => test(id)) &&
23
+ this.typeTests.every((test) => types.some((it) => test(it))) &&
24
+ this.ingredientTests.every((test) => recipe.getIngredients().some((it) => test(it))) &&
25
+ this.resultTests.every((test) => recipe.getResults().some((it) => test(it))));
26
+ }
27
+ printWarning(logger) {
28
+ logger.trace("could not find any recipes matching", this.context);
29
+ }
30
+ }
31
+ //# sourceMappingURL=rule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rule.js","sourceRoot":"","sources":["../src/rule.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,IAAI,GAGL,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAkB,MAAM,0CAA0C,CAAC;AAC1E,OAAO,EAGN,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAiC,MAAM,0BAA0B,CAAC;AACzE,OAAO,EAAqB,MAAM,qBAAqB,CAAC;AAExD,MAAM,OAAO,UAAW,SAAQ,IAAkB;IAE7B;IACA;IACA;IACA;IACA;IALnB,YACmB,OAAoB,EACpB,QAAyB,EACzB,SAA0B,EAC1B,eAAwC,EACxC,WAAgC,EACjD,QAAgC;QAEhC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAPC,YAAO,GAAP,OAAO,CAAa;QACpB,aAAQ,GAAR,QAAQ,CAAiB;QACzB,cAAS,GAAT,SAAS,CAAiB;QAC1B,oBAAe,GAAf,eAAe,CAAyB;QACxC,gBAAW,GAAX,WAAW,CAAqB;IAInD,CAAC;IAED,OAAO,CAAC,EAAM,EAAE,MAAoB;QAClC,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAE9C,OAAO,CACL,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACvC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;YAC5D,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAClC,MAAM,CAAC,cAAc,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAC/C;YACD,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAC9B,MAAM,CAAC,UAAU,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAC3C,CACF,CAAC;IACJ,CAAC;IAED,YAAY,CAAC,MAAc;QACzB,MAAM,CAAC,KAAK,CAAC,qCAAqC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IACpE,CAAC;CACF"}
@@ -0,0 +1,7 @@
1
+ import { type IdInput, type SemVerInput, type WithConditions } from "@adeficior/data-modifier-core";
2
+ import { type RecipeSerializerId } from "@adeficior/data-modifier/generated";
3
+ export type RecipeDefinition = WithConditions<Readonly<{
4
+ type: RecipeSerializerId;
5
+ }>>;
6
+ export declare function recipePath(packFormat: SemVerInput, id: IdInput): string;
7
+ export declare function recipePattern(packFormat: SemVerInput): string;
package/dist/schema.js ADDED
@@ -0,0 +1,14 @@
1
+ import { createId, isAtLeastVersion, jsonFilePattern, } from "@adeficior/data-modifier-core";
2
+ import {} from "@adeficior/data-modifier/generated";
3
+ function recipeFolder(packFormat) {
4
+ return isAtLeastVersion(packFormat, "44") ? "recipe" : "recipes";
5
+ }
6
+ export function recipePath(packFormat, id) {
7
+ const folder = recipeFolder(packFormat);
8
+ const { namespace, path } = createId(id);
9
+ return `data/${namespace}/${folder}/${path}.json`;
10
+ }
11
+ export function recipePattern(packFormat) {
12
+ return jsonFilePattern("data", recipeFolder(packFormat));
13
+ }
14
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,gBAAgB,EAChB,eAAe,GAIhB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAA2B,MAAM,oCAAoC,CAAC;AAS7E,SAAS,YAAY,CAAC,UAAuB;IAC3C,OAAO,gBAAgB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;AACnE,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,UAAuB,EAAE,EAAW;IAC7D,MAAM,MAAM,GAAG,YAAY,CAAC,UAAU,CAAC,CAAC;IACxC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;IACzC,OAAO,QAAQ,SAAS,IAAI,MAAM,IAAI,IAAI,OAAO,CAAC;AACpD,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,UAAuB;IACnD,OAAO,eAAe,CAAC,MAAM,EAAE,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC;AAC3D,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { type NormalizedId } from "@adeficior/data-modifier-core";
2
+ import { type Ingredient, type Result, type WithSerializerModules } from "@adeficior/data-modifier-ingredients";
3
+ import { type RecipeDefinition } from "../schema";
4
+ import { type RecipeParseContext } from "./context";
5
+ import { type RecipeModifier } from "./modifier";
6
+ export declare abstract class Recipe {
7
+ abstract getIngredients(): Ingredient[];
8
+ abstract getResults(): Result[];
9
+ abstract modify(modifier: RecipeModifier): Recipe;
10
+ additionalTypes(): NormalizedId[];
11
+ abstract serialize(context: RecipeParseContext): Partial<RecipeDefinition>;
12
+ }
13
+ export declare abstract class RecipeParser<TDefinition extends RecipeDefinition = RecipeDefinition, TRecipe extends Recipe = Recipe> implements WithSerializerModules {
14
+ ingredientModules(): {};
15
+ resultModules(): {};
16
+ abstract deserialize(definition: TDefinition, context: RecipeParseContext): TRecipe;
17
+ }