aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/util
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-07-27 05:07:58 +0200
committerLinnea Gräf <nea@nea.moe>2024-07-27 05:07:58 +0200
commit60994a08677d864f79de58d8912b02d2d7077289 (patch)
tree70850c6acb5d6fa58d8df9cc08e06a7d92606f2a /src/main/kotlin/moe/nea/firmament/util
parent564f81e1896ea36b9ad165f29f49ce990912c388 (diff)
downloadFirmament-60994a08677d864f79de58d8912b02d2d7077289.tar.gz
Firmament-60994a08677d864f79de58d8912b02d2d7077289.tar.bz2
Firmament-60994a08677d864f79de58d8912b02d2d7077289.zip
Add some carnival features
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/util')
-rw-r--r--src/main/kotlin/moe/nea/firmament/util/LegacyFormattingCode.kt3
-rw-r--r--src/main/kotlin/moe/nea/firmament/util/SkyblockId.kt29
-rw-r--r--src/main/kotlin/moe/nea/firmament/util/item/SkullItemData.kt3
3 files changed, 28 insertions, 7 deletions
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 <nea@nea.moe>
+ * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
*
* 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")