Handle invalid set_lore functions

This commit is contained in:
Misode
2024-12-03 21:14:26 +01:00
parent 1d1bae9459
commit a8aaec69e2
2 changed files with 5 additions and 0 deletions

View File

@@ -471,6 +471,7 @@ const LootFunctions: Record<string, (params: any) => 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))))

View File

@@ -351,6 +351,9 @@ const LootFunctions: Record<string, (params: any) => 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<string, (params: any) => 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))))