aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/util
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-06-11 02:43:14 +0200
committernea <nea@nea.moe>2023-06-11 02:43:14 +0200
commita36c8f1c0eae969dcee8cf690f12d9121350212d (patch)
treeea93f19bf5f77f8b5e42a7b56162d9b6492b7fed /src/main/kotlin/moe/nea/firmament/util
parent040f7c7275568d783bfa5e4ed20412f72d126549 (diff)
downloadFirmament-a36c8f1c0eae969dcee8cf690f12d9121350212d.tar.gz
Firmament-a36c8f1c0eae969dcee8cf690f12d9121350212d.tar.bz2
Firmament-a36c8f1c0eae969dcee8cf690f12d9121350212d.zip
Add collection info to skill page
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/util')
-rw-r--r--src/main/kotlin/moe/nea/firmament/util/ItemUtil.kt10
-rw-r--r--src/main/kotlin/moe/nea/firmament/util/MC.kt1
-rw-r--r--src/main/kotlin/moe/nea/firmament/util/colorconversion.kt5
3 files changed, 16 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/util/ItemUtil.kt b/src/main/kotlin/moe/nea/firmament/util/ItemUtil.kt
index 25fb7d3..78627cd 100644
--- a/src/main/kotlin/moe/nea/firmament/util/ItemUtil.kt
+++ b/src/main/kotlin/moe/nea/firmament/util/ItemUtil.kt
@@ -33,6 +33,16 @@ fun ItemStack.appendLore(args: List<Text>) {
}
}
+fun ItemStack.modifyLore(update: (List<Text>) -> List<Text>) {
+ val compoundTag = getOrCreateSubNbt("display")
+ val loreList = compoundTag.getOrCreateList("Lore", NbtString.STRING_TYPE)
+ val parsed = loreList.map { Text.Serializer.fromJson(it.asString())!! }
+ val updated = update(parsed)
+ loreList.clear()
+ loreList.addAll(updated.map { NbtString.of(Text.Serializer.toJson(it)) })
+}
+
+
fun NbtCompound.getOrCreateList(label: String, tag: Byte): NbtList = getList(label, tag.toInt()).also {
put(label, it)
}
diff --git a/src/main/kotlin/moe/nea/firmament/util/MC.kt b/src/main/kotlin/moe/nea/firmament/util/MC.kt
index 53bad8b..e9ab6c9 100644
--- a/src/main/kotlin/moe/nea/firmament/util/MC.kt
+++ b/src/main/kotlin/moe/nea/firmament/util/MC.kt
@@ -24,6 +24,7 @@ import net.minecraft.client.gui.screen.ingame.HandledScreen
import net.minecraft.util.math.BlockPos
object MC {
+ inline val font get() = MinecraftClient.getInstance().textRenderer
inline val soundManager get() = MinecraftClient.getInstance().soundManager
inline val player get() = MinecraftClient.getInstance().player
inline val world get() = MinecraftClient.getInstance().world
diff --git a/src/main/kotlin/moe/nea/firmament/util/colorconversion.kt b/src/main/kotlin/moe/nea/firmament/util/colorconversion.kt
index c19eefa..5da9f22 100644
--- a/src/main/kotlin/moe/nea/firmament/util/colorconversion.kt
+++ b/src/main/kotlin/moe/nea/firmament/util/colorconversion.kt
@@ -1,6 +1,11 @@
package moe.nea.firmament.util
+import net.minecraft.text.TextColor
import net.minecraft.util.DyeColor
fun DyeColor.toShedaniel(): me.shedaniel.math.Color =
me.shedaniel.math.Color.ofOpaque(this.signColor)
+
+fun DyeColor.toTextColor(): TextColor =
+ TextColor.fromRgb(this.signColor)
+