aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/util/item
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-03-01 21:31:48 +0100
committerLinnea Gräf <nea@nea.moe>2024-03-02 19:43:00 +0100
commit3bfec3033e9d905514d5c1c6c62953c2a1646af0 (patch)
treeafee0b3c20d0bdef9780e5fddb368c9d58fb3c70 /src/main/kotlin/moe/nea/firmament/util/item
parentf28dee0ef3a0dd4a0819a3d3a1c800a83a0f07f5 (diff)
downloadfirmament-3bfec3033e9d905514d5c1c6c62953c2a1646af0.tar.gz
firmament-3bfec3033e9d905514d5c1c6c62953c2a1646af0.tar.bz2
firmament-3bfec3033e9d905514d5c1c6c62953c2a1646af0.zip
Add mob drop viewer to item list
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/util/item')
-rw-r--r--src/main/kotlin/moe/nea/firmament/util/item/SkullItemData.kt40
1 files changed, 39 insertions, 1 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 4b72c5e..a061ee4 100644
--- a/src/main/kotlin/moe/nea/firmament/util/item/SkullItemData.kt
+++ b/src/main/kotlin/moe/nea/firmament/util/item/SkullItemData.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
*/
@@ -18,8 +19,13 @@ import kotlinx.serialization.Serializable
import kotlinx.serialization.UseSerializers
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
-import net.minecraft.client.texture.PlayerSkinProvider
+import net.minecraft.block.entity.SkullBlockEntity
+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
@@ -46,6 +52,38 @@ fun GameProfile.setTextures(textures: MinecraftTexturesPayloadKt) {
}
private val propertyTextures = "textures"
+fun String.padBase64(): String {
+ return this + "=".repeat((4 - (this.length % 4)) % 4)
+}
+
+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
+ )
+}
+
+val zeroUUID = UUID.fromString("d3cb85e2-3075-48a1-b213-a9bfb62360c1")
+fun ItemStack.setSkullOwner(uuid: UUID, url: String) {
+ assert(this.item == Items.PLAYER_HEAD)
+ val gameProfile = GameProfile(uuid, "LameGuy123")
+ gameProfile.setTextures(
+ MinecraftTexturesPayloadKt(
+ mapOf(MinecraftProfileTexture.Type.SKIN to MinecraftProfileTextureKt(url))
+ )
+ )
+ val nbt: NbtCompound = this.orCreateNbt
+ nbt[SkullBlockEntity.SKULL_OWNER_KEY] = NbtHelper.writeGameProfile(
+ NbtCompound(),
+ gameProfile
+ )
+
+}
+
fun decodeProfileTextureProperty(property: Property): MinecraftTexturesPayloadKt? {
assertTrueOr(property.name == propertyTextures) { return null }