Add mob drop viewer to item list
This commit is contained in:
@@ -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) {
|
||||
|
||||
25
src/main/kotlin/moe/nea/firmament/util/LoadResource.kt
Normal file
25
src/main/kotlin/moe/nea/firmament/util/LoadResource.kt
Normal file
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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 }
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
Reference in New Issue
Block a user