diff options
author | Walker Selby <git@walkerselby.com> | 2023-10-16 11:10:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-16 12:10:25 +0200 |
commit | 560cdada4b3577fb83c39c5cac62409093055103 (patch) | |
tree | 1acb9584b486e1d1c71f02ccc3314f7fd9da72a4 | |
parent | 94e6c479359c68d7dbf9b657aad86ab3fa12e525 (diff) | |
download | skyhanni-560cdada4b3577fb83c39c5cac62409093055103.tar.gz skyhanni-560cdada4b3577fb83c39c5cac62409093055103.tar.bz2 skyhanni-560cdada4b3577fb83c39c5cac62409093055103.zip |
Add NBT Copy Keybind (#562)
created more useful copy item data keybind #562
3 files changed, 41 insertions, 25 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/DevConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/DevConfig.java index edf6391b4..c1456d770 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/DevConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/DevConfig.java @@ -71,7 +71,12 @@ public class DevConfig { public boolean showItemUuid = false; @Expose - @ConfigOption(name = "Copy NBT Data", desc = "Copies compressed NBT data on key press in a GUI") + @ConfigOption(name = "Copy NBT Data", desc = "Copies NBT data on key press in a GUI") + @ConfigEditorKeybind(defaultKey = Keyboard.KEY_NONE) + public int copyNBTData = Keyboard.KEY_NONE; + + @Expose + @ConfigOption(name = "Copy Compressed NBT Data", desc = "Copies compressed NBT data on key press in a GUI") @ConfigEditorKeybind(defaultKey = Keyboard.KEY_NONE) public int copyNBTDataCompressed = Keyboard.KEY_NONE; @@ -81,7 +86,7 @@ public class DevConfig { public boolean copyRngMeter = false; @Expose - @ConfigOption(name = "Copy Bestiary Data", desc = "Copies the bestiary data from the inventory as json to clipboard.") + @ConfigOption(name = "Copy Bestiary Data", desc = "Copies the bestiary data from the inventory as json to clipboard.") @ConfigEditorBoolean public boolean copyBestiaryData = false; diff --git a/src/main/java/at/hannibal2/skyhanni/test/TestExportTools.kt b/src/main/java/at/hannibal2/skyhanni/test/TestExportTools.kt index 95399fb1e..3f14885c3 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/TestExportTools.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/TestExportTools.kt @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.test import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.test.command.CopyItemCommand.copyItemToClipboard import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator import at.hannibal2.skyhanni.utils.ItemStackTypeAdapterFactory import at.hannibal2.skyhanni.utils.KSerializable @@ -21,6 +22,8 @@ import java.io.InputStreamReader import java.io.Reader object TestExportTools { + private val config get() = SkyHanniMod.feature.dev.debug + val gson = GsonBuilder() .registerTypeAdapterFactory(KotlinTypeAdapterFactory()) .registerTypeAdapter(NBTTagCompound::class.java, NBTTypeAdapter) @@ -49,13 +52,17 @@ object TestExportTools { @SubscribeEvent fun onKeybind(event: GuiScreenEvent.KeyboardInputEvent.Post) { - if (!SkyHanniMod.feature.dev.debug.copyNBTDataCompressed.isKeyHeld()) return + if (!config.copyNBTDataCompressed.isKeyHeld() && !config.copyNBTData.isKeyHeld()) return val gui = event.gui as? GuiContainer ?: return val focussedSlot = gui.slotUnderMouse ?: return val stack = focussedSlot.stack ?: return + if (config.copyNBTData.isKeyHeld()) { + copyItemToClipboard(stack) + return + } val json = toJson(Item, stack) OSUtils.copyToClipboard(json) - LorenzUtils.chat("Copied test importable to clipbooard") + LorenzUtils.chat("Copied test importable to clipboard") } diff --git a/src/main/java/at/hannibal2/skyhanni/test/command/CopyItemCommand.kt b/src/main/java/at/hannibal2/skyhanni/test/command/CopyItemCommand.kt index 06496036d..f3d0d80ef 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/command/CopyItemCommand.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/command/CopyItemCommand.kt @@ -6,33 +6,15 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.OSUtils import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getMinecraftId +import net.minecraft.item.ItemStack import net.minecraft.nbt.NBTTagCompound object CopyItemCommand { fun command() { try { - val resultList = mutableListOf<String>() - val itemStack = InventoryUtils.getItemInHand() ?: return - resultList.add("ITEM LORE") - resultList.add("display name: '" + itemStack.displayName.toString() + "'") - val itemID = itemStack.getInternalName_old() - resultList.add("internalName: '$itemID'") - resultList.add("minecraft id: '" + itemStack.getMinecraftId() + "'") - resultList.add("lore:") - for (line in itemStack.getLore()) { - resultList.add(" '$line'") - } - resultList.add("") - resultList.add("getTagCompound") - if (itemStack.hasTagCompound()) { - val tagCompound = itemStack.tagCompound - recurseTag(tagCompound, " ", resultList) - } - - val string = resultList.joinToString("\n") - OSUtils.copyToClipboard(string) - LorenzUtils.chat("§e[SkyHanni] Item info copied into the clipboard!") + val itemStack = InventoryUtils.getItemInHand() ?: throw Exception() + copyItemToClipboard(itemStack) } catch (_: Throwable) { LorenzUtils.chat("§c[SkyHanni] No item in hand!") } @@ -53,4 +35,26 @@ object CopyItemCommand { } } + fun copyItemToClipboard(itemStack: ItemStack){ + val resultList = mutableListOf<String>() + resultList.add("ITEM LORE") + resultList.add("display name: '" + itemStack.displayName.toString() + "'") + val itemID = itemStack.getInternalName_old() + resultList.add("internalName: '$itemID'") + resultList.add("minecraft id: '" + itemStack.getMinecraftId() + "'") + resultList.add("lore:") + for (line in itemStack.getLore()) { + resultList.add(" '$line'") + } + resultList.add("") + resultList.add("getTagCompound") + if (itemStack.hasTagCompound()) { + val tagCompound = itemStack.tagCompound + recurseTag(tagCompound, " ", resultList) + } + + val string = resultList.joinToString("\n") + OSUtils.copyToClipboard(string) + LorenzUtils.chat("§e[SkyHanni] Item info copied into the clipboard!") + } }
\ No newline at end of file |