From a44214f2d62ef45b44f6da057be37a276ccdce76 Mon Sep 17 00:00:00 2001 From: Brandon Date: Wed, 27 Sep 2023 08:18:20 -0300 Subject: Add actual NBT data to /shcopyitem command (#509) Add actual NBT data to /shcopyitem command #509 --- .../skyhanni/test/command/CopyItemCommand.kt | 32 ++++++++++++++-------- .../skyhanni/utils/SkyBlockItemModifierUtils.kt | 2 ++ 2 files changed, 23 insertions(+), 11 deletions(-) (limited to 'src/main/java/at') 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 4fc82bbc3..cb7031f4b 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/command/CopyItemCommand.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/command/CopyItemCommand.kt @@ -1,11 +1,13 @@ package at.hannibal2.skyhanni.test.command -import at.hannibal2.skyhanni.test.SkyHanniDebugsAndTests import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName_old import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.OSUtils +import net.minecraft.item.Item +import net.minecraft.nbt.NBTTagCompound +import net.minecraft.util.ResourceLocation object CopyItemCommand { @@ -17,6 +19,7 @@ object CopyItemCommand { resultList.add("display name: '" + itemStack.displayName.toString() + "'") val itemID = itemStack.getInternalName_old() resultList.add("internalName: '$itemID'") + resultList.add("minecraft id: '" + (Item.itemRegistry.getNameForObject(itemStack.item) as ResourceLocation) + "'") resultList.add("") for (line in itemStack.getLore()) { resultList.add("'$line'") @@ -25,22 +28,29 @@ object CopyItemCommand { resultList.add("getTagCompound") if (itemStack.hasTagCompound()) { val tagCompound = itemStack.tagCompound - for (s in tagCompound.keySet) { - resultList.add(" '$s'") - } - if (tagCompound.hasKey("ExtraAttributes")) { - resultList.add("") - resultList.add("ExtraAttributes") - val extraAttributes = tagCompound.getCompoundTag("ExtraAttributes") - SkyHanniDebugsAndTests.runn(extraAttributes, " . ") - } + recurseTag(tagCompound, " ", resultList) } val string = resultList.joinToString("\n") OSUtils.copyToClipboard(string) - LorenzUtils.chat("§e[SkyHanni] item info copied into the clipboard!") + LorenzUtils.chat("§e[SkyHanni] Item info copied into the clipboard!") } catch (_: Throwable) { LorenzUtils.chat("§c[SkyHanni] No item in hand!") } } + + private fun recurseTag(compound: NBTTagCompound, text: String, list: MutableList) { + for (s in compound.keySet) { + val tag = compound.getTag(s) + + if (tag !is NBTTagCompound) { + list.add("${text}${s}: $tag") + } else { + val element = compound.getCompoundTag(s) + list.add("${text}${s}:") + recurseTag(element, "$text ", list) + } + } + } + } \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt index 3d33acf3c..4be6dd30a 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt @@ -178,6 +178,8 @@ object SkyBlockItemModifierUtils { fun ItemStack.getItemUuid() = getAttributeString("uuid") + fun ItemStack.getItemId() = getAttributeString("id") + fun ItemStack.getGemstones() = getExtraAttributes()?.let { val list = mutableListOf() for (attributes in it.keySet) { -- cgit