1
1
import type { MobEffectInstance , NbtTag } from 'deepslate'
2
2
import { ItemStack , NbtCompound , NbtList , PotionContents } from 'deepslate'
3
3
import { Identifier } from 'deepslate/core'
4
+ import { useVersion } from '../contexts/Version.jsx'
4
5
import type { ResolvedItem } from '../services/ResolvedItem.js'
5
6
import { intToDisplayHexRgb , makeDescriptionId , mergeTextComponentStyles } from '../Utils.js'
6
7
import { TextComponent } from './TextComponent.jsx'
@@ -11,8 +12,9 @@ interface Props {
11
12
resolver : ( item : ItemStack ) => ResolvedItem ,
12
13
}
13
14
export function ItemTooltip ( { item, advanced, resolver } : Props ) {
15
+ const { version } = useVersion ( )
14
16
return < >
15
- < TextComponent component = { item . getStyledHoverName ( ) } />
17
+ < TextComponent component = { item . getStyledHoverName ( version ) } />
16
18
{ ! advanced && ! item . has ( 'custom_name' ) && item . is ( 'filled_map' ) && item . has ( 'map_id' ) && (
17
19
< TextComponent component = { { translate : 'filled_map.id' , with : [ item . get ( 'map_id' , tag => tag . getAsNumber ( ) ) ] , color : 'gray' } } />
18
20
) }
@@ -25,7 +27,7 @@ export function ItemTooltip({ item, advanced, resolver }: Props) {
25
27
< 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' } } />
26
28
) }
27
29
{ 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 ) ] } } />
29
31
) }
30
32
{ item . is ( 'disc_fragment_5' ) && (
31
33
< TextComponent component = { { translate : `${ makeDescriptionId ( 'item' , item . id ) } .desc` , color : 'gray' } } />
@@ -63,7 +65,7 @@ export function ItemTooltip({ item, advanced, resolver }: Props) {
63
65
{ item . is ( 'decorated_pot' ) && item . has ( 'pot_decorations' ) && < >
64
66
< TextComponent component = { '' } />
65
67
{ 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' } ) } />
67
69
) : undefined ) }
68
70
</ > }
69
71
{ item . id . path . endsWith ( '_shulker_box' ) && < >
@@ -72,7 +74,7 @@ export function ItemTooltip({ item, advanced, resolver }: Props) {
72
74
) }
73
75
{ ( item . get ( 'container' , tag => tag . isList ( ) ? tag . getItems ( ) : [ ] ) ?? [ ] ) . slice ( 0 , 5 ) . map ( e => {
74
76
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 ] } } />
76
78
} ) }
77
79
{ ( item . get ( 'container' , tag => tag . isList ( ) ? tag . length : 0 ) ?? 0 ) > 5 && (
78
80
< 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) {
110
112
? < TextComponent component = { { translate : 'item.color' , with : [ intToDisplayHexRgb ( item . get ( 'dyed_color' , tag => tag . isCompound ( ) ? tag . getNumber ( 'rgb' ) : tag . getAsNumber ( ) ) ) ] , color : 'gray' } } />
111
113
: < TextComponent component = { { translate : 'item.dyed' , color : 'gray' } } />
112
114
) }
113
- { item . getLore ( ) . map ( ( component ) =>
115
+ { item . getLore ( version ) . map ( ( component ) =>
114
116
< TextComponent component = { component } base = { { color : 'dark_purple' , italic : true } } />
115
117
) }
116
118
{ item . showInTooltip ( 'attribute_modifiers' ) && (
0 commit comments