11import type { MobEffectInstance , NbtTag } from 'deepslate'
22import { ItemStack , NbtCompound , NbtList , PotionContents } from 'deepslate'
33import { Identifier } from 'deepslate/core'
4+ import { useVersion } from '../contexts/Version.jsx'
45import type { ResolvedItem } from '../services/ResolvedItem.js'
56import { intToDisplayHexRgb , makeDescriptionId , mergeTextComponentStyles } from '../Utils.js'
67import { TextComponent } from './TextComponent.jsx'
@@ -11,8 +12,9 @@ interface Props {
1112 resolver : ( item : ItemStack ) => ResolvedItem ,
1213}
1314export function ItemTooltip ( { item, advanced, resolver } : Props ) {
15+ const { version } = useVersion ( )
1416 return < >
15- < TextComponent component = { item . getStyledHoverName ( ) } />
17+ < TextComponent component = { item . getStyledHoverName ( version ) } />
1618 { ! advanced && ! item . has ( 'custom_name' ) && item . is ( 'filled_map' ) && item . has ( 'map_id' ) && (
1719 < TextComponent component = { { translate : 'filled_map.id' , with : [ item . get ( 'map_id' , tag => tag . getAsNumber ( ) ) ] , color : 'gray' } } />
1820 ) }
@@ -25,7 +27,7 @@ export function ItemTooltip({ item, advanced, resolver }: Props) {
2527 < TextComponent component = { { translate : `${ layer . isCompound ( ) ? ( layer . hasCompound ( 'pattern' ) ? layer . getString ( 'translation_key' ) : `block.minecraft.banner.${ layer . getString ( 'pattern' ) . replace ( / ^ m i n e c r a f t : / , '' ) } ` ) : '' } .${ layer . isCompound ( ) ? layer . getString ( 'color' ) : '' } ` , color : 'gray' } } />
2628 ) }
2729 { item . is ( 'crossbow' ) && item . getChargedProjectile ( ) && (
28- < TextComponent component = { { translate : 'item.minecraft.crossbow.projectile' , extra : [ ' ' , resolver ( item . getChargedProjectile ( ) ! ) . getDisplayName ( ) ] } } />
30+ < TextComponent component = { { translate : 'item.minecraft.crossbow.projectile' , extra : [ ' ' , resolver ( item . getChargedProjectile ( ) ! ) . getDisplayName ( version ) ] } } />
2931 ) }
3032 { item . is ( 'disc_fragment_5' ) && (
3133 < TextComponent component = { { translate : `${ makeDescriptionId ( 'item' , item . id ) } .desc` , color : 'gray' } } />
@@ -63,7 +65,7 @@ export function ItemTooltip({ item, advanced, resolver }: Props) {
6365 { item . is ( 'decorated_pot' ) && item . has ( 'pot_decorations' ) && < >
6466 < TextComponent component = { '' } />
6567 { item . get ( 'pot_decorations' , tag => tag . isList ( ) ? tag . map ( e =>
66- < TextComponent component = { mergeTextComponentStyles ( resolver ( new ItemStack ( Identifier . parse ( e . getAsString ( ) ) , 1 ) ) . getHoverName ( ) , { color : 'gray' } ) } />
68+ < TextComponent component = { mergeTextComponentStyles ( resolver ( new ItemStack ( Identifier . parse ( e . getAsString ( ) ) , 1 ) ) . getHoverName ( version ) , { color : 'gray' } ) } />
6769 ) : undefined ) }
6870 </ > }
6971 { item . id . path . endsWith ( '_shulker_box' ) && < >
@@ -72,7 +74,7 @@ export function ItemTooltip({ item, advanced, resolver }: Props) {
7274 ) }
7375 { ( item . get ( 'container' , tag => tag . isList ( ) ? tag . getItems ( ) : [ ] ) ?? [ ] ) . slice ( 0 , 5 ) . map ( e => {
7476 const subItem = resolver ( ItemStack . fromNbt ( e . isCompound ( ) ? e . getCompound ( 'item' ) : new NbtCompound ( ) ) )
75- return < TextComponent component = { { translate : 'container.shulkerBox.itemCount' , with : [ subItem . getHoverName ( ) , subItem . count ] } } />
77+ return < TextComponent component = { { translate : 'container.shulkerBox.itemCount' , with : [ subItem . getHoverName ( version ) , subItem . count ] } } />
7678 } ) }
7779 { ( item . get ( 'container' , tag => tag . isList ( ) ? tag . length : 0 ) ?? 0 ) > 5 && (
7880 < TextComponent component = { { translate : 'container.shulkerBox.more' , with : [ ( item . get ( 'container' , tag => tag . isList ( ) ? tag . length : 0 ) ?? 0 ) - 5 ] , italic : true } } />
@@ -110,7 +112,7 @@ export function ItemTooltip({ item, advanced, resolver }: Props) {
110112 ? < TextComponent component = { { translate : 'item.color' , with : [ intToDisplayHexRgb ( item . get ( 'dyed_color' , tag => tag . isCompound ( ) ? tag . getNumber ( 'rgb' ) : tag . getAsNumber ( ) ) ) ] , color : 'gray' } } />
111113 : < TextComponent component = { { translate : 'item.dyed' , color : 'gray' } } />
112114 ) }
113- { item . getLore ( ) . map ( ( component ) =>
115+ { item . getLore ( version ) . map ( ( component ) =>
114116 < TextComponent component = { component } base = { { color : 'dark_purple' , italic : true } } />
115117 ) }
116118 { item . showInTooltip ( 'attribute_modifiers' ) && (
0 commit comments