@adeficior/data-modifier-loot 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.
@@ -0,0 +1,42 @@
1
+ import { type ClearableEmitter, type IdInput, type LoaderContext, type NormalizedId, type RegistryLookup, type RegistryProvider, type SemVerInput } from "@adeficior/data-modifier-core";
2
+ import { type CommonFilter } from "@adeficior/data-modifier-core/serializer";
3
+ import { type IngredientFilter, type Predicates } from "@adeficior/data-modifier-ingredients";
4
+ import { type LootItemInput, type LootModifier, type LootTable } from "./schema";
5
+ export declare const EMPTY_LOOT_TABLE: LootTable;
6
+ export declare const EMPTY_LOOT_MODIFIER: LootModifier;
7
+ type LootTableTest = Readonly<{
8
+ id?: CommonFilter<NormalizedId>;
9
+ output?: IngredientFilter;
10
+ }>;
11
+ export interface LootRules {
12
+ replaceOutput(from: IngredientFilter, to: LootItemInput, additionalTests?: LootTableTest): void;
13
+ removeOutput(from: IngredientFilter, additionalTests?: LootTableTest): void;
14
+ add(id: IdInput, value: LootTable): void;
15
+ disable(test: LootTableTest): void;
16
+ block(id: IdInput): void;
17
+ addModifier<T extends LootModifier>(id: IdInput, value: T): void;
18
+ disabledModifier(id: IdInput): void;
19
+ }
20
+ export declare class LootTableEmitter implements LootRules, ClearableEmitter {
21
+ private readonly packFormat;
22
+ private readonly lootTables;
23
+ private readonly lookup;
24
+ private readonly predicates;
25
+ private readonly customTables;
26
+ private readonly customModifiers;
27
+ private readonly ruled;
28
+ constructor(packFormat: SemVerInput, lootTables: RegistryProvider<LootTable>, lookup: RegistryLookup, predicates: Predicates);
29
+ resolver(context: LoaderContext): import("@adeficior/pack-resolver").Resolver<import("@adeficior/pack-resolver").Acceptable, import("@adeficior/pack-resolver").BaseContext>;
30
+ private tablePath;
31
+ private modifierPath;
32
+ clear(): void;
33
+ private resolveLootTableTest;
34
+ add(id: IdInput, value: LootTable): void;
35
+ disable(test: LootTableTest): void;
36
+ replaceOutput(from: IngredientFilter, to: LootItemInput, additionalTests?: LootTableTest): void;
37
+ removeOutput(from: IngredientFilter, additionalTests?: LootTableTest): void;
38
+ block(id: IdInput): void;
39
+ disabledModifier(id: IdInput): void;
40
+ addModifier<T extends LootModifier>(id: IdInput, value: T): void;
41
+ }
42
+ export {};
@@ -0,0 +1,107 @@
1
+ import { CustomEmitter, encodeId, prefix, RuledEmitter, } from "@adeficior/data-modifier-core";
2
+ import {} from "@adeficior/data-modifier-core/serializer";
3
+ import {} from "@adeficior/data-modifier-ingredients";
4
+ import { combineResolvers } from "@adeficior/pack-resolver";
5
+ import { lootTableFolder } from "./helper";
6
+ import { LootTableRule } from "./rule";
7
+ import { EmptyLootEntry, LootTableSchema, } from "./schema";
8
+ import { createLootEntry, replaceItemInTable } from "./serializer";
9
+ export const EMPTY_LOOT_TABLE = {
10
+ type: "minecraft:empty",
11
+ pools: [],
12
+ };
13
+ export const EMPTY_LOOT_MODIFIER = {
14
+ type: "noop",
15
+ };
16
+ export class LootTableEmitter {
17
+ packFormat;
18
+ lootTables;
19
+ lookup;
20
+ predicates;
21
+ customTables = new CustomEmitter((it) => this.tablePath(it));
22
+ customModifiers = new CustomEmitter((it) => this.modifierPath(it));
23
+ ruled;
24
+ constructor(
25
+ // TODO inject
26
+ packFormat, lootTables, lookup, predicates) {
27
+ this.packFormat = packFormat;
28
+ this.lootTables = lootTables;
29
+ this.lookup = lookup;
30
+ this.predicates = predicates;
31
+ this.ruled = new RuledEmitter(this.lootTables, (id) => this.tablePath(id), EMPTY_LOOT_TABLE,
32
+ // TODO also add value object here?
33
+ (it) => it, (id) => this.customTables.has(id));
34
+ }
35
+ resolver(context) {
36
+ return combineResolvers([
37
+ this.ruled.resolver(context),
38
+ this.customTables.resolver(context),
39
+ this.customModifiers.resolver(context),
40
+ ], { async: true });
41
+ }
42
+ tablePath(id) {
43
+ const folder = lootTableFolder(this.packFormat);
44
+ return `data/${id.namespace}/${folder}/${id.path}.json`;
45
+ }
46
+ modifierPath(id) {
47
+ return `data/${id.namespace}/loot_modifiers/${id.path}.json`;
48
+ }
49
+ clear() {
50
+ this.customTables.clear();
51
+ this.customModifiers.clear();
52
+ this.ruled.clear();
53
+ }
54
+ resolveLootTableTest(test) {
55
+ const id = [];
56
+ const output = [];
57
+ if (test.id)
58
+ id.push(this.predicates.id(test.id, "minecraft:item"));
59
+ if (test.output)
60
+ output.push(this.predicates.ingredient(test.output));
61
+ return { id, output };
62
+ }
63
+ add(id, value) {
64
+ this.customTables.add(id, LootTableSchema.parse(value));
65
+ }
66
+ disable(test) {
67
+ const predicates = this.resolveLootTableTest(test);
68
+ this.ruled.addRule(new LootTableRule({ operation: "remove", test }, predicates.id, predicates.output, () => null));
69
+ }
70
+ replaceOutput(from, to, additionalTests = {}) {
71
+ const predicates = this.resolveLootTableTest(additionalTests);
72
+ const outputPredicate = this.predicates.ingredient(from);
73
+ const replacer = replaceItemInTable(outputPredicate, createLootEntry(to, this.lookup));
74
+ this.ruled.addRule(new LootTableRule({ operation: "replace output", from, to, test: additionalTests }, predicates.id, [outputPredicate, ...predicates.output], replacer));
75
+ }
76
+ removeOutput(from, additionalTests) {
77
+ this.replaceOutput(from, EmptyLootEntry, additionalTests);
78
+ }
79
+ block(id) {
80
+ this.add(prefix(id, "blocks/"), {
81
+ type: "minecraft:block",
82
+ pools: [
83
+ {
84
+ rolls: 1,
85
+ entries: [
86
+ {
87
+ type: "minecraft:item",
88
+ name: encodeId(id),
89
+ },
90
+ ],
91
+ conditions: [
92
+ {
93
+ condition: "minecraft:survives_explosion",
94
+ },
95
+ ],
96
+ },
97
+ ],
98
+ });
99
+ }
100
+ disabledModifier(id) {
101
+ this.addModifier(id, EMPTY_LOOT_MODIFIER);
102
+ }
103
+ addModifier(id, value) {
104
+ this.customModifiers.add(id, value);
105
+ }
106
+ }
107
+ //# sourceMappingURL=emitter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emitter.js","sourceRoot":"","sources":["../src/emitter.ts"],"names":[],"mappings":"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AAC,aAAa,CAAC,IAAI,EAAE,cAAc,EAAE,eAAe,CAAC,CAAC;IAC5D,CAAC;IAED,KAAK,CAAC,EAAW;QACf,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,EAAE,SAAS,CAAC,EAAE;YAC9B,IAAI,EAAE,iBAAiB;YACvB,KAAK,EAAE;gBACL;oBACE,KAAK,EAAE,CAAC;oBACR,OAAO,EAAE;wBACP;4BACE,IAAI,EAAE,gBAAgB;4BACtB,IAAI,EAAE,QAAQ,CAAC,EAAE,CAAC;yBACnB;qBACF;oBACD,UAAU,EAAE;wBACV;4BACE,SAAS,EAAE,8BAA8B;yBAC1C;qBACF;iBACF;aACF;SACF,CAAC,CAAC;IACL,CAAC;IAED,gBAAgB,CAAC,EAAW;QAC1B,IAAI,CAAC,WAAW,CAAC,EAAE,EAAE,mBAAmB,CAAC,CAAC;IAC5C,CAAC;IAED,WAAW,CAAyB,EAAW,EAAE,KAAQ;QACvD,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;IACtC,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ import { type SemVerInput } from "@adeficior/data-modifier-core";
2
+ export declare function lootTableFolder(packFormat: SemVerInput): "loot_table" | "loot_tables";
package/dist/helper.js ADDED
@@ -0,0 +1,5 @@
1
+ import { isAtLeastVersion, } from "@adeficior/data-modifier-core";
2
+ export function lootTableFolder(packFormat) {
3
+ return isAtLeastVersion(packFormat, "44") ? "loot_table" : "loot_tables";
4
+ }
5
+ //# sourceMappingURL=helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helper.js","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,GAEjB,MAAM,+BAA+B,CAAC;AAEvC,MAAM,UAAU,eAAe,CAAC,UAAuB;IACrD,OAAO,gBAAgB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,aAAa,CAAC;AAC3E,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { EMPTY_LOOT_MODIFIER, EMPTY_LOOT_TABLE, type LootRules, } from "./emitter";
2
+ export type * from "./loader";
3
+ export { default } from "./module";
4
+ export type * from "./schema";
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { EMPTY_LOOT_MODIFIER, EMPTY_LOOT_TABLE, } from "./emitter";
2
+ export { default } from "./module";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,gBAAgB,GAEjB,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { JsonLoader } from "@adeficior/data-modifier-core";
2
+ import { type LootTable } from "./schema";
3
+ export declare class LootTableLoader extends JsonLoader<LootTable> {
4
+ protected parse(json: unknown): LootTable | null;
5
+ }
package/dist/loader.js ADDED
@@ -0,0 +1,9 @@
1
+ import { JsonLoader } from "@adeficior/data-modifier-core";
2
+ import {} from "./schema";
3
+ import { LootTableSchema } from "./schema";
4
+ export class LootTableLoader extends JsonLoader {
5
+ parse(json) {
6
+ return LootTableSchema.parse(json);
7
+ }
8
+ }
9
+ //# sourceMappingURL=loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,EAAkB,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C,MAAM,OAAO,eAAgB,SAAQ,UAAqB;IAC9C,KAAK,CAAC,IAAa;QAC3B,OAAO,eAAe,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;CACF"}
@@ -0,0 +1,11 @@
1
+ import { type LootRules } from "./emitter";
2
+ import { LootTableLoader } from "./loader";
3
+ declare const _default: import("@adeficior/data-modifier-core").ModuleConfig<{
4
+ loaders: {
5
+ loot: LootTableLoader;
6
+ };
7
+ emitters: {
8
+ loot: LootRules;
9
+ };
10
+ }>;
11
+ export default _default;
package/dist/module.js ADDED
@@ -0,0 +1,25 @@
1
+ import { defineModule } from "@adeficior/data-modifier-core";
2
+ import { name } from "../package.json";
3
+ import { LootTableEmitter } from "./emitter";
4
+ import { lootTableFolder } from "./helper";
5
+ import { LootTableLoader } from "./loader";
6
+ export default defineModule({
7
+ importModule: name,
8
+ dependencies: {
9
+ // TODO make optional?
10
+ "@adeficior/data-modifier-tags": "required",
11
+ },
12
+ types: {
13
+ loaders: {
14
+ loot: "LootTableLoader",
15
+ },
16
+ emitters: {
17
+ loot: "LootRules",
18
+ },
19
+ },
20
+ setup(pack) {
21
+ const loader = pack.loader("loot", () => new LootTableLoader(), lootTableFolder(pack.options.packFormat));
22
+ pack.emitter("loot", (container) => new LootTableEmitter(pack.options.packFormat, loader(), container.get("registries"), container.get("predicates")));
23
+ },
24
+ });
25
+ //# sourceMappingURL=module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.js","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAkB,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C,eAAe,YAAY,CAOxB;IACD,YAAY,EAAE,IAAI;IAClB,YAAY,EAAE;QACZ,sBAAsB;QACtB,+BAA+B,EAAE,UAAU;KAC5C;IACD,KAAK,EAAE;QACL,OAAO,EAAE;YACP,IAAI,EAAE,iBAAiB;SACxB;QACD,QAAQ,EAAE;YACR,IAAI,EAAE,WAAW;SAClB;KACF;IACD,KAAK,CAAC,IAAI;QACR,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CACxB,MAAM,EACN,GAAG,EAAE,CAAC,IAAI,eAAe,EAAE,EAC3B,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CACzC,CAAC;QAEF,IAAI,CAAC,OAAO,CACV,MAAM,EACN,CAAC,SAAS,EAAE,EAAE,CACZ,IAAI,gBAAgB,CAClB,IAAI,CAAC,OAAO,CAAC,UAAU,EACvB,MAAM,EAAE,EACR,SAAS,CAAC,GAAG,CAAC,YAAY,CAAC,EAC3B,SAAS,CAAC,GAAG,CAAC,YAAY,CAAC,CAC5B,CACJ,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
package/dist/rule.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { type Id, type Modifier, Rule } from "@adeficior/data-modifier-core";
2
+ import { type Predicate } from "@adeficior/data-modifier-core/serializer";
3
+ import { type Ingredient } from "@adeficior/data-modifier-ingredients";
4
+ import { type ContextLike, type Logger } from "@adeficior/pack-resolver";
5
+ import { type LootTable } from "./schema";
6
+ export declare class LootTableRule extends Rule<LootTable> {
7
+ private readonly context;
8
+ private readonly idTests;
9
+ private readonly outputTests;
10
+ constructor(context: ContextLike, idTests: Predicate<Id>[], outputTests: Predicate<Ingredient>[], modifier: Modifier<LootTable>);
11
+ matches(id: Id, table: LootTable, logger: Logger): boolean;
12
+ printWarning(logger: Logger): void;
13
+ }
package/dist/rule.js ADDED
@@ -0,0 +1,48 @@
1
+ import { IllegalShapeError, Rule, tryCatching, } from "@adeficior/data-modifier-core";
2
+ import {} from "@adeficior/data-modifier-core/serializer";
3
+ import { ItemIngredient, ItemTagIngredient, } from "@adeficior/data-modifier-ingredients";
4
+ import {} from "@adeficior/pack-resolver";
5
+ import { extendLootEntry } from "./schema";
6
+ // TODO add function Predicate<Ingredient> -> Predicate<LootEntry>
7
+ function entryMatches(test, base) {
8
+ try {
9
+ const entry = extendLootEntry(base);
10
+ switch (entry.type) {
11
+ case "minecraft:alternatives":
12
+ return entry.children.some((it) => entryMatches(test, it));
13
+ case "minecraft:item":
14
+ return test(new ItemIngredient(entry.name));
15
+ case "minecraft:tag":
16
+ return test(new ItemTagIngredient(entry.name));
17
+ default:
18
+ return false;
19
+ }
20
+ }
21
+ catch {
22
+ throw new IllegalShapeError(`unknown loot entry type:`, base);
23
+ }
24
+ }
25
+ function hasOutput(logger, test, table) {
26
+ return table.pools.some((pool) => pool.entries.some((entry) => {
27
+ return tryCatching(logger, () => entryMatches(test, entry)) ?? false;
28
+ }));
29
+ }
30
+ export class LootTableRule extends Rule {
31
+ context;
32
+ idTests;
33
+ outputTests;
34
+ constructor(context, idTests, outputTests, modifier) {
35
+ super(modifier);
36
+ this.context = context;
37
+ this.idTests = idTests;
38
+ this.outputTests = outputTests;
39
+ }
40
+ matches(id, table, logger) {
41
+ return (this.idTests.every((test) => test(id)) &&
42
+ this.outputTests.every((test) => hasOutput(logger, test, table)));
43
+ }
44
+ printWarning(logger) {
45
+ logger.trace("could not find any matching loot table", this.context);
46
+ }
47
+ }
48
+ //# sourceMappingURL=rule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rule.js","sourceRoot":"","sources":["../src/rule.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,iBAAiB,EACjB,IAAI,EACJ,WAAW,GACZ,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAkB,MAAM,0CAA0C,CAAC;AAC1E,OAAO,EAEL,cAAc,EACd,iBAAiB,GAClB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAiC,MAAM,0BAA0B,CAAC;AACzE,OAAO,EAAsC,eAAe,EAAE,MAAM,UAAU,CAAC;AAE/E,kEAAkE;AAElE,SAAS,YAAY,CACnB,IAA2B,EAC3B,IAAmB;IAEnB,IAAI,CAAC;QACH,MAAM,KAAK,GA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,EAAE,MAAc;QAC9C,OAAO,CACL,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACtC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CACjE,CAAC;IACJ,CAAC;IAED,YAAY,CAAC,MAAc;QACzB,MAAM,CAAC,KAAK,CAAC,wCAAwC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IACvE,CAAC;CACF"}
@@ -0,0 +1,214 @@
1
+ import { type ItemLikeIngredient, type ItemResult } from "@adeficior/data-modifier-ingredients";
2
+ import * as z from "zod";
3
+ declare const LootEntryBaseSchema: z.ZodObject<{
4
+ type: z.ZodString;
5
+ conditions: z.ZodOptional<z.ZodArray<z.ZodObject<{
6
+ condition: z.ZodString;
7
+ }, z.core.$loose>>>;
8
+ functions: z.ZodOptional<z.ZodArray<z.ZodObject<{
9
+ conditions: z.ZodOptional<z.ZodArray<z.ZodObject<{
10
+ condition: z.ZodString;
11
+ }, z.core.$loose>>>;
12
+ function: z.ZodString;
13
+ }, z.core.$loose>>>;
14
+ }, z.core.$loose>;
15
+ export type LootEntryBase = z.infer<typeof LootEntryBaseSchema>;
16
+ export declare const EmptyLootEntry: LootEntry;
17
+ declare const LootEntrySchema: z.ZodIntersection<z.ZodObject<{
18
+ type: z.ZodString;
19
+ conditions: z.ZodOptional<z.ZodArray<z.ZodObject<{
20
+ condition: z.ZodString;
21
+ }, z.core.$loose>>>;
22
+ functions: z.ZodOptional<z.ZodArray<z.ZodObject<{
23
+ conditions: z.ZodOptional<z.ZodArray<z.ZodObject<{
24
+ condition: z.ZodString;
25
+ }, z.core.$loose>>>;
26
+ function: z.ZodString;
27
+ }, z.core.$loose>>>;
28
+ }, z.core.$loose>, z.ZodDiscriminatedUnion<[z.ZodObject<{
29
+ type: z.ZodLiteral<"minecraft:alternatives">;
30
+ children: z.ZodArray<z.ZodObject<{
31
+ type: z.ZodString;
32
+ conditions: z.ZodOptional<z.ZodArray<z.ZodObject<{
33
+ condition: z.ZodString;
34
+ }, z.core.$loose>>>;
35
+ functions: z.ZodOptional<z.ZodArray<z.ZodObject<{
36
+ conditions: z.ZodOptional<z.ZodArray<z.ZodObject<{
37
+ condition: z.ZodString;
38
+ }, z.core.$loose>>>;
39
+ function: z.ZodString;
40
+ }, z.core.$loose>>>;
41
+ }, z.core.$loose>>;
42
+ }, z.core.$strip>, z.ZodObject<{
43
+ type: z.ZodLiteral<"minecraft:item">;
44
+ name: z.ZodString;
45
+ }, z.core.$strip>, z.ZodObject<{
46
+ type: z.ZodLiteral<"minecraft:tag">;
47
+ name: z.ZodString;
48
+ expand: z.ZodOptional<z.ZodBoolean>;
49
+ }, z.core.$strip>, z.ZodObject<{
50
+ type: z.ZodLiteral<"minecraft:loot_table">;
51
+ name: z.ZodString;
52
+ }, z.core.$strip>, z.ZodObject<{
53
+ type: z.ZodLiteral<"minecraft:empty">;
54
+ }, z.core.$strip>], "type">>;
55
+ export declare function parseLootEntry(input: unknown): {
56
+ [x: string]: unknown;
57
+ type: string;
58
+ conditions?: {
59
+ [x: string]: unknown;
60
+ condition: string;
61
+ }[] | undefined;
62
+ functions?: {
63
+ [x: string]: unknown;
64
+ function: string;
65
+ conditions?: {
66
+ [x: string]: unknown;
67
+ condition: string;
68
+ }[] | undefined;
69
+ }[] | undefined;
70
+ } & ({
71
+ type: "minecraft:alternatives";
72
+ children: {
73
+ [x: string]: unknown;
74
+ type: string;
75
+ conditions?: {
76
+ [x: string]: unknown;
77
+ condition: string;
78
+ }[] | undefined;
79
+ functions?: {
80
+ [x: string]: unknown;
81
+ function: string;
82
+ conditions?: {
83
+ [x: string]: unknown;
84
+ condition: string;
85
+ }[] | undefined;
86
+ }[] | undefined;
87
+ }[];
88
+ } | {
89
+ type: "minecraft:item";
90
+ name: string;
91
+ } | {
92
+ type: "minecraft:tag";
93
+ name: string;
94
+ expand?: boolean | undefined;
95
+ } | {
96
+ type: "minecraft:loot_table";
97
+ name: string;
98
+ } | {
99
+ type: "minecraft:empty";
100
+ });
101
+ export declare function parseLootTable(input: unknown): {
102
+ pools: {
103
+ rolls: number | {
104
+ [x: string]: unknown;
105
+ type?: string | undefined;
106
+ };
107
+ entries: {
108
+ [x: string]: unknown;
109
+ type: string;
110
+ conditions?: {
111
+ [x: string]: unknown;
112
+ condition: string;
113
+ }[] | undefined;
114
+ functions?: {
115
+ [x: string]: unknown;
116
+ function: string;
117
+ conditions?: {
118
+ [x: string]: unknown;
119
+ condition: string;
120
+ }[] | undefined;
121
+ }[] | undefined;
122
+ }[];
123
+ bonus_rolls?: number | {
124
+ [x: string]: unknown;
125
+ type?: string | undefined;
126
+ } | undefined;
127
+ conditions?: {
128
+ [x: string]: unknown;
129
+ condition: string;
130
+ }[] | undefined;
131
+ functions?: {
132
+ [x: string]: unknown;
133
+ function: string;
134
+ conditions?: {
135
+ [x: string]: unknown;
136
+ condition: string;
137
+ }[] | undefined;
138
+ }[] | undefined;
139
+ }[];
140
+ type?: string | undefined;
141
+ };
142
+ export type LootEntry = z.infer<typeof LootEntrySchema>;
143
+ export declare const LootPoolSchema: z.ZodObject<{
144
+ rolls: z.ZodUnion<readonly [z.ZodNumber, z.ZodObject<{
145
+ type: z.ZodOptional<z.ZodString>;
146
+ }, z.core.$loose>]>;
147
+ bonus_rolls: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodObject<{
148
+ type: z.ZodOptional<z.ZodString>;
149
+ }, z.core.$loose>]>>;
150
+ entries: z.ZodArray<z.ZodObject<{
151
+ type: z.ZodString;
152
+ conditions: z.ZodOptional<z.ZodArray<z.ZodObject<{
153
+ condition: z.ZodString;
154
+ }, z.core.$loose>>>;
155
+ functions: z.ZodOptional<z.ZodArray<z.ZodObject<{
156
+ conditions: z.ZodOptional<z.ZodArray<z.ZodObject<{
157
+ condition: z.ZodString;
158
+ }, z.core.$loose>>>;
159
+ function: z.ZodString;
160
+ }, z.core.$loose>>>;
161
+ }, z.core.$loose>>;
162
+ conditions: z.ZodOptional<z.ZodArray<z.ZodObject<{
163
+ condition: z.ZodString;
164
+ }, z.core.$loose>>>;
165
+ functions: z.ZodOptional<z.ZodArray<z.ZodObject<{
166
+ conditions: z.ZodOptional<z.ZodArray<z.ZodObject<{
167
+ condition: z.ZodString;
168
+ }, z.core.$loose>>>;
169
+ function: z.ZodString;
170
+ }, z.core.$loose>>>;
171
+ }, z.core.$strip>;
172
+ export type LootPool = z.infer<typeof LootPoolSchema>;
173
+ export declare const LootTableSchema: z.ZodObject<{
174
+ type: z.ZodOptional<z.ZodString>;
175
+ pools: z.ZodDefault<z.ZodArray<z.ZodObject<{
176
+ rolls: z.ZodUnion<readonly [z.ZodNumber, z.ZodObject<{
177
+ type: z.ZodOptional<z.ZodString>;
178
+ }, z.core.$loose>]>;
179
+ bonus_rolls: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodObject<{
180
+ type: z.ZodOptional<z.ZodString>;
181
+ }, z.core.$loose>]>>;
182
+ entries: z.ZodArray<z.ZodObject<{
183
+ type: z.ZodString;
184
+ conditions: z.ZodOptional<z.ZodArray<z.ZodObject<{
185
+ condition: z.ZodString;
186
+ }, z.core.$loose>>>;
187
+ functions: z.ZodOptional<z.ZodArray<z.ZodObject<{
188
+ conditions: z.ZodOptional<z.ZodArray<z.ZodObject<{
189
+ condition: z.ZodString;
190
+ }, z.core.$loose>>>;
191
+ function: z.ZodString;
192
+ }, z.core.$loose>>>;
193
+ }, z.core.$loose>>;
194
+ conditions: z.ZodOptional<z.ZodArray<z.ZodObject<{
195
+ condition: z.ZodString;
196
+ }, z.core.$loose>>>;
197
+ functions: z.ZodOptional<z.ZodArray<z.ZodObject<{
198
+ conditions: z.ZodOptional<z.ZodArray<z.ZodObject<{
199
+ condition: z.ZodString;
200
+ }, z.core.$loose>>>;
201
+ function: z.ZodString;
202
+ }, z.core.$loose>>>;
203
+ }, z.core.$strip>>>;
204
+ }, z.core.$strip>;
205
+ export type LootTable = z.infer<typeof LootTableSchema>;
206
+ export declare function extendLootEntry(base: LootEntryBase): LootEntry;
207
+ export type LootModifier = Readonly<{
208
+ type: string;
209
+ conditions?: Array<{
210
+ condition: string;
211
+ }>;
212
+ }>;
213
+ export type LootItemInput = ItemLikeIngredient | ItemResult | LootEntry;
214
+ export {};
package/dist/schema.js ADDED
@@ -0,0 +1,83 @@
1
+ import { encodeId } from "@adeficior/data-modifier-core";
2
+ import {} from "@adeficior/data-modifier-ingredients";
3
+ import * as z from "zod";
4
+ const NumberProviderSchema = z.union([
5
+ z.number(),
6
+ z
7
+ .object({
8
+ type: z.string().optional(),
9
+ })
10
+ .passthrough(),
11
+ ]);
12
+ const LootConditionSchema = z
13
+ .object({
14
+ condition: z.string(),
15
+ })
16
+ .passthrough();
17
+ const LootFunctionSchema = z
18
+ .object({
19
+ conditions: z.array(LootConditionSchema).optional(),
20
+ function: z.string(),
21
+ })
22
+ .passthrough();
23
+ const LootEntryBaseSchema = z
24
+ .object({
25
+ type: z.string(),
26
+ conditions: z.array(LootConditionSchema).optional(),
27
+ functions: z.array(LootFunctionSchema).optional(),
28
+ })
29
+ .passthrough();
30
+ const LootEntryAlternativeSchema = z.object({
31
+ type: z.literal("minecraft:alternatives"),
32
+ children: z.array(LootEntryBaseSchema),
33
+ });
34
+ const LootEntryItemSchema = z.object({
35
+ type: z.literal("minecraft:item"),
36
+ name: z.string(),
37
+ });
38
+ const LootEntryTagSchema = z.object({
39
+ type: z.literal("minecraft:tag"),
40
+ name: z.string(),
41
+ expand: z.boolean().optional(),
42
+ });
43
+ const LootEntryEmptySchema = z.object({
44
+ type: z.literal("minecraft:empty"),
45
+ });
46
+ export const EmptyLootEntry = {
47
+ type: "minecraft:empty",
48
+ };
49
+ const LootEntryReferenceSchema = z.object({
50
+ type: z.literal("minecraft:loot_table"),
51
+ name: z.string(),
52
+ });
53
+ const LootEntrySchema = LootEntryBaseSchema.and(z.discriminatedUnion("type", [
54
+ LootEntryAlternativeSchema,
55
+ LootEntryItemSchema,
56
+ LootEntryTagSchema,
57
+ LootEntryReferenceSchema,
58
+ LootEntryEmptySchema,
59
+ ]));
60
+ export function parseLootEntry(input) {
61
+ return LootEntrySchema.parse(input);
62
+ }
63
+ export function parseLootTable(input) {
64
+ return LootTableSchema.parse(input);
65
+ }
66
+ export const LootPoolSchema = z.object({
67
+ rolls: NumberProviderSchema,
68
+ bonus_rolls: NumberProviderSchema.optional(),
69
+ entries: z.array(LootEntryBaseSchema),
70
+ conditions: z.array(LootConditionSchema).optional(),
71
+ functions: z.array(LootFunctionSchema).optional(),
72
+ });
73
+ export const LootTableSchema = z.object({
74
+ type: z.string().optional(),
75
+ pools: z.array(LootPoolSchema).default([]),
76
+ });
77
+ export function extendLootEntry(base) {
78
+ if (typeof base === "object" && "type" in base) {
79
+ base.type = encodeId(base.type);
80
+ }
81
+ return LootEntrySchema.parse(base);
82
+ }
83
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AACzD,OAAO,EAGN,MAAM,sCAAsC,CAAC;AAC9C,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC;IACnC,CAAC,CAAC,MAAM,EAAE;IACV,CAAC;SACE,MAAM,CAAC;QACN,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;KAC5B,CAAC;SACD,WAAW,EAAE;CACjB,CAAC,CAAC;AAEH,MAAM,mBAAmB,GAAG,CAAC;KAC1B,MAAM,CAAC;IACN,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;CACtB,CAAC;KACD,WAAW,EAAE,CAAC;AAEjB,MAAM,kB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AAQ,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;QAC/C,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;IACD,OAAO,eAAe,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACrC,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { type RegistryLookup } from "@adeficior/data-modifier-core";
2
+ import { type Predicate, type Replacer } from "@adeficior/data-modifier-core/serializer";
3
+ import { type Ingredient } from "@adeficior/data-modifier-ingredients";
4
+ import { type LootEntry, type LootItemInput, type LootTable } from "./schema";
5
+ export declare function createLootEntry(input: LootItemInput, lookup: RegistryLookup): LootEntry;
6
+ export declare function replaceItemInTable(predicate: Predicate<Ingredient>, to: LootEntry): Replacer<LootTable>;
@@ -0,0 +1,72 @@
1
+ import { encodeId, stripTag, } from "@adeficior/data-modifier-core";
2
+ import {} from "@adeficior/data-modifier-core/serializer";
3
+ import { ItemIngredient, ItemResult, ItemTagIngredient, } from "@adeficior/data-modifier-ingredients";
4
+ import { extendLootEntry, } from "./schema";
5
+ function createUnvalidatedLootEntry(input) {
6
+ if (input instanceof ItemIngredient || input instanceof ItemResult) {
7
+ return {
8
+ type: "minecraft:item",
9
+ name: encodeId(input.id),
10
+ };
11
+ }
12
+ if (input instanceof ItemTagIngredient) {
13
+ return {
14
+ type: "minecraft:tag",
15
+ name: stripTag(input.tag),
16
+ };
17
+ }
18
+ return extendLootEntry(input);
19
+ }
20
+ function validateLootEntry(entry, lookup) {
21
+ if (entry.type === "minecraft:item")
22
+ lookup.validateEntry("minecraft:item", entry.name);
23
+ if (entry.type === "minecraft:alternatives") {
24
+ entry.children.forEach((it) => validateLootEntry(extendLootEntry(it), lookup));
25
+ }
26
+ }
27
+ export function createLootEntry(input, lookup) {
28
+ const unvalidated = createUnvalidatedLootEntry(input);
29
+ validateLootEntry(unvalidated, lookup);
30
+ return unvalidated;
31
+ }
32
+ // TODO add function Predicate<Ingredient> -> Predicate<LootEntry>
33
+ function replaceItemInEntry(predicate, to) {
34
+ const replace = (base) => {
35
+ const entry = extendLootEntry(base);
36
+ const shared = {
37
+ functions: entry.functions,
38
+ conditions: entry.conditions,
39
+ };
40
+ switch (entry.type) {
41
+ case "minecraft:alternatives":
42
+ return {
43
+ ...entry,
44
+ children: entry.children.map(replace),
45
+ };
46
+ case "minecraft:item":
47
+ return predicate(new ItemIngredient(entry.name))
48
+ ? { ...shared, ...to }
49
+ : entry;
50
+ case "minecraft:tag":
51
+ return predicate(new ItemTagIngredient(entry.name))
52
+ ? { ...shared, ...to }
53
+ : entry;
54
+ default:
55
+ return entry;
56
+ }
57
+ };
58
+ return replace;
59
+ }
60
+ export function replaceItemInTable(predicate, to) {
61
+ const replaceEntry = replaceItemInEntry(predicate, to);
62
+ return (table) => {
63
+ return {
64
+ ...table,
65
+ pools: table.pools.map((pool) => ({
66
+ ...pool,
67
+ entries: pool.entries.map(replaceEntry),
68
+ })),
69
+ };
70
+ };
71
+ }
72
+ //# sourceMappingURL=serializer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serializer.js","sourceRoot":"","sources":["../src/serializer.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAER,QAAQ,GACT,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAGN,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAEL,cAAc,EACd,UAAU,EACV,iBAAiB,GAClB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACL,eAAe,GAKhB,MAAM,UAAU,CAAC;AAElB,SAAS,0BAA0B,CAAC,KAAoB;IACtD,IAAI,KAAK,YAAY,cAAc,IAAI,KAAK,YAAY,UAAU,EAAE,CAAC;QACnE,OAAO;YACL,IAAI,EAAE,gBAAgB;YACtB,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;SACzB,CAAC;IACJ,CAAC;IAED,IAAI,KAAK,YAAY,iBAAiB,EAAE,CAAC;QACvC,OAAO;YACL,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AC,IAAI,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;oBAC9C,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,EAAE;oBACtB,CAAC,CAAC,KAAK,CAAC;YAEZ,KAAK,eAAe;gBAClB,OAAO,SAAS,CAAC,IAAI,iBAAiB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;oBACjD,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,EAAE;oBACtB,CAAC,CAAC,KAAK,CAAC;YAEZ;gBACE,OAAO,KAAK,CAAC;QACjB,CAAC;IACH,CAAC,CAAC;IAEF,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,SAAgC,EAChC,EAAa;IAEb,MAAM,YAAY,GAAG,kBAAkB,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IACvD,OAAO,CAAC,KAAK,EAAE,EAAE;QACf,OAAO;YACL,GAAG,KAAK;YACR,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;gBAChC,GAAG,IAAI;gBACP,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC;aACxC,CAAC,CAAC;SACJ,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@adeficior/data-modifier-loot",
3
+ "version": "2.0.0-rc.20260814115618",
4
+ "exports": {
5
+ ".": "./dist/index.js",
6
+ "./testing": "./dist/testing/index.js"
7
+ },
8
+ "types": "./dist/index.d.ts",
9
+ "typesVersions": {
10
+ "*": {
11
+ "testing": [
12
+ "./dist/testing/index.d.ts"
13
+ ]
14
+ }
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "type": "module",
20
+ "scripts": {
21
+ "build": "tsc --project tsconfig.build.json",
22
+ "check": "tsc --noEmit",
23
+ "dev": "bun run build --watch",
24
+ "lint": "eslint {src,test}",
25
+ "test": "bun test --timeout 10000",
26
+ "prune": "bun run datamod-dev --prune",
27
+ "prepare": "datamod-dev --configs && datamod-dev --types",
28
+ "test:ci": "bun run lint && bun run check && bun run test --coverage"
29
+ },
30
+ "devDependencies": {
31
+ "@adeficior/configs": "workspace:*",
32
+ "@adeficior/testing": "workspace:*",
33
+ "@adeficior/data-modifier-ingredients": "workspace:*"
34
+ },
35
+ "peerDependencies": {
36
+ "@adeficior/pack-resolver": "catalog:",
37
+ "typescript": "catalog:",
38
+ "zod": "catalog:",
39
+ "@adeficior/data-modifier-core": "workspace:*",
40
+ "@adeficior/data-modifier-ingredients": "workspace:*",
41
+ "@adeficior/data-modifier-tags": "workspace:*"
42
+ }
43
+ }