diff options
author | Linnea Gräf <nea@nea.moe> | 2024-04-26 18:04:45 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-04-26 18:15:54 +0200 |
commit | 7e0151569477df63601be50c82177ecfd21e5deb (patch) | |
tree | f30e5440a1855de92d2b424ef79339d3d6cf5f34 /src/main/kotlin/moe/nea/firmament/util/item | |
parent | 041da7c7d179df01c4048a81ddf40a9f13c3ce77 (diff) | |
download | firmament-7e0151569477df63601be50c82177ecfd21e5deb.tar.gz firmament-7e0151569477df63601be50c82177ecfd21e5deb.tar.bz2 firmament-7e0151569477df63601be50c82177ecfd21e5deb.zip |
Bump to 1.20.5
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/util/item')
-rw-r--r-- | src/main/kotlin/moe/nea/firmament/util/item/NbtItemData.kt | 31 | ||||
-rw-r--r-- | src/main/kotlin/moe/nea/firmament/util/item/SkullItemData.kt | 20 |
2 files changed, 16 insertions, 35 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/util/item/NbtItemData.kt b/src/main/kotlin/moe/nea/firmament/util/item/NbtItemData.kt index 80628ae..c366dc2 100644 --- a/src/main/kotlin/moe/nea/firmament/util/item/NbtItemData.kt +++ b/src/main/kotlin/moe/nea/firmament/util/item/NbtItemData.kt @@ -7,27 +7,20 @@ package moe.nea.firmament.util.item +import net.minecraft.component.DataComponentTypes +import net.minecraft.component.type.LoreComponent import net.minecraft.item.ItemStack -import net.minecraft.nbt.NbtElement -import net.minecraft.nbt.NbtString import net.minecraft.text.Text -fun textFromNbt() { - -} - -val ItemStack.loreAccordingToNbt - get() = getOrCreateSubNbt(ItemStack.DISPLAY_KEY).getList(ItemStack.LORE_KEY, NbtElement.STRING_TYPE.toInt()) - .map { - lazy(LazyThreadSafetyMode.NONE) { - Text.Serialization.fromJson((it as NbtString).asString()) - } - } +var ItemStack.loreAccordingToNbt + get() = get(DataComponentTypes.LORE)?.lines ?: listOf() + set(value) { + set(DataComponentTypes.LORE, LoreComponent(value)) + } val ItemStack.displayNameAccordingToNbt - get() = getOrCreateSubNbt(ItemStack.DISPLAY_KEY).let { - if (it.contains(ItemStack.NAME_KEY, NbtElement.STRING_TYPE.toInt())) - Text.Serialization.fromJson(it.getString(ItemStack.NAME_KEY)) - else - null - } + get() = get(DataComponentTypes.CUSTOM_NAME) ?: get(DataComponentTypes.ITEM_NAME) ?: item.name + +fun ItemStack.setCustomName(literal: Text) { + set(DataComponentTypes.CUSTOM_NAME, literal) +} diff --git a/src/main/kotlin/moe/nea/firmament/util/item/SkullItemData.kt b/src/main/kotlin/moe/nea/firmament/util/item/SkullItemData.kt index a061ee4..96bf49a 100644 --- a/src/main/kotlin/moe/nea/firmament/util/item/SkullItemData.kt +++ b/src/main/kotlin/moe/nea/firmament/util/item/SkullItemData.kt @@ -17,15 +17,12 @@ import kotlinx.datetime.Clock import kotlinx.datetime.Instant import kotlinx.serialization.Serializable import kotlinx.serialization.UseSerializers -import kotlinx.serialization.decodeFromString import kotlinx.serialization.encodeToString -import net.minecraft.block.entity.SkullBlockEntity +import net.minecraft.component.DataComponentTypes +import net.minecraft.component.type.ProfileComponent import net.minecraft.item.ItemStack import net.minecraft.item.Items -import net.minecraft.nbt.NbtCompound -import net.minecraft.nbt.NbtHelper import moe.nea.firmament.Firmament -import moe.nea.firmament.repo.set import moe.nea.firmament.util.assertTrueOr import moe.nea.firmament.util.json.DashlessUUIDSerializer import moe.nea.firmament.util.json.InstantAsLongSerializer @@ -60,11 +57,7 @@ fun ItemStack.setEncodedSkullOwner(uuid: UUID, encodedData: String) { assert(this.item == Items.PLAYER_HEAD) val gameProfile = GameProfile(uuid, "LameGuy123") gameProfile.properties.put(propertyTextures, Property(propertyTextures, encodedData.padBase64())) - val nbt: NbtCompound = this.orCreateNbt - nbt[SkullBlockEntity.SKULL_OWNER_KEY] = NbtHelper.writeGameProfile( - NbtCompound(), - gameProfile - ) + this.set(DataComponentTypes.PROFILE, ProfileComponent(gameProfile)) } val zeroUUID = UUID.fromString("d3cb85e2-3075-48a1-b213-a9bfb62360c1") @@ -76,12 +69,7 @@ fun ItemStack.setSkullOwner(uuid: UUID, url: String) { mapOf(MinecraftProfileTexture.Type.SKIN to MinecraftProfileTextureKt(url)) ) ) - val nbt: NbtCompound = this.orCreateNbt - nbt[SkullBlockEntity.SKULL_OWNER_KEY] = NbtHelper.writeGameProfile( - NbtCompound(), - gameProfile - ) - + this.set(DataComponentTypes.PROFILE, ProfileComponent(gameProfile)) } |