blob: 6a583b1e3348b826a2e226c366f8d26a1691e6d6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
package at.hannibal2.skyhanni.test.command
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
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() {
val itemStack = InventoryUtils.getItemInHand()
if (itemStack == null) {
LorenzUtils.userError("No item in hand!")
return
}
copyItemToClipboard(itemStack)
}
private fun recurseTag(compound: NBTTagCompound, text: String, list: MutableList<String>) {
for (s in compound.keySet) {
if (s == "Lore") continue
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)
}
}
}
fun copyItemToClipboard(itemStack: ItemStack) {
val resultList = mutableListOf<String>()
resultList.add(itemStack.getInternalName().toString())
resultList.add("display name: '" + itemStack.displayName.toString() + "'")
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("Item info copied into the clipboard!")
}
}
|