From a8aaec69e2f91378415d3d6fb3ac9b4d061b3a27 Mon Sep 17 00:00:00 2001 From: Misode Date: Tue, 3 Dec 2024 21:14:26 +0100 Subject: [PATCH] Handle invalid set_lore functions --- src/app/components/previews/LootTable.ts | 1 + src/app/components/previews/LootTable1204.ts | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/app/components/previews/LootTable.ts b/src/app/components/previews/LootTable.ts index 15ee7f70..87ba95c5 100644 --- a/src/app/components/previews/LootTable.ts +++ b/src/app/components/previews/LootTable.ts @@ -471,6 +471,7 @@ const LootFunctions: Record LootFunction> = { .set('seed', new NbtLong(typeof seed === 'number' ? BigInt(seed) : BigInt(0)))) }, set_lore: ({ lore }) => (item) => { + if (!Array.isArray(lore)) return const lines: string[] = lore.flatMap((line: any) => line !== undefined ? [JSON.stringify(line)] : []) // TODO: account for mode item.set('lore', new NbtList(lines.map(l => new NbtString(l)))) diff --git a/src/app/components/previews/LootTable1204.ts b/src/app/components/previews/LootTable1204.ts index 3627a9b1..a4eac639 100644 --- a/src/app/components/previews/LootTable1204.ts +++ b/src/app/components/previews/LootTable1204.ts @@ -351,6 +351,9 @@ const LootFunctions: Record LootFunction> = { } }, set_enchantments: ({ enchantments, add }) => (item, ctx) => { + if (!isObject(enchantments)) { + return + } Object.entries(enchantments).forEach(([id, level]) => { const lvl = computeInt(level, ctx) try { @@ -359,6 +362,7 @@ const LootFunctions: Record LootFunction> = { }) }, set_lore: ({ lore, replace }) => (item) => { + if (!Array.isArray(lore)) return const lines: string[] = lore.flatMap((line: any) => line !== undefined ? [JSON.stringify(line)] : []) const newLore = replace ? lines : [...item.tag.getCompound('display').getList('Lore', NbtType.String).map(s => s.getAsString()), ...lines] getOrCreateTag(item, 'display').set('Lore', new NbtList(newLore.map(l => new NbtString(l))))