Skip to content

Commit a8aaec6

Browse files
committed
Handle invalid set_lore functions
1 parent 1d1bae9 commit a8aaec6

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

src/app/components/previews/LootTable.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ const LootFunctions: Record<string, (params: any) => LootFunction> = {
471471
.set('seed', new NbtLong(typeof seed === 'number' ? BigInt(seed) : BigInt(0))))
472472
},
473473
set_lore: ({ lore }) => (item) => {
474+
if (!Array.isArray(lore)) return
474475
const lines: string[] = lore.flatMap((line: any) => line !== undefined ? [JSON.stringify(line)] : [])
475476
// TODO: account for mode
476477
item.set('lore', new NbtList(lines.map(l => new NbtString(l))))

src/app/components/previews/LootTable1204.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,9 @@ const LootFunctions: Record<string, (params: any) => LootFunction> = {
351351
}
352352
},
353353
set_enchantments: ({ enchantments, add }) => (item, ctx) => {
354+
if (!isObject(enchantments)) {
355+
return
356+
}
354357
Object.entries(enchantments).forEach(([id, level]) => {
355358
const lvl = computeInt(level, ctx)
356359
try {
@@ -359,6 +362,7 @@ const LootFunctions: Record<string, (params: any) => LootFunction> = {
359362
})
360363
},
361364
set_lore: ({ lore, replace }) => (item) => {
365+
if (!Array.isArray(lore)) return
362366
const lines: string[] = lore.flatMap((line: any) => line !== undefined ? [JSON.stringify(line)] : [])
363367
const newLore = replace ? lines : [...item.tag.getCompound('display').getList('Lore', NbtType.String).map(s => s.getAsString()), ...lines]
364368
getOrCreateTag(item, 'display').set('Lore', new NbtList(newLore.map(l => new NbtString(l))))

0 commit comments

Comments
 (0)