aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/util/item
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-09-09 04:50:29 +0200
committernea <nea@nea.moe>2023-09-09 04:50:29 +0200
commitc82c051704424763c20742b616228cfe636b9f65 (patch)
treed9400135aebefe40671d990218415443b842d033 /src/main/kotlin/moe/nea/firmament/util/item
parentdd974fcb79014452e6109dbeb008d5413819b73d (diff)
downloadfirmament-c82c051704424763c20742b616228cfe636b9f65.tar.gz
firmament-c82c051704424763c20742b616228cfe636b9f65.tar.bz2
firmament-c82c051704424763c20742b616228cfe636b9f65.zip
Add custom textures to placed skulls
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/util/item')
-rw-r--r--src/main/kotlin/moe/nea/firmament/util/item/SkullItemData.kt23
1 files changed, 19 insertions, 4 deletions
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 5b440b1..4d4d386 100644
--- a/src/main/kotlin/moe/nea/firmament/util/item/SkullItemData.kt
+++ b/src/main/kotlin/moe/nea/firmament/util/item/SkullItemData.kt
@@ -11,14 +11,16 @@ package moe.nea.firmament.util.item
import com.mojang.authlib.GameProfile
import com.mojang.authlib.minecraft.MinecraftProfileTexture
import com.mojang.authlib.properties.Property
-import java.util.UUID
+import java.util.*
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.client.texture.PlayerSkinProvider
import moe.nea.firmament.Firmament
+import moe.nea.firmament.util.assertTrueOr
import moe.nea.firmament.util.json.DashlessUUIDSerializer
import moe.nea.firmament.util.json.InstantAsLongSerializer
@@ -30,9 +32,9 @@ data class MinecraftProfileTextureKt(
@Serializable
data class MinecraftTexturesPayloadKt(
- val textures: Map<MinecraftProfileTexture.Type, MinecraftProfileTextureKt>,
- val profileId: UUID,
- val profileName: String,
+ val textures: Map<MinecraftProfileTexture.Type, MinecraftProfileTextureKt> = mapOf(),
+ val profileId: UUID? = null,
+ val profileName: String? = null,
val isPublic: Boolean = true,
val timestamp: Instant = Clock.System.now(),
)
@@ -43,3 +45,16 @@ fun GameProfile.setTextures(textures: MinecraftTexturesPayloadKt) {
properties.put(PlayerSkinProvider.TEXTURES, Property(PlayerSkinProvider.TEXTURES, encoded))
}
+fun decodeProfileTextureProperty(property: Property): MinecraftTexturesPayloadKt? {
+ assertTrueOr(property.name == PlayerSkinProvider.TEXTURES) { return null }
+ try {
+ val json = java.util.Base64.getDecoder().decode(property.value).decodeToString()
+ return Firmament.json.decodeFromString<MinecraftTexturesPayloadKt>(json)
+ } catch (e: Exception) {
+ // Malformed profile data
+ if (Firmament.DEBUG)
+ e.printStackTrace()
+ return null
+ }
+}
+