@adeficior/data-modifier 1.0.0-rc.12 → 1.0.0-rc.14
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.
- package/dist/common/id.d.ts +1 -0
- package/dist/common/id.js +4 -0
- package/dist/common/id.js.map +1 -1
- package/dist/common/ingredient/filter.d.ts +6 -0
- package/dist/common/ingredient/filter.js +97 -0
- package/dist/common/ingredient/filter.js.map +1 -0
- package/dist/common/ingredient/index.d.ts +74 -0
- package/dist/common/ingredient/index.js +112 -0
- package/dist/common/ingredient/index.js.map +1 -0
- package/dist/common/ingredient/input.d.ts +3 -0
- package/dist/common/ingredient/input.js +1 -0
- package/dist/common/ingredient/input.js.map +1 -0
- package/dist/common/ingredient/serializer.d.ts +17 -0
- package/dist/common/ingredient/serializer.js +112 -0
- package/dist/common/ingredient/serializer.js.map +1 -0
- package/dist/common/predicates.d.ts +2 -1
- package/dist/common/predicates.js.map +1 -1
- package/dist/common/result/filter.d.ts +6 -0
- package/dist/common/result/filter.js +68 -0
- package/dist/common/result/filter.js.map +1 -0
- package/dist/common/result/index.d.ts +41 -0
- package/dist/common/result/index.js +59 -0
- package/dist/common/result/index.js.map +1 -0
- package/dist/common/result/input.d.ts +3 -0
- package/dist/common/result/input.js +1 -0
- package/dist/common/result/input.js.map +1 -0
- package/dist/common/result/serializer.d.ts +15 -0
- package/dist/common/result/serializer.js +81 -0
- package/dist/common/result/serializer.js.map +1 -0
- package/dist/common/serializable.d.ts +6 -0
- package/dist/common/serializable.js +1 -0
- package/dist/common/serializable.js.map +1 -0
- package/dist/common/units.d.ts +1 -0
- package/dist/common/units.js +2 -0
- package/dist/common/units.js.map +1 -0
- package/dist/emit/blacklist.d.ts +4 -6
- package/dist/emit/blacklist.js +19 -21
- package/dist/emit/blacklist.js.map +1 -1
- package/dist/emit/data/loot.d.ts +6 -8
- package/dist/emit/data/loot.js +11 -13
- package/dist/emit/data/loot.js.map +1 -1
- package/dist/emit/data/recipe.d.ts +20 -18
- package/dist/emit/data/recipe.js +40 -29
- package/dist/emit/data/recipe.js.map +1 -1
- package/dist/emit/data/tags.d.ts +1 -1
- package/dist/emit/data/tags.js.map +1 -1
- package/dist/emit/polytoneTabs.d.ts +1 -1
- package/dist/emit/polytoneTabs.js +1 -2
- package/dist/emit/polytoneTabs.js.map +1 -1
- package/dist/emit/rule/lootTable.d.ts +2 -1
- package/dist/emit/rule/lootTable.js +4 -2
- package/dist/emit/rule/lootTable.js.map +1 -1
- package/dist/emit/rule/recipe.d.ts +7 -5
- package/dist/emit/rule/recipe.js.map +1 -1
- package/dist/emit/ruled.d.ts +2 -1
- package/dist/emit/ruled.js +5 -2
- package/dist/emit/ruled.js.map +1 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -2
- package/dist/index.js.map +1 -1
- package/dist/loader/context.d.ts +12 -0
- package/dist/loader/context.js +1 -0
- package/dist/loader/context.js.map +1 -0
- package/dist/loader/pack.d.ts +13 -7
- package/dist/loader/pack.js +43 -25
- package/dist/loader/pack.js.map +1 -1
- package/dist/loader/recipe.d.ts +9 -5
- package/dist/loader/recipe.js +39 -48
- package/dist/loader/recipe.js.map +1 -1
- package/dist/loader/registry/dump.d.ts +0 -2
- package/dist/loader/registry/dump.js +0 -11
- package/dist/loader/registry/dump.js.map +1 -1
- package/dist/loader/registry/index.d.ts +0 -2
- package/dist/loader/registry/wrapped.d.ts +13 -0
- package/dist/loader/registry/wrapped.js +26 -0
- package/dist/loader/registry/wrapped.js.map +1 -0
- package/dist/loader/tags.d.ts +1 -1
- package/dist/loader/tags.js.map +1 -1
- package/dist/parser/adAstra.d.ts +5 -11
- package/dist/parser/adAstra.js +5 -5
- package/dist/parser/adAstra.js.map +1 -1
- package/dist/parser/botania.d.ts +10 -20
- package/dist/parser/botania.js +10 -10
- package/dist/parser/botania.js.map +1 -1
- package/dist/parser/create.d.ts +2 -4
- package/dist/parser/create.js +2 -2
- package/dist/parser/create.js.map +1 -1
- package/dist/parser/index.d.ts +7 -13
- package/dist/parser/index.js +7 -7
- package/dist/parser/index.js.map +1 -1
- package/dist/parser/lootTable.d.ts +7 -6
- package/dist/parser/lootTable.js +25 -23
- package/dist/parser/lootTable.js.map +1 -1
- package/dist/parser/recipe/adAstra/conversion.d.ts +15 -14
- package/dist/parser/recipe/adAstra/conversion.js +27 -20
- package/dist/parser/recipe/adAstra/conversion.js.map +1 -1
- package/dist/parser/recipe/adAstra/hammering.d.ts +3 -17
- package/dist/parser/recipe/adAstra/hammering.js +2 -25
- package/dist/parser/recipe/adAstra/hammering.js.map +1 -1
- package/dist/parser/recipe/adAstra/inputOutput.d.ts +16 -19
- package/dist/parser/recipe/adAstra/inputOutput.js +37 -29
- package/dist/parser/recipe/adAstra/inputOutput.js.map +1 -1
- package/dist/parser/recipe/adAstra/nasaWorkbench.d.ts +3 -19
- package/dist/parser/recipe/adAstra/nasaWorkbench.js +2 -28
- package/dist/parser/recipe/adAstra/nasaWorkbench.js.map +1 -1
- package/dist/parser/recipe/adAstra/spaceStation.d.ts +15 -14
- package/dist/parser/recipe/adAstra/spaceStation.js +33 -14
- package/dist/parser/recipe/adAstra/spaceStation.js.map +1 -1
- package/dist/parser/recipe/botania/apothecary.d.ts +17 -14
- package/dist/parser/recipe/botania/apothecary.js +26 -17
- package/dist/parser/recipe/botania/apothecary.js.map +1 -1
- package/dist/parser/recipe/botania/blocks.d.ts +21 -0
- package/dist/parser/recipe/botania/blocks.js +77 -0
- package/dist/parser/recipe/botania/blocks.js.map +1 -0
- package/dist/parser/recipe/botania/brew.d.ts +13 -12
- package/dist/parser/recipe/botania/brew.js +16 -11
- package/dist/parser/recipe/botania/brew.js.map +1 -1
- package/dist/parser/recipe/botania/elvenTrade.d.ts +8 -13
- package/dist/parser/recipe/botania/elvenTrade.js +11 -22
- package/dist/parser/recipe/botania/elvenTrade.js.map +1 -1
- package/dist/parser/recipe/botania/gogWrapper.d.ts +12 -12
- package/dist/parser/recipe/botania/gogWrapper.js +14 -15
- package/dist/parser/recipe/botania/gogWrapper.js.map +1 -1
- package/dist/parser/recipe/botania/manaInfusion.d.ts +18 -15
- package/dist/parser/recipe/botania/manaInfusion.js +29 -21
- package/dist/parser/recipe/botania/manaInfusion.js.map +1 -1
- package/dist/parser/recipe/botania/nbtWrapper.d.ts +12 -12
- package/dist/parser/recipe/botania/nbtWrapper.js +12 -13
- package/dist/parser/recipe/botania/nbtWrapper.js.map +1 -1
- package/dist/parser/recipe/botania/orechid.d.ts +3 -30
- package/dist/parser/recipe/botania/orechid.js +2 -72
- package/dist/parser/recipe/botania/orechid.js.map +1 -1
- package/dist/parser/recipe/botania/pureDaisy.d.ts +3 -18
- package/dist/parser/recipe/botania/pureDaisy.js +2 -28
- package/dist/parser/recipe/botania/pureDaisy.js.map +1 -1
- package/dist/parser/recipe/botania/runicAltar.d.ts +8 -13
- package/dist/parser/recipe/botania/runicAltar.js +11 -22
- package/dist/parser/recipe/botania/runicAltar.js.map +1 -1
- package/dist/parser/recipe/botania/terraPlate.d.ts +4 -16
- package/dist/parser/recipe/botania/terraPlate.js +2 -25
- package/dist/parser/recipe/botania/terraPlate.js.map +1 -1
- package/dist/parser/recipe/create/assembly.d.ts +18 -17
- package/dist/parser/recipe/create/assembly.js +28 -28
- package/dist/parser/recipe/create/assembly.js.map +1 -1
- package/dist/parser/recipe/create/processing.d.ts +4 -16
- package/dist/parser/recipe/create/processing.js +2 -25
- package/dist/parser/recipe/create/processing.js.map +1 -1
- package/dist/parser/recipe/farmersdelight/cooking.d.ts +16 -12
- package/dist/parser/recipe/farmersdelight/cooking.js +27 -15
- package/dist/parser/recipe/farmersdelight/cooking.js.map +1 -1
- package/dist/parser/recipe/farmersdelight/cutting.d.ts +14 -15
- package/dist/parser/recipe/farmersdelight/cutting.js +32 -29
- package/dist/parser/recipe/farmersdelight/cutting.js.map +1 -1
- package/dist/parser/recipe/forge/conditional.d.ts +11 -11
- package/dist/parser/recipe/forge/conditional.js +17 -21
- package/dist/parser/recipe/forge/conditional.js.map +1 -1
- package/dist/parser/recipe/index.d.ts +36 -13
- package/dist/parser/recipe/index.js +38 -5
- package/dist/parser/recipe/index.js.map +1 -1
- package/dist/parser/recipe/ingredientMap.d.ts +12 -0
- package/dist/parser/recipe/ingredientMap.js +17 -0
- package/dist/parser/recipe/ingredientMap.js.map +1 -0
- package/dist/parser/recipe/manyToMany.d.ts +20 -0
- package/dist/parser/recipe/manyToMany.js +33 -0
- package/dist/parser/recipe/manyToMany.js.map +1 -0
- package/dist/parser/recipe/manyToOne.d.ts +20 -0
- package/dist/parser/recipe/manyToOne.js +33 -0
- package/dist/parser/recipe/manyToOne.js.map +1 -0
- package/dist/parser/recipe/oneToOne.d.ts +20 -0
- package/dist/parser/recipe/oneToOne.js +33 -0
- package/dist/parser/recipe/oneToOne.js.map +1 -0
- package/dist/parser/recipe/roots/component.d.ts +13 -12
- package/dist/parser/recipe/roots/component.js +16 -11
- package/dist/parser/recipe/roots/component.js.map +1 -1
- package/dist/parser/recipe/roots/ritual.d.ts +14 -16
- package/dist/parser/recipe/roots/ritual.js +18 -25
- package/dist/parser/recipe/roots/ritual.js.map +1 -1
- package/dist/parser/recipe/sullys/polishing.d.ts +4 -16
- package/dist/parser/recipe/sullys/polishing.js +2 -25
- package/dist/parser/recipe/sullys/polishing.js.map +1 -1
- package/dist/parser/recipe/thermal/catalyst.d.ts +13 -12
- package/dist/parser/recipe/thermal/catalyst.js +16 -11
- package/dist/parser/recipe/thermal/catalyst.js.map +1 -1
- package/dist/parser/recipe/thermal/fuel.d.ts +13 -12
- package/dist/parser/recipe/thermal/fuel.js +17 -11
- package/dist/parser/recipe/thermal/fuel.js.map +1 -1
- package/dist/parser/recipe/thermal/index.d.ts +16 -14
- package/dist/parser/recipe/thermal/index.js +35 -24
- package/dist/parser/recipe/thermal/index.js.map +1 -1
- package/dist/parser/recipe/thermal/ingredient.d.ts +4 -21
- package/dist/parser/recipe/thermal/ingredient.js +40 -33
- package/dist/parser/recipe/thermal/ingredient.js.map +1 -1
- package/dist/parser/recipe/thermal/treeExtraction.d.ts +17 -17
- package/dist/parser/recipe/thermal/treeExtraction.js +30 -31
- package/dist/parser/recipe/thermal/treeExtraction.js.map +1 -1
- package/dist/parser/recipe/vanilla/shaped.d.ts +17 -13
- package/dist/parser/recipe/vanilla/shaped.js +21 -16
- package/dist/parser/recipe/vanilla/shaped.js.map +1 -1
- package/dist/parser/recipe/vanilla/shapeless.d.ts +3 -17
- package/dist/parser/recipe/vanilla/shapeless.js +2 -25
- package/dist/parser/recipe/vanilla/shapeless.js.map +1 -1
- package/dist/parser/recipe/vanilla/smelting.d.ts +16 -13
- package/dist/parser/recipe/vanilla/smelting.js +21 -15
- package/dist/parser/recipe/vanilla/smelting.js.map +1 -1
- package/dist/parser/recipe/vanilla/smithing.d.ts +18 -14
- package/dist/parser/recipe/vanilla/smithing.js +25 -16
- package/dist/parser/recipe/vanilla/smithing.js.map +1 -1
- package/dist/parser/recipe/vanilla/stonecutting.d.ts +15 -13
- package/dist/parser/recipe/vanilla/stonecutting.js +22 -24
- package/dist/parser/recipe/vanilla/stonecutting.js.map +1 -1
- package/dist/parser/roots.d.ts +2 -4
- package/dist/parser/roots.js +2 -2
- package/dist/parser/roots.js.map +1 -1
- package/dist/parser/thermal.d.ts +4 -10
- package/dist/parser/thermal.js +4 -5
- package/dist/parser/thermal.js.map +1 -1
- package/dist/schema/data/recipe.d.ts +2 -1
- package/package.json +2 -1
- package/dist/common/ingredient.d.ts +0 -49
- package/dist/common/ingredient.js +0 -108
- package/dist/common/ingredient.js.map +0 -1
- package/dist/common/result.d.ts +0 -48
- package/dist/common/result.js +0 -37
- package/dist/common/result.js.map +0 -1
- package/dist/parser/recipe/adAstra/index.d.ts +0 -5
- package/dist/parser/recipe/adAstra/index.js +0 -1
- package/dist/parser/recipe/adAstra/index.js.map +0 -1
- package/dist/parser/recipe/ignored.d.ts +0 -10
- package/dist/parser/recipe/ignored.js +0 -16
- package/dist/parser/recipe/ignored.js.map +0 -1
- package/dist/parser/recipe/quark/exclusion.d.ts +0 -20
- package/dist/parser/recipe/quark/exclusion.js +0 -32
- package/dist/parser/recipe/quark/exclusion.js.map +0 -1
package/dist/common/id.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export type IdInput<T extends string = string> = T | Id;
|
|
|
8
8
|
export type NormalizedId<T extends string = string> = T extends `${string}:${string}` ? T : T extends `#${infer R}` ? `#${string}:${R}` : `${string}:${T}`;
|
|
9
9
|
export type TagInput = IdInput<`#${string}`>;
|
|
10
10
|
export declare const IdSchema: zod.ZodString;
|
|
11
|
+
export declare const TagSchema: zod.ZodType<`#${string}`>;
|
|
11
12
|
export declare const IdOrTagSchema: zod.ZodString;
|
|
12
13
|
export declare function createId(from: IdInput): Id;
|
|
13
14
|
export declare function encodeId<T extends string>(from: IdInput<T>): NormalizedId<T>;
|
package/dist/common/id.js
CHANGED
|
@@ -3,6 +3,10 @@ export const IdSchema = zod
|
|
|
3
3
|
.string()
|
|
4
4
|
.regex(/^([a-z0-9_.-]+:)?[a-z0-9/._-]+$/i)
|
|
5
5
|
.describe("Valid ID");
|
|
6
|
+
export const TagSchema = zod
|
|
7
|
+
.string()
|
|
8
|
+
.regex(/^#([a-z0-9_.-]+:)?[a-z0-9/._-]+$/i)
|
|
9
|
+
.describe("Valid Tag-ID");
|
|
6
10
|
export const IdOrTagSchema = zod
|
|
7
11
|
.string()
|
|
8
12
|
.regex(/^#?([a-z0-9_.-]+:)?[a-z0-9/._-]+$/i)
|
package/dist/common/id.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"id.js","sourceRoot":"","sources":["../../src/common/id.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AAmBtB,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAG;KACxB,MAAM,EAAE;KACR,KAAK,CAAC,kCAAkC,CAAC;KACzC,QAAQ,CAAC,UAAU,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"id.js","sourceRoot":"","s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AAC,GAAG,CAAC;YAAE,OAAO,IAAuB,CAAC;QACvD,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;YACtB,OAAO,cAAc,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAqB,CAAC;QAC9D,OAAO,aAAa,IAAI,EAAqB,CAAC;IAChD,CAAC;IACD,IAAI,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,IAAI,EAAqB,CAAC;IAC5E,OAAO,GAAG,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,IAAI,EAAqB,CAAC;AAC7D,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,EAAW,EAAE,MAAc;IAChD,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;IACvC,OAAO,QAAQ,CAAC,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,CAAC,CAAC;AACpD,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,EAAW,EAAE,MAAc;IAChD,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;IACvC,OAAO,QAAQ,CAAC,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,IAAI,GAAG,MAAM,EAAE,CAAC,CAAC;AACpD,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Ingredient } from ".";
|
|
2
|
+
import type { PackContext } from "../../loader/context";
|
|
3
|
+
import { type CommonTest, type Predicate } from "../predicates";
|
|
4
|
+
import type { IngredientInput } from "./input";
|
|
5
|
+
export type IngredientTest = CommonTest<Ingredient> | IngredientInput | `#${string}`;
|
|
6
|
+
export default function resolveIngredientTest(test: IngredientTest, context: Omit<PackContext, "results">): Predicate<IngredientInput>;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { exists } from "@adeficior/pack-resolver";
|
|
2
|
+
import { BlockIngredient, BlockTagIngredient, FluidIngredient, FluidTagIngredient, Ingredient, ItemIngredient, ItemTagIngredient, ListIngredient, } from ".";
|
|
3
|
+
import { tryCatching } from "../../error";
|
|
4
|
+
import { createId, encodeId } from "../id";
|
|
5
|
+
import { resolveCommonTest, } from "../predicates";
|
|
6
|
+
export default function resolveIngredientTest(test,
|
|
7
|
+
// TODO pass context?
|
|
8
|
+
context) {
|
|
9
|
+
if (typeof test === "string") {
|
|
10
|
+
if (test.startsWith("#")) {
|
|
11
|
+
return resolveIngredientTest(new ItemTagIngredient(test.substring(1)), context);
|
|
12
|
+
}
|
|
13
|
+
return resolveIngredientTest(new ItemIngredient(test), context);
|
|
14
|
+
}
|
|
15
|
+
if (test instanceof RegExp) {
|
|
16
|
+
return resolveIdTest(test, context.tags.registry("item"), extractItemID);
|
|
17
|
+
}
|
|
18
|
+
if (typeof test === "function") {
|
|
19
|
+
return (it, logger) => test(context.ingredients.create(it), logger);
|
|
20
|
+
}
|
|
21
|
+
if (test instanceof Ingredient) {
|
|
22
|
+
test.validate(context.lookup);
|
|
23
|
+
}
|
|
24
|
+
if (test instanceof ItemTagIngredient) {
|
|
25
|
+
return resolveIdTest(`#${encodeId(test.tag)}`, context.tags.registry("item"), extractItemID);
|
|
26
|
+
}
|
|
27
|
+
if (test instanceof ItemIngredient) {
|
|
28
|
+
return resolveIdTest(encodeId(test.id), context.tags.registry("item"), extractItemID);
|
|
29
|
+
}
|
|
30
|
+
if (test instanceof FluidTagIngredient) {
|
|
31
|
+
return resolveIdTest(`#${encodeId(test.tag)}`, context.tags.registry("fluid"), extractFluidID);
|
|
32
|
+
}
|
|
33
|
+
if (test instanceof FluidIngredient) {
|
|
34
|
+
return resolveIdTest(encodeId(test.id), context.tags.registry("fluid"), extractFluidID);
|
|
35
|
+
}
|
|
36
|
+
if (test instanceof BlockTagIngredient) {
|
|
37
|
+
return resolveIdTest(`#${encodeId(test.tag)}`, context.tags.registry("block"), extractBlockID);
|
|
38
|
+
}
|
|
39
|
+
// TODO match method in ingredient itself?
|
|
40
|
+
if (test instanceof BlockIngredient) {
|
|
41
|
+
return resolveIdTest(encodeId(test.id), context.tags.registry("block"), extractBlockID);
|
|
42
|
+
}
|
|
43
|
+
// TODO add support for ListIngredient?
|
|
44
|
+
// TODO warn or throw?
|
|
45
|
+
return () => false;
|
|
46
|
+
}
|
|
47
|
+
// TODO is Predicate<Ingredient> fine?
|
|
48
|
+
function resolveIdTest(test, tags, idSupplier) {
|
|
49
|
+
function resolveIds(it) {
|
|
50
|
+
if (typeof it === "string")
|
|
51
|
+
return [it];
|
|
52
|
+
if (it instanceof ListIngredient) {
|
|
53
|
+
return it.entries.flatMap(resolveIds);
|
|
54
|
+
}
|
|
55
|
+
else if (Array.isArray(it)) {
|
|
56
|
+
return it.flatMap(resolveIds);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
return [idSupplier(it)].filter(exists);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return resolveCommonTest(test, (input, logger) =>
|
|
63
|
+
// TODO which exception has to be caught here?
|
|
64
|
+
tryCatching(logger, () => {
|
|
65
|
+
return resolveIds(input).map(encodeId);
|
|
66
|
+
}) ?? [], tags);
|
|
67
|
+
}
|
|
68
|
+
function extractItemID(ingredient) {
|
|
69
|
+
if (ingredient instanceof ItemTagIngredient) {
|
|
70
|
+
return { ...createId(ingredient.tag), isTag: true };
|
|
71
|
+
}
|
|
72
|
+
if (ingredient instanceof ItemIngredient) {
|
|
73
|
+
return ingredient.id;
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
// TODO functions on the ingredient itself?
|
|
78
|
+
// TODO common super class maybe even?
|
|
79
|
+
function extractBlockID(ingredient) {
|
|
80
|
+
if (ingredient instanceof BlockTagIngredient) {
|
|
81
|
+
return { ...createId(ingredient.tag), isTag: true };
|
|
82
|
+
}
|
|
83
|
+
if (ingredient instanceof BlockIngredient) {
|
|
84
|
+
return ingredient.id;
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
function extractFluidID(ingredient) {
|
|
89
|
+
if (ingredient instanceof FluidTagIngredient) {
|
|
90
|
+
return { ...createId(ingredient.tag), isTag: true };
|
|
91
|
+
}
|
|
92
|
+
if (ingredient instanceof FluidIngredient) {
|
|
93
|
+
return ingredient.id;
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=filter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter.js","sourceRoot":"","sources":["../../../src/common/ingredient/filter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,kBAAkB,EAClB,UAAU,EACV,cAAc,EACd,iBAAiB,EACjB,cAAc,GACf,MAAM,GAAG,CAAC;AACX,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1C,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAmC,MAAM,OAAO,CAAC;AAC5E,OAAO,EACL,iBAAiB,GAGlB,MAAM,eAAe,CAAC;AAQvB,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAC3C,IAAoB;AACpB,qBAAqB;AACrB,OAAqC;IAErC,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YACzB,OAAO,qBAAqB,CAC1B,IAAI,iBAAiB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EACxC,OAAO,CACR,CAAC;QACJ,CAAC;QAED,OAAO,qBAAqB,CAAC,IAAI,cAAc,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC;IAClE,CAAC;IAED,IAAI,IAAI,YAAY,MAAM,EAAE,CAAC;QAC3B,OA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AAQ,CAAC,CAAC;IACzC,CAAC,CAAC,IAAI,EAAE,EACV,IAAI,CACL,CAAC;AACJ,CAAC;AAED,SAAS,aAAa,CAAC,UAAsB;IAC3C,IAAI,UAAU,YAAY,iBAAiB,EAAE,CAAC;QAC5C,OAAO,EAAE,GAAG,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IACtD,CAAC;IAED,IAAI,UAAU,YAAY,cAAc,EAAE,CAAC;QACzC,OAAO,UAAU,CAAC,EAAE,CAAC;IACvB,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,2CAA2C;AAC3C,sCAAsC;AACtC,SAAS,cAAc,CAAC,UAAsB;IAC5C,IAAI,UAAU,YAAY,kBAAkB,EAAE,CAAC;QAC7C,OAAO,EAAE,GAAG,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IACtD,CAAC;IAED,IAAI,UAAU,YAAY,eAAe,EAAE,CAAC;QAC1C,OAAO,UAAU,CAAC,EAAE,CAAC;IACvB,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,cAAc,CAAC,UAAsB;IAC5C,IAAI,UAAU,YAAY,kBAAkB,EAAE,CAAC;QAC7C,OAAO,EAAE,GAAG,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IACtD,CAAC;IAED,IAAI,UAAU,YAAY,eAAe,EAAE,CAAC;QAC1C,OAAO,UAAU,CAAC,EAAE,CAAC;IACvB,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { BlockId, FluidId, ItemId } from "@adeficior/data-modifier/generated";
|
|
2
|
+
import type RegistryLookup from "../../loader/registry";
|
|
3
|
+
import type { SemVerInput } from "../../packFormat";
|
|
4
|
+
import { type IdInput } from "../id";
|
|
5
|
+
import type { Serializable } from "../serializable";
|
|
6
|
+
export declare abstract class Ingredient implements Serializable {
|
|
7
|
+
validate(_?: RegistryLookup): void;
|
|
8
|
+
abstract toJSON(packFormat: SemVerInput): unknown;
|
|
9
|
+
}
|
|
10
|
+
export declare class ItemTagIngredient extends Ingredient {
|
|
11
|
+
readonly tag: IdInput;
|
|
12
|
+
readonly count: number;
|
|
13
|
+
constructor(tag: IdInput, count?: number);
|
|
14
|
+
toJSON(_packFormat: SemVerInput): {
|
|
15
|
+
tag: `${string}:${string}`;
|
|
16
|
+
count: number | undefined;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export declare class FluidTagIngredient extends Ingredient {
|
|
20
|
+
readonly tag: IdInput;
|
|
21
|
+
readonly amount: number;
|
|
22
|
+
constructor(tag: IdInput, amount?: number);
|
|
23
|
+
toJSON(_packFormat: SemVerInput): {
|
|
24
|
+
fluidTag: `${string}:${string}`;
|
|
25
|
+
amount: number;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export declare class BlockTagIngredient extends Ingredient {
|
|
29
|
+
readonly tag: IdInput;
|
|
30
|
+
constructor(tag: IdInput);
|
|
31
|
+
toJSON(_packFormat: SemVerInput): {
|
|
32
|
+
blockTag: `${string}:${string}`;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export declare class ItemIngredient extends Ingredient {
|
|
36
|
+
readonly id: IdInput<ItemId>;
|
|
37
|
+
readonly count: number;
|
|
38
|
+
constructor(id: IdInput<ItemId>, count?: number);
|
|
39
|
+
toJSON(_packFormat: SemVerInput): {
|
|
40
|
+
item: `${string}:${string}`;
|
|
41
|
+
count: number | undefined;
|
|
42
|
+
};
|
|
43
|
+
validate(lookup?: RegistryLookup): void;
|
|
44
|
+
}
|
|
45
|
+
export declare class FluidIngredient extends Ingredient {
|
|
46
|
+
readonly id: IdInput<FluidId>;
|
|
47
|
+
readonly amount: number;
|
|
48
|
+
readonly chance?: number | undefined;
|
|
49
|
+
constructor(id: IdInput<FluidId>, amount?: number, chance?: number | undefined);
|
|
50
|
+
toJSON(_packFormat: SemVerInput): {
|
|
51
|
+
fluid: `${string}:${string}`;
|
|
52
|
+
amount: number;
|
|
53
|
+
};
|
|
54
|
+
validate(lookup?: RegistryLookup): void;
|
|
55
|
+
}
|
|
56
|
+
export declare class BlockIngredient extends Ingredient {
|
|
57
|
+
readonly id: IdInput<BlockId>;
|
|
58
|
+
readonly weight?: number | undefined;
|
|
59
|
+
constructor(id: IdInput<BlockId>, weight?: number | undefined);
|
|
60
|
+
toJSON(_packFormat: SemVerInput): {
|
|
61
|
+
block: `${string}:${string}`;
|
|
62
|
+
weight: number | undefined;
|
|
63
|
+
};
|
|
64
|
+
validate(lookup?: RegistryLookup): void;
|
|
65
|
+
}
|
|
66
|
+
export declare class ListIngredient extends Ingredient {
|
|
67
|
+
readonly entries: Ingredient[];
|
|
68
|
+
constructor(entries: Ingredient[]);
|
|
69
|
+
toJSON(packFormat: SemVerInput): unknown[];
|
|
70
|
+
validate(lookup?: RegistryLookup): void;
|
|
71
|
+
}
|
|
72
|
+
export type ItemLikeIngredient = ItemTagIngredient | ItemIngredient;
|
|
73
|
+
export type FluidLikeIngredient = FluidTagIngredient | FluidIngredient;
|
|
74
|
+
export type BlockLikeIngredient = BlockTagIngredient | BlockIngredient;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { encodeId } from "../id";
|
|
2
|
+
import { BUCKET } from "../units";
|
|
3
|
+
export class Ingredient {
|
|
4
|
+
// TODO make required
|
|
5
|
+
validate(_) { }
|
|
6
|
+
}
|
|
7
|
+
export class ItemTagIngredient extends Ingredient {
|
|
8
|
+
tag;
|
|
9
|
+
count;
|
|
10
|
+
constructor(tag, count = 1) {
|
|
11
|
+
super();
|
|
12
|
+
this.tag = tag;
|
|
13
|
+
this.count = count;
|
|
14
|
+
}
|
|
15
|
+
toJSON(_packFormat) {
|
|
16
|
+
const count = this.count === 1 ? undefined : this.count;
|
|
17
|
+
const tag = encodeId(this.tag);
|
|
18
|
+
return { tag, count };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export class FluidTagIngredient extends Ingredient {
|
|
22
|
+
tag;
|
|
23
|
+
amount;
|
|
24
|
+
constructor(tag, amount = BUCKET) {
|
|
25
|
+
super();
|
|
26
|
+
this.tag = tag;
|
|
27
|
+
this.amount = amount;
|
|
28
|
+
}
|
|
29
|
+
toJSON(_packFormat) {
|
|
30
|
+
const { amount } = this;
|
|
31
|
+
const tag = encodeId(this.tag);
|
|
32
|
+
return { fluidTag: tag, amount };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export class BlockTagIngredient extends Ingredient {
|
|
36
|
+
tag;
|
|
37
|
+
constructor(tag) {
|
|
38
|
+
super();
|
|
39
|
+
this.tag = tag;
|
|
40
|
+
}
|
|
41
|
+
toJSON(_packFormat) {
|
|
42
|
+
const tag = encodeId(this.tag);
|
|
43
|
+
return { blockTag: tag };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export class ItemIngredient extends Ingredient {
|
|
47
|
+
id;
|
|
48
|
+
count;
|
|
49
|
+
constructor(id, count = 1) {
|
|
50
|
+
super();
|
|
51
|
+
this.id = id;
|
|
52
|
+
this.count = count;
|
|
53
|
+
}
|
|
54
|
+
toJSON(_packFormat) {
|
|
55
|
+
const count = this.count === 1 ? undefined : this.count;
|
|
56
|
+
const id = encodeId(this.id);
|
|
57
|
+
return { item: id, count };
|
|
58
|
+
}
|
|
59
|
+
validate(lookup) {
|
|
60
|
+
lookup?.validateEntry("minecraft:item", this.id);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export class FluidIngredient extends Ingredient {
|
|
64
|
+
id;
|
|
65
|
+
amount;
|
|
66
|
+
chance;
|
|
67
|
+
constructor(id, amount = BUCKET, chance) {
|
|
68
|
+
super();
|
|
69
|
+
this.id = id;
|
|
70
|
+
this.amount = amount;
|
|
71
|
+
this.chance = chance;
|
|
72
|
+
}
|
|
73
|
+
toJSON(_packFormat) {
|
|
74
|
+
const { amount } = this;
|
|
75
|
+
const id = encodeId(this.id);
|
|
76
|
+
return { fluid: id, amount };
|
|
77
|
+
}
|
|
78
|
+
validate(lookup) {
|
|
79
|
+
lookup?.validateEntry("minecraft:fluid", this.id);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
export class BlockIngredient extends Ingredient {
|
|
83
|
+
id;
|
|
84
|
+
weight;
|
|
85
|
+
constructor(id, weight) {
|
|
86
|
+
super();
|
|
87
|
+
this.id = id;
|
|
88
|
+
this.weight = weight;
|
|
89
|
+
}
|
|
90
|
+
toJSON(_packFormat) {
|
|
91
|
+
const { weight } = this;
|
|
92
|
+
const id = encodeId(this.id);
|
|
93
|
+
return { block: id, weight };
|
|
94
|
+
}
|
|
95
|
+
validate(lookup) {
|
|
96
|
+
lookup?.validateEntry("minecraft:block", this.id);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
export class ListIngredient extends Ingredient {
|
|
100
|
+
entries;
|
|
101
|
+
constructor(entries) {
|
|
102
|
+
super();
|
|
103
|
+
this.entries = entries;
|
|
104
|
+
}
|
|
105
|
+
toJSON(packFormat) {
|
|
106
|
+
return this.entries.map((it) => it.toJSON(packFormat));
|
|
107
|
+
}
|
|
108
|
+
validate(lookup) {
|
|
109
|
+
this.entries.forEach((it) => it.validate(lookup));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/ingredient/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,QAAQ,EAAgB,MAAM,OAAO,CAAC;AAE/C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,MAAM,OAAgB,UAAU;IAC9B,qBAAqB;IACrB,QAAQ,CAAC,CAAkB,IAAS,CAAC;CAEtC;AAED,MAAM,OAAO,iBAAkB,SAAQ,U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AS;IAGjC,CAAC;IAED,MAAM,CAAC,WAAwB;QAC7B,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QACxB,MAAM,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC7B,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC;IAC/B,CAAC;IAEQ,QAAQ,CAAC,MAAuB;QACvC,MAAM,EAAE,aAAa,CAAC,iBAAiB,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;IACpD,CAAC;CACF;AAED,MAAM,OAAO,cAAe,SAAQ,UAAU;IAChB;IAA5B,YAA4B,OAAqB;QAC/C,KAAK,EAAE,CAAC;QADkB,YAAO,GAAP,OAAO,CAAc;IAEjD,CAAC;IAEQ,MAAM,CAAC,UAAuB;QACrC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;IACzD,CAAC;IAEQ,QAAQ,CAAC,MAAuB;QACvC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;IACpD,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input.js","sourceRoot":"","sources":["../../../src/common/ingredient/input.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Ingredient } from ".";
|
|
2
|
+
import type RegistryLookup from "../../loader/registry";
|
|
3
|
+
import type { SemVerInput } from "../../packFormat";
|
|
4
|
+
import { IngredientMap, type IngredientMapInput } from "../../parser/recipe/ingredientMap";
|
|
5
|
+
export default class IngredientSerializer {
|
|
6
|
+
private readonly packFormat;
|
|
7
|
+
private readonly lookup;
|
|
8
|
+
private readonly deserializer;
|
|
9
|
+
constructor(packFormat: SemVerInput, lookup: RegistryLookup);
|
|
10
|
+
serialize(ingredient: Ingredient): unknown;
|
|
11
|
+
serializeList(ingredients: Ingredient[]): unknown[];
|
|
12
|
+
private deserialize;
|
|
13
|
+
create(input: unknown): Ingredient;
|
|
14
|
+
validated<T extends Ingredient>(ingredient: T): T;
|
|
15
|
+
createList(input: unknown[]): Ingredient[];
|
|
16
|
+
ingredientMap(input: IngredientMapInput): IngredientMap;
|
|
17
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { mapValues } from "lodash-es";
|
|
2
|
+
import z from "zod";
|
|
3
|
+
import { BlockIngredient, BlockTagIngredient, FluidIngredient, FluidTagIngredient, Ingredient, ItemIngredient, ItemTagIngredient, ListIngredient, } from ".";
|
|
4
|
+
import { IllegalShapeError } from "../../error";
|
|
5
|
+
import { IngredientMap, } from "../../parser/recipe/ingredientMap";
|
|
6
|
+
import { IdSchema } from "../id";
|
|
7
|
+
class OldDeserializer {
|
|
8
|
+
schemas = {
|
|
9
|
+
itemTag: z.object({
|
|
10
|
+
tag: IdSchema,
|
|
11
|
+
count: z.number().optional(),
|
|
12
|
+
}),
|
|
13
|
+
fluidTag: z.object({
|
|
14
|
+
fluidTag: IdSchema,
|
|
15
|
+
amount: z.number(),
|
|
16
|
+
}),
|
|
17
|
+
blockTag: z.object({
|
|
18
|
+
blockTag: IdSchema,
|
|
19
|
+
weight: z.number().optional(),
|
|
20
|
+
}),
|
|
21
|
+
itemStack: z.object({
|
|
22
|
+
item: IdSchema,
|
|
23
|
+
count: z.number().int().optional(),
|
|
24
|
+
}),
|
|
25
|
+
fluidStack: z.object({
|
|
26
|
+
fluid: IdSchema,
|
|
27
|
+
amount: z.number(),
|
|
28
|
+
}),
|
|
29
|
+
block: z.object({
|
|
30
|
+
block: IdSchema,
|
|
31
|
+
}),
|
|
32
|
+
};
|
|
33
|
+
deserialize(input) {
|
|
34
|
+
if ("blockTag" in input) {
|
|
35
|
+
const parsed = this.schemas.blockTag.parse(input);
|
|
36
|
+
return new BlockTagIngredient(parsed.blockTag);
|
|
37
|
+
}
|
|
38
|
+
if ("tag" in input) {
|
|
39
|
+
const parsed = this.schemas.itemTag.parse(input);
|
|
40
|
+
return new ItemTagIngredient(parsed.tag, parsed.count);
|
|
41
|
+
}
|
|
42
|
+
if ("fluidTag" in input) {
|
|
43
|
+
const parsed = this.schemas.fluidTag.parse(input);
|
|
44
|
+
return new FluidTagIngredient(parsed.fluidTag, parsed.amount);
|
|
45
|
+
}
|
|
46
|
+
if ("block" in input) {
|
|
47
|
+
const parsed = this.schemas.block.parse(input);
|
|
48
|
+
return new BlockIngredient(parsed.block);
|
|
49
|
+
}
|
|
50
|
+
if ("item" in input) {
|
|
51
|
+
const parsed = this.schemas.itemStack.parse(input);
|
|
52
|
+
return new ItemIngredient(parsed.item, parsed.count);
|
|
53
|
+
}
|
|
54
|
+
if ("fluid" in input) {
|
|
55
|
+
const parsed = this.schemas.fluidStack.parse(input);
|
|
56
|
+
return new FluidIngredient(parsed.fluid, parsed.amount);
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export default class IngredientSerializer {
|
|
62
|
+
packFormat;
|
|
63
|
+
lookup;
|
|
64
|
+
deserializer;
|
|
65
|
+
constructor(packFormat, lookup) {
|
|
66
|
+
this.packFormat = packFormat;
|
|
67
|
+
this.lookup = lookup;
|
|
68
|
+
this.deserializer = new OldDeserializer();
|
|
69
|
+
}
|
|
70
|
+
serialize(ingredient) {
|
|
71
|
+
return ingredient.toJSON(this.packFormat);
|
|
72
|
+
}
|
|
73
|
+
serializeList(ingredients) {
|
|
74
|
+
return ingredients.map((it) => this.serialize(it));
|
|
75
|
+
}
|
|
76
|
+
deserialize(input) {
|
|
77
|
+
if (input instanceof Ingredient)
|
|
78
|
+
return input;
|
|
79
|
+
if (!input)
|
|
80
|
+
throw new IllegalShapeError("ingredient input may not be null");
|
|
81
|
+
if (typeof input === "string") {
|
|
82
|
+
this.lookup.validateEntry("minecraft:item", input);
|
|
83
|
+
return new ItemIngredient(input);
|
|
84
|
+
}
|
|
85
|
+
if (Array.isArray(input)) {
|
|
86
|
+
return new ListIngredient(input.map((it) => this.deserialize(it)));
|
|
87
|
+
}
|
|
88
|
+
if (typeof input === "object") {
|
|
89
|
+
const deserialized = this.deserializer.deserialize(input);
|
|
90
|
+
if (deserialized)
|
|
91
|
+
return deserialized;
|
|
92
|
+
}
|
|
93
|
+
throw new IllegalShapeError(`unknown ingredient shape`, input);
|
|
94
|
+
}
|
|
95
|
+
// TODO rename deserialize
|
|
96
|
+
create(input) {
|
|
97
|
+
const deserialized = this.deserialize(input);
|
|
98
|
+
deserialized.validate(this.lookup);
|
|
99
|
+
return deserialized;
|
|
100
|
+
}
|
|
101
|
+
validated(ingredient) {
|
|
102
|
+
ingredient.validate(this.lookup);
|
|
103
|
+
return ingredient;
|
|
104
|
+
}
|
|
105
|
+
createList(input) {
|
|
106
|
+
return input.map((it) => this.create(it));
|
|
107
|
+
}
|
|
108
|
+
ingredientMap(input) {
|
|
109
|
+
return new IngredientMap(mapValues(input, (it) => this.create(it)));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=serializer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serializer.js","sourceRoot":"","sources":["../../../src/common/ingredient/serializer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,CAAC,MAAM,KAAK,CAAC;AACpB,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,kBAAkB,EAClB,UAAU,EACV,cAAc,EACd,iBAAiB,EACjB,cAAc,GACf,MAAM,GAAG,CAAC;AACX,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGhD,OAAO,EACL,aAAa,GAEd,MAAM,mCAA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,IAAI,CAAC,MAAM,CAAC,CAAC;QACnC,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,SAAS,CAAuB,UAAa;QAC3C,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACjC,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,UAAU,CAAC,KAAgB;QACzB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;IAC5C,CAAC;IAED,aAAa,CAAC,KAAyB;QACrC,OAAO,IAAI,aAAa,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACtE,CAAC;CACF"}
|
|
@@ -2,6 +2,7 @@ import type { InferIds, RegistryId } from "@adeficior/data-modifier/generated";
|
|
|
2
2
|
import type { Logger } from "@adeficior/pack-resolver";
|
|
3
3
|
import type { TagRegistry } from "../loader/tags.js";
|
|
4
4
|
import type { IdInput, NormalizedId } from "./id.js";
|
|
5
|
-
|
|
5
|
+
export type Predicate<T> = (value: T, logger?: Logger) => boolean;
|
|
6
|
+
export type CommonTest<T> = RegExp | Predicate<T> | T;
|
|
6
7
|
export declare function resolveCommonTest<TEntry, TId extends string>(test: CommonTest<TId>, resolve: (value: TEntry, logger?: Logger) => NormalizedId<TId>[], tags?: TagRegistry<RegistryId>): Predicate<TEntry>;
|
|
7
8
|
export declare function resolveIDTest<T extends RegistryId>(test: CommonTest<NormalizedId<InferIds<T>>>, tags?: TagRegistry<T>): Predicate<IdInput<InferIds<T>>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"predicates.js","sourceRoot":"","sources":["../../src/common/predicates.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"predicates.js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AAM,EAAE,EAAE;YAC5B,OAAO,OAAO,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;QAC9D,CAAC,CAAC;IACJ,CAAC;AACH,CAAC;AAED,MAAM,UAAU,aAAa,CAC3B,IAA2C,EAC3C,IAAqB;IAErB,OAAO,iBAAiB,CACtB,IAAI,EACJ,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,EACtB,IAAI,CACL,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Result } from ".";
|
|
2
|
+
import type { PackContext } from "../../loader/context";
|
|
3
|
+
import { type CommonTest, type Predicate } from "../predicates";
|
|
4
|
+
import type { ResultInput } from "./input";
|
|
5
|
+
export type ResultTest = CommonTest<Result> | ResultInput;
|
|
6
|
+
export default function resolveResultTest(test: ResultTest, context: Omit<PackContext, "ingredients">): Predicate<ResultInput>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { exists } from "@adeficior/pack-resolver";
|
|
2
|
+
import { BlockResult, FluidResult, ItemResult } from ".";
|
|
3
|
+
import { tryCatching } from "../../error";
|
|
4
|
+
import { encodeId } from "../id";
|
|
5
|
+
import { resolveCommonTest, } from "../predicates";
|
|
6
|
+
export default function resolveResultTest(test,
|
|
7
|
+
// TODO pass context?
|
|
8
|
+
context) {
|
|
9
|
+
if (typeof test === "string") {
|
|
10
|
+
return resolveResultTest(new ItemResult(test), context);
|
|
11
|
+
}
|
|
12
|
+
if (test instanceof RegExp) {
|
|
13
|
+
return resolveIdTest(test, context.tags.registry("item"), extractItemID);
|
|
14
|
+
}
|
|
15
|
+
if (typeof test === "function") {
|
|
16
|
+
return (it, logger) => test(context.results.create(it), logger);
|
|
17
|
+
}
|
|
18
|
+
if (test instanceof ItemResult) {
|
|
19
|
+
return resolveIdTest(encodeId(test.id), context.tags.registry("item"), extractItemID);
|
|
20
|
+
}
|
|
21
|
+
if (test instanceof FluidResult) {
|
|
22
|
+
return resolveIdTest(encodeId(test.id), context.tags.registry("fluid"), extractFluidID);
|
|
23
|
+
}
|
|
24
|
+
// TODO match method in ingredient itself?
|
|
25
|
+
if (test instanceof BlockResult) {
|
|
26
|
+
return resolveIdTest(encodeId(test.id), context.tags.registry("block"), extractBlockID);
|
|
27
|
+
}
|
|
28
|
+
// TODO warn or throw?
|
|
29
|
+
return () => false;
|
|
30
|
+
}
|
|
31
|
+
function resolveIdTest(test, tags, idSupplier) {
|
|
32
|
+
function resolveIds(it) {
|
|
33
|
+
if (typeof it === "string")
|
|
34
|
+
return [it];
|
|
35
|
+
if (Array.isArray(it)) {
|
|
36
|
+
return it.flatMap(resolveIds);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
return [idSupplier(it)].filter(exists);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return resolveCommonTest(test, (input, logger) =>
|
|
43
|
+
// TODO which exception has to be caught here?
|
|
44
|
+
tryCatching(logger, () => {
|
|
45
|
+
return resolveIds(input).map(encodeId);
|
|
46
|
+
}) ?? [], tags);
|
|
47
|
+
}
|
|
48
|
+
function extractItemID(ingredient) {
|
|
49
|
+
if (ingredient instanceof ItemResult) {
|
|
50
|
+
return ingredient.id;
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
// TODO functions on the ingredient itself?
|
|
55
|
+
// TODO common super class maybe even?
|
|
56
|
+
function extractBlockID(ingredient) {
|
|
57
|
+
if (ingredient instanceof BlockResult) {
|
|
58
|
+
return ingredient.id;
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
function extractFluidID(ingredient) {
|
|
63
|
+
if (ingredient instanceof FluidResult) {
|
|
64
|
+
return ingredient.id;
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=filter.js.map
|
|
@@ -0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C3C,sCAAsC;AACtC,SAAS,cAAc,CAAC,UAAkB;IACxC,IAAI,UAAU,YAAY,WAAW,EAAE,CAAC;QACtC,OAAO,UAAU,CAAC,EAAE,CAAC;IACvB,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,cAAc,CAAC,UAAkB;IACxC,IAAI,UAAU,YAAY,WAAW,EAAE,CAAC;QACtC,OAAO,UAAU,CAAC,EAAE,CAAC;IACvB,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { BlockId, FluidId, ItemId } from "@adeficior/data-modifier/generated";
|
|
2
|
+
import type RegistryLookup from "../../loader/registry";
|
|
3
|
+
import type { SemVerInput } from "../../packFormat";
|
|
4
|
+
import { type IdInput } from "../id";
|
|
5
|
+
import type { Serializable } from "../serializable";
|
|
6
|
+
export declare abstract class Result implements Serializable {
|
|
7
|
+
validate(_?: RegistryLookup): void;
|
|
8
|
+
abstract toJSON(packFormat: SemVerInput): Record<string, unknown>;
|
|
9
|
+
}
|
|
10
|
+
export declare class ItemResult extends Result {
|
|
11
|
+
readonly id: IdInput<ItemId>;
|
|
12
|
+
readonly count: number;
|
|
13
|
+
readonly chance?: number | undefined;
|
|
14
|
+
constructor(id: IdInput<ItemId>, count?: number, chance?: number | undefined);
|
|
15
|
+
toJSON(_packFormat: SemVerInput): {
|
|
16
|
+
item: `${string}:${string}`;
|
|
17
|
+
count: number | undefined;
|
|
18
|
+
chance: number | undefined;
|
|
19
|
+
};
|
|
20
|
+
validate(lookup?: RegistryLookup): void;
|
|
21
|
+
}
|
|
22
|
+
export declare class FluidResult extends Result {
|
|
23
|
+
readonly id: IdInput<FluidId>;
|
|
24
|
+
readonly amount: number;
|
|
25
|
+
readonly chance?: number | undefined;
|
|
26
|
+
constructor(id: IdInput<FluidId>, amount?: number, chance?: number | undefined);
|
|
27
|
+
toJSON(_packFormat: SemVerInput): {
|
|
28
|
+
fluid: `${string}:${string}`;
|
|
29
|
+
amount: number;
|
|
30
|
+
chance: number | undefined;
|
|
31
|
+
};
|
|
32
|
+
validate(lookup?: RegistryLookup): void;
|
|
33
|
+
}
|
|
34
|
+
export declare class BlockResult extends Result {
|
|
35
|
+
readonly id: IdInput<BlockId>;
|
|
36
|
+
constructor(id: IdInput<BlockId>);
|
|
37
|
+
toJSON(_packFormat: SemVerInput): {
|
|
38
|
+
block: `${string}:${string}`;
|
|
39
|
+
};
|
|
40
|
+
validate(lookup?: RegistryLookup): void;
|
|
41
|
+
}
|