diff --git a/src/app/components/ItemTooltip.tsx b/src/app/components/ItemTooltip.tsx index 6f39b81b..f64df6a3 100644 --- a/src/app/components/ItemTooltip.tsx +++ b/src/app/components/ItemTooltip.tsx @@ -36,39 +36,41 @@ export function ItemTooltip({ item, advanced }: Props) { return <> 0 }} /> - {(!advanced && displayName.length === 0 && item.is('filled_map') && item.tag.hasNumber('map')) && <> - + {shouldShow(item, 'additional') && <> + {(!advanced && displayName.length === 0 && item.is('filled_map') && item.tag.hasNumber('map')) && <> + + } + {(item.is('filled_map') && advanced) && <> + + } + {isPotion && effects.length === 0 + ? + : effects.map(e => { + const color = e.effect.category === 'harmful' ? 'red' : 'blue' + let component: any = { translate: `effect.${e.effect.id.namespace}.${e.effect.id.path}` } + if (e.amplifier > 0) { + component = { translate: 'potion.withAmplifier', with: [component, { translate: `potion.potency.${e.amplifier}` }] } + } + if (e.duration > 20) { + component = { translate: 'potion.withDuration', with: [component, MobEffectInstance.formatDuration(e)] } + } + return + })} + {attributeModifiers.length > 0 && <> + + + {attributeModifiers.map(([attr, { amount, operation }]) => { + const a = operation === AttributeModifierOperation.addition ? amount * 100 : amount + if (amount > 0) { + return + } else if (amount < 0) { + return + } + return null + })} + } } - {(item.is('filled_map') && advanced) && <> - - } - {isPotion && effects.length === 0 - ? - : effects.map(e => { - const color = e.effect.category === 'harmful' ? 'red' : 'blue' - let component: any = { translate: `effect.${e.effect.id.namespace}.${e.effect.id.path}` } - if (e.amplifier > 0) { - component = { translate: 'potion.withAmplifier', with: [component, { translate: `potion.potency.${e.amplifier}` }] } - } - if (e.duration > 20) { - component = { translate: 'potion.withDuration', with: [component, MobEffectInstance.formatDuration(e)] } - } - return - })} - {attributeModifiers.length > 0 && <> - - - {attributeModifiers.map(([attr, { amount, operation }]) => { - const a = operation === AttributeModifierOperation.addition ? amount * 100 : amount - if (amount > 0) { - return - } else if (amount < 0) { - return - } - return null - })} - } - {enchantments.map(enchantment => { + {shouldShow(item, 'enchantments') && enchantments.map(enchantment => { const id = enchantment.getString('id') const lvl = enchantment.getNumber('lvl') const ench = Enchantment.REGISTRY.get(Identifier.parse(id)) @@ -79,12 +81,12 @@ export function ItemTooltip({ item, advanced }: Props) { return })} {item.tag.hasCompound('display') && <> - {item.tag.getCompound('display').hasNumber('color') && (advanced + {shouldShow(item, 'dye') && item.tag.getCompound('display').hasNumber('color') && (advanced ? : )} {(item.tag.getCompound('display').getList('Lore', NbtType.String)).map((line) => )} } - {item.tag.getBoolean('Unbreakable') && } + {shouldShow(item, 'unbreakable') && item.tag.getBoolean('Unbreakable') && } {(advanced && item.tag.getNumber('Damage') > 0 && durability) && } {advanced && <> @@ -100,3 +102,19 @@ function fakeTranslation(str: string) { .map(word => word.charAt(0).toUpperCase() + word.slice(1)) .join(' ') } + +const TooltipMasks = { + enchantments: 1, + modifiers: 2, + unbreakable: 4, + can_destroy: 8, + can_place: 16, + additional: 32, + dye: 64, + upgrades: 128, +} + +function shouldShow(item: ItemStack, mask: keyof typeof TooltipMasks) { + const flags = item.tag.getNumber('HideFlags') + return (flags & TooltipMasks[mask]) === 0 +}