Fix #599 catch invalid lore lines

This commit is contained in:
Misode
2024-09-18 17:38:31 +02:00
parent 586c777cf8
commit 88b7b74ca0
2 changed files with 13 additions and 5 deletions

View File

@@ -115,7 +115,7 @@ export function ItemTooltip({ item, advanced, resolver }: Props) {
: <TextComponent component={{ translate: 'item.dyed', color: 'gray' }} />
)}
{item.getLore().map((component) =>
<TextComponent component={JSON.parse(component)} base={{ color: 'dark_purple', italic: true }} />
<TextComponent component={component} base={{ color: 'dark_purple', italic: true }} />
)}
{item.showInTooltip('attribute_modifiers') && (
<AttributeModifiersTooltip data={item.get('attribute_modifiers', tag => tag)} />

View File

@@ -107,7 +107,13 @@ export class ResolvedItem extends ItemStack {
public getLore() {
return this.get('lore', tag => {
return tag.isList() ? tag.map(e => e.getAsString()) : []
return tag.isList() ? tag.map(e => {
try {
return JSON.parse(e.getAsString())
} catch (e) {
return { text: '(invalid lore line)' }
}
}) : []
}) ?? []
}
@@ -160,11 +166,13 @@ export class ResolvedItem extends ItemStack {
}
const itemName = this.get('item_name', tag => tag.isString() ? tag.getAsString() : undefined)
try {
if (itemName) {
if (itemName) {
try {
return JSON.parse(itemName)
} catch (e) {
return { text: '(invalid item name)' }
}
} catch (e) {}
}
const guess = this.id.path
.replace(/[_\/]/g, ' ')