aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/util
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
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')
-rw-r--r--src/main/kotlin/moe/nea/firmament/util/ItemUtil.kt2
-rw-r--r--src/main/kotlin/moe/nea/firmament/util/LoadResource.kt25
-rw-r--r--src/main/kotlin/moe/nea/firmament/util/assertions.kt1
-rw-r--r--src/main/kotlin/moe/nea/firmament/util/item/SkullItemData.kt40
-rw-r--r--src/main/kotlin/moe/nea/firmament/util/render/TranslatedScissors.kt27
5 files changed, 94 insertions, 1 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/util/ItemUtil.kt b/src/main/kotlin/moe/nea/firmament/util/ItemUtil.kt
index 4f8c90c..5a7a116 100644
--- a/src/main/kotlin/moe/nea/firmament/util/ItemUtil.kt
+++ b/src/main/kotlin/moe/nea/firmament/util/ItemUtil.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
*/
@@ -14,6 +15,7 @@ import net.minecraft.text.Text
fun ItemStack.appendLore(args: List<Text>) {
+ if (args.isEmpty()) return
val compoundTag = getOrCreateSubNbt("display")
val loreList = compoundTag.getOrCreateList("Lore", NbtString.STRING_TYPE)
for (arg in args) {
diff --git a/src/main/kotlin/moe/nea/firmament/util/LoadResource.kt b/src/main/kotlin/moe/nea/firmament/util/LoadResource.kt
new file mode 100644
index 0000000..5a8bfbf
--- /dev/null
+++ b/src/main/kotlin/moe/nea/firmament/util/LoadResource.kt
@@ -0,0 +1,25 @@
+/*
+ * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+package moe.nea.firmament.util
+
+import java.io.InputStream
+import kotlin.io.path.inputStream
+import kotlin.jvm.optionals.getOrNull
+import net.minecraft.util.Identifier
+import moe.nea.firmament.repo.RepoDownloadManager
+
+
+fun Identifier.openFirmamentResource(): InputStream {
+ val resource = MC.resourceManager.getResource(this).getOrNull()
+ if (resource == null) {
+ if (namespace == "neurepo")
+ return RepoDownloadManager.repoSavedLocation.resolve(path).inputStream()
+ error("Could not read resource $this")
+ }
+ return resource.inputStream
+}
+
diff --git a/src/main/kotlin/moe/nea/firmament/util/assertions.kt b/src/main/kotlin/moe/nea/firmament/util/assertions.kt
index 5505422..7f06955 100644
--- a/src/main/kotlin/moe/nea/firmament/util/assertions.kt
+++ b/src/main/kotlin/moe/nea/firmament/util/assertions.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
*/
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 }
diff --git a/src/main/kotlin/moe/nea/firmament/util/render/TranslatedScissors.kt b/src/main/kotlin/moe/nea/firmament/util/render/TranslatedScissors.kt
new file mode 100644
index 0000000..8f80f1b
--- /dev/null
+++ b/src/main/kotlin/moe/nea/firmament/util/render/TranslatedScissors.kt
@@ -0,0 +1,27 @@
+/*
+ * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+package moe.nea.firmament.util.render
+
+import org.joml.Vector4f
+import net.minecraft.client.gui.DrawContext
+
+fun DrawContext.enableScissorWithTranslation(x1: Float, y1: Float, x2: Float, y2: Float) {
+ val pMat = matrices.peek().positionMatrix
+ val target = Vector4f()
+
+ target.set(x1, y1, 0f, 1f)
+ target.mul(pMat)
+ val scissorX1 = target.x
+ val scissorY1 = target.y
+
+ target.set(x2, y2, 0f, 1f)
+ target.mul(pMat)
+ val scissorX2 = target.x
+ val scissorY2 = target.y
+
+ enableScissor(scissorX1.toInt(), scissorY1.toInt(), scissorX2.toInt(), scissorY2.toInt())
+}