1717 */
1818package gg.skytils.skytilsmod.utils
1919
20+ import com.mojang.authlib.properties.Property
21+ import com.mojang.authlib.properties.PropertyMap
2022import gg.skytils.skytilsmod.utils.ItemRarity.Companion.RARITY_PATTERN
2123import gg.skytils.skytilsmod.utils.multiplatform.nbt
24+ import net.minecraft.component.DataComponentTypes
25+ import net.minecraft.component.type.LoreComponent
26+ import net.minecraft.component.type.ProfileComponent
2227import net.minecraft.item.ItemStack
2328import net.minecraft.nbt.NbtCompound
2429import net.minecraft.nbt.NbtList
30+ import net.minecraft.text.Text
31+ import java.util.Optional
32+ import java.util.UUID
2533import kotlin.jvm.optionals.getOrDefault
2634import kotlin.jvm.optionals.getOrNull
2735import kotlin.math.max
@@ -63,7 +71,7 @@ object ItemUtil {
6371 */
6472 @JvmStatic
6573 fun getSkyBlockItemID (item : ItemStack ? ): String? {
66- if (item == null ) {
74+ if (item == null || item.isEmpty ) {
6775 return null
6876 }
6977 val extraAttributes = getExtraAttributes(item) ? : return null
@@ -81,7 +89,7 @@ object ItemUtil {
8189 */
8290 @JvmStatic
8391 fun getExtraAttributes (item : ItemStack ? ): NbtCompound ? =
84- item?.nbt?.getCompoundOrEmpty(" ExtraAttributes" )
92+ item?.get( DataComponentTypes . CUSTOM_DATA )?. nbt?.getCompoundOrEmpty(" ExtraAttributes" )
8593
8694 /* *
8795 * Returns the Skyblock Item ID of a given Skyblock Extra Attributes NBT Compound
@@ -103,12 +111,7 @@ object ItemUtil {
103111 */
104112 @JvmStatic
105113 fun getItemLore (itemStack : ItemStack ): List <String > =
106- itemStack.nbt?.getCompoundOrEmpty(" display" )
107- ?.takeUnless (NbtCompound ::isEmpty)
108- ?.getListOrEmpty(" Lore" )
109- ?.mapNotNull { line ->
110- line.asString().getOrNull()
111- } ? : emptyList()
114+ itemStack.get(DataComponentTypes .LORE )?.lines?.map { it.formattedText } ? : emptyList()
112115
113116 @JvmStatic
114117 fun hasRightClickAbility (itemStack : ItemStack ): Boolean {
@@ -150,9 +153,12 @@ object ItemUtil {
150153 ?.getOrNull()
151154 ?.run (PET_PATTERN ::matches) ? : false
152155
153- // TODO: Fix this, maybe construct the entire item nbt and deserialize from that?
154156 fun setSkullTexture (item : ItemStack , texture : String , SkullOwner : String ): ItemStack {
155- val textureTagCompound = NbtCompound ()
157+ item.set(DataComponentTypes .PROFILE , ProfileComponent (Optional .empty(), Optional .of(UUID .fromString(SkullOwner )),
158+ PropertyMap ().apply {
159+ put(" textures" , Property (" Value" , texture))
160+ }))
161+ /* val textureTagCompound = NbtCompound()
156162 textureTagCompound.putString("Value", texture)
157163
158164 val textures = NbtList()
@@ -168,18 +174,12 @@ object ItemUtil {
168174 val nbtTag = NbtCompound()
169175 nbtTag.put("SkullOwner", skullOwner)
170176
171- // item.nbt = nbtTag
177+ // item.nbt = nbtTag*/
172178 return item
173179 }
174180
175181 fun getSkullTexture (item : ItemStack ? ): String? =
176- item?.nbt
177- ?.getCompoundOrEmpty(" SkullOwner" )
178- ?.getCompoundOrEmpty(" Properties" )
179- ?.getListOrEmpty(" textures" )
180- ?.getCompoundOrEmpty(0 )
181- ?.getString(" Value" )
182- ?.getOrNull()
182+ item?.get(DataComponentTypes .PROFILE )?.properties?.get(" textures" )?.first()?.value
183183
184184 // TODO: fix later
185185 fun ItemStack.setLore (lines : List <String >): ItemStack {
@@ -188,6 +188,7 @@ object ItemUtil {
188188// for (line in lines) add(NbtString(line))
189189// })
190190// })
191+ this .set(DataComponentTypes .LORE , LoreComponent (lines.map { Text .of(it) }))
191192 return this
192193 }
193194
0 commit comments