mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-23 07:10:41 +00:00
Handle invalid set_lore functions
This commit is contained in:
@@ -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))))
|
||||
|
||||
@@ -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))))
|
||||
|
||||
Reference in New Issue
Block a user