From 60994a08677d864f79de58d8912b02d2d7077289 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Sat, 27 Jul 2024 05:07:58 +0200 Subject: Add some carnival features --- .../moe/nea/firmament/util/LegacyFormattingCode.kt | 3 +++ .../kotlin/moe/nea/firmament/util/SkyblockId.kt | 29 ++++++++++++++++------ .../moe/nea/firmament/util/item/SkullItemData.kt | 3 +++ 3 files changed, 28 insertions(+), 7 deletions(-) (limited to 'src/main/kotlin/moe/nea/firmament/util') diff --git a/src/main/kotlin/moe/nea/firmament/util/LegacyFormattingCode.kt b/src/main/kotlin/moe/nea/firmament/util/LegacyFormattingCode.kt index 1dcd08e..ff4d85b 100644 --- a/src/main/kotlin/moe/nea/firmament/util/LegacyFormattingCode.kt +++ b/src/main/kotlin/moe/nea/firmament/util/LegacyFormattingCode.kt @@ -1,5 +1,6 @@ /* * SPDX-FileCopyrightText: 2023 Linnea Gräf + * SPDX-FileCopyrightText: 2024 Linnea Gräf * * SPDX-License-Identifier: GPL-3.0-or-later */ @@ -34,4 +35,6 @@ enum class LegacyFormattingCode(val label: String, val char: Char, val index: In val modern = Formatting.byCode(char)!! + val formattingCode = "§$char" + } diff --git a/src/main/kotlin/moe/nea/firmament/util/SkyblockId.kt b/src/main/kotlin/moe/nea/firmament/util/SkyblockId.kt index 040e2e9..3ac1463 100644 --- a/src/main/kotlin/moe/nea/firmament/util/SkyblockId.kt +++ b/src/main/kotlin/moe/nea/firmament/util/SkyblockId.kt @@ -16,9 +16,11 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.UseSerializers import kotlinx.serialization.json.Json import net.minecraft.component.DataComponentTypes +import net.minecraft.component.type.NbtComponent import net.minecraft.item.ItemStack import net.minecraft.nbt.NbtCompound import net.minecraft.util.Identifier +import moe.nea.firmament.repo.set import moe.nea.firmament.util.json.DashlessUUIDSerializer /** @@ -32,12 +34,12 @@ import moe.nea.firmament.util.json.DashlessUUIDSerializer value class SkyblockId(val neuItem: String) { val identifier get() = Identifier.of("skyblockitem", - neuItem.lowercase().replace(";", "__") - .replace(":", "___") - .replace(illlegalPathRegex) { - it.value.toCharArray() - .joinToString("") { "__" + it.code.toString(16).padStart(4, '0') } - }) + neuItem.lowercase().replace(";", "__") + .replace(":", "___") + .replace(illlegalPathRegex) { + it.value.toCharArray() + .joinToString("") { "__" + it.code.toString(16).padStart(4, '0') } + }) override fun toString(): String { return neuItem @@ -85,7 +87,14 @@ data class HypixelPetInfo( private val jsonparser = Json { ignoreUnknownKeys = true } val ItemStack.extraAttributes: NbtCompound - get() = get(DataComponentTypes.CUSTOM_DATA)?.nbt ?: NbtCompound() + get() { + val customData = get(DataComponentTypes.CUSTOM_DATA) ?: run { + val component = NbtComponent.of(NbtCompound()) + set(DataComponentTypes.CUSTOM_DATA, component) + component + } + return customData.nbt + } val ItemStack.skyblockUUIDString: String? get() = extraAttributes.getString("uuid")?.takeIf { it.isNotBlank() } @@ -101,6 +110,12 @@ val ItemStack.petData: HypixelPetInfo? .getOrElse { return null } } +fun ItemStack.setSkyBlockFirmamentUiId(uiId: String) = setSkyBlockId(SkyblockId("FIRMAMENT_UI_$uiId")) +fun ItemStack.setSkyBlockId(skyblockId: SkyblockId): ItemStack { + this.extraAttributes["id"] = skyblockId.neuItem + return this +} + val ItemStack.skyBlockId: SkyblockId? get() { return when (val id = extraAttributes.getString("id")) { 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 291abed..c22b987 100644 --- a/src/main/kotlin/moe/nea/firmament/util/item/SkullItemData.kt +++ b/src/main/kotlin/moe/nea/firmament/util/item/SkullItemData.kt @@ -59,6 +59,9 @@ fun ItemStack.setEncodedSkullOwner(uuid: UUID, encodedData: String) { } val zeroUUID = UUID.fromString("d3cb85e2-3075-48a1-b213-a9bfb62360c1") +fun createSkullItem(uuid: UUID, url: String) = ItemStack(Items.PLAYER_HEAD) + .also { it.setSkullOwner(uuid, url) } + fun ItemStack.setSkullOwner(uuid: UUID, url: String) { assert(this.item == Items.PLAYER_HEAD) val gameProfile = GameProfile(uuid, "nea89") -- cgit