aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/features/debug
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-09-09 03:37:29 +0200
committernea <nea@nea.moe>2023-09-09 03:37:29 +0200
commit255e4f5899642e099e7ec7b1a7fe1e0c32ebbc20 (patch)
tree11016247a0403d2c1e4bd0de62d3fdf913709eb0 /src/main/kotlin/moe/nea/firmament/features/debug
parente0f784a1b209e5ec88a07a71e9336790aac1fc7d (diff)
downloadfirmament-255e4f5899642e099e7ec7b1a7fe1e0c32ebbc20.tar.gz
firmament-255e4f5899642e099e7ec7b1a7fe1e0c32ebbc20.tar.bz2
firmament-255e4f5899642e099e7ec7b1a7fe1e0c32ebbc20.zip
Add tools for copying id, texture id and nbt data
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/features/debug')
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/debug/DeveloperFeatures.kt2
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/debug/PowerUserTools.kt94
2 files changed, 95 insertions, 1 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/features/debug/DeveloperFeatures.kt b/src/main/kotlin/moe/nea/firmament/features/debug/DeveloperFeatures.kt
index 20d1358..e045fa8 100644
--- a/src/main/kotlin/moe/nea/firmament/features/debug/DeveloperFeatures.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/debug/DeveloperFeatures.kt
@@ -68,7 +68,7 @@ object DeveloperFeatures : FirmamentFeature {
HandledScreenKeyPressedEvent.subscribe {
if (it.matches(IKeyBinding.ofKeyCode(GLFW.GLFW_KEY_K))) {
it.screen as AccessorHandledScreen
- val focussedSlot = it.screen.focusedSlot_NEU ?: return@subscribe
+ val focussedSlot = it.screen.focusedSlot_Firmament ?: return@subscribe
val item = focussedSlot.stack ?: return@subscribe
val ident = item.skyBlockId?.identifier.toString()
MinecraftClient.getInstance().inGameHud.chatHud.addMessage(
diff --git a/src/main/kotlin/moe/nea/firmament/features/debug/PowerUserTools.kt b/src/main/kotlin/moe/nea/firmament/features/debug/PowerUserTools.kt
new file mode 100644
index 0000000..398042d
--- /dev/null
+++ b/src/main/kotlin/moe/nea/firmament/features/debug/PowerUserTools.kt
@@ -0,0 +1,94 @@
+/*
+ * SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+package moe.nea.firmament.features.debug
+
+import net.minecraft.item.ItemStack
+import net.minecraft.text.Text
+import moe.nea.firmament.events.CustomItemModelEvent
+import moe.nea.firmament.events.HandledScreenKeyPressedEvent
+import moe.nea.firmament.events.ItemTooltipEvent
+import moe.nea.firmament.events.ScreenOpenEvent
+import moe.nea.firmament.events.TickEvent
+import moe.nea.firmament.features.FirmamentFeature
+import moe.nea.firmament.gui.config.ManagedConfig
+import moe.nea.firmament.mixins.accessor.AccessorHandledScreen
+import moe.nea.firmament.util.ClipboardUtils
+import moe.nea.firmament.util.skyBlockId
+
+object PowerUserTools : FirmamentFeature {
+ override val identifier: String
+ get() = "power-user"
+
+ object TConfig : ManagedConfig(identifier) {
+ val showItemIds by toggle("show-item-id") { false }
+ val copyItemId by keyBindingWithDefaultUnbound("copy-item-id")
+ val copyTexturePackId by keyBindingWithDefaultUnbound("copy-texture-pack-id")
+ val copyNbtData by keyBindingWithDefaultUnbound("copy-nbt-data")
+ }
+
+ override val config
+ get() = TConfig
+
+ var lastCopiedStack: Pair<ItemStack, Text>? = null
+ set(value) {
+ field = value
+ if (value != null)
+ lastCopiedStackViewTime = true
+ }
+ var lastCopiedStackViewTime = false
+
+ override fun onLoad() {
+ ItemTooltipEvent.subscribe {
+ if (TConfig.showItemIds) {
+ val id = it.stack.skyBlockId ?: return@subscribe
+ it.lines.add(Text.translatable("firmament.tooltip.skyblockid", id.neuItem))
+ }
+ val (item, text) = lastCopiedStack ?: return@subscribe
+ if (item != it.stack) {
+ lastCopiedStack = null
+ return@subscribe
+ }
+ lastCopiedStackViewTime = true
+ it.lines.add(text)
+ }
+ TickEvent.subscribe {
+ if (!lastCopiedStackViewTime)
+ lastCopiedStack = null
+ lastCopiedStackViewTime = false
+ }
+ ScreenOpenEvent.subscribe {
+ lastCopiedStack = null
+ }
+ HandledScreenKeyPressedEvent.subscribe {
+ if (it.screen !is AccessorHandledScreen) return@subscribe
+ val item = it.screen.focusedSlot_Firmament?.stack ?: return@subscribe
+ if (it.matches(TConfig.copyItemId)) {
+ val sbId = item.skyBlockId
+ if (sbId == null) {
+ lastCopiedStack = Pair(item, Text.translatable("firmament.tooltip.copied.skyblockid.fail"))
+ return@subscribe
+ }
+ ClipboardUtils.setTextContent(sbId.neuItem)
+ lastCopiedStack = Pair(item, Text.translatable("firmament.tooltip.copied.skyblockid", sbId.neuItem))
+ } else if (it.matches(TConfig.copyTexturePackId)) {
+ val model = CustomItemModelEvent.getModelIdentifier(item)
+ if (model == null) {
+ lastCopiedStack = Pair(item, Text.translatable("firmament.tooltip.copied.modelid.fail"))
+ return@subscribe
+ }
+ ClipboardUtils.setTextContent(model.toString())
+ lastCopiedStack = Pair(item, Text.translatable("firmament.tooltip.copied.modelid", model.toString()))
+ } else if (it.matches(TConfig.copyNbtData)) {
+ val nbt = item.orCreateNbt.toString()
+ ClipboardUtils.setTextContent(nbt)
+ lastCopiedStack = Pair(item, Text.translatable("firmament.tooltip.copied.nbt"))
+ }
+ }
+ }
+
+
+}