Skip to content

Commit

Permalink
impl TestCopyChestData
Browse files Browse the repository at this point in the history
Signed-off-by: Erymanthus[#5074] | (u/)RayDeeUx <[email protected]>
  • Loading branch information
RayDeeUx committed Jan 17, 2024
1 parent 69cfa25 commit ab90a3c
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ import at.hannibal2.skyhanni.test.ShowItemUuid
import at.hannibal2.skyhanni.test.SkyHanniDebugsAndTests
import at.hannibal2.skyhanni.test.TestBingo
import at.hannibal2.skyhanni.test.TestCopyBestiaryValues
import at.hannibal2.skyhanni.test.TestCopyChestData
import at.hannibal2.skyhanni.test.TestCopyRngMeterValues
import at.hannibal2.skyhanni.test.TestExportTools
import at.hannibal2.skyhanni.test.TestShowSlotNumber
Expand Down Expand Up @@ -387,6 +388,7 @@ class SkyHanniMod {
loadModule(EntityData())
loadModule(EntityMovementData())
loadModule(TestExportTools)
loadModule(TestCopyChestData)
loadModule(ItemClickData())
// loadModule(Year300RaffleEvent)
loadModule(MinecraftData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,6 @@ public class DebugConfig {
@ConfigEditorBoolean
public boolean showItemUuid = false;

@Expose
@ConfigOption(name = "Copy Item Data", desc = "Copies item NBT data on key press in a GUI to clipboard.")
@ConfigEditorKeybind(defaultKey = Keyboard.KEY_NONE)
public int copyItemData = Keyboard.KEY_NONE;

@Expose
@ConfigOption(name = "Copy Compressed Item Data", desc = "Copies compressed item NBT data on key press in a GUI to clipboard.")
@ConfigEditorKeybind(defaultKey = Keyboard.KEY_NONE)
public int copyItemDataCompressed = Keyboard.KEY_NONE;

@Expose
@ConfigOption(name = "Copy RNG Meter", desc = "Copies internal names and maxed XP needed from RNG meter inventories as json to clipboard.")
@ConfigEditorBoolean
Expand Down Expand Up @@ -96,4 +86,44 @@ public class DebugConfig {
@ConfigOption(name = "Bypass Advanced Tab List", desc = "The Advaced Player Tab list is disabled whie pressing this hotkey.")
@ConfigEditorKeybind(defaultKey = Keyboard.KEY_NONE)
public int bypassAdvancedPlayerTabList = Keyboard.KEY_NONE;

@Expose
@ConfigOption(name = "Copy Item Data", desc = "Copies item NBT data on key press in a GUI to clipboard.")
@ConfigEditorKeybind(defaultKey = Keyboard.KEY_NONE)
public int copyItemData = Keyboard.KEY_NONE;

@Expose
@ConfigOption(name = "Copy Compressed Item Data", desc = "Copies compressed item NBT data on key press in a GUI to clipboard.")
@ConfigEditorKeybind(defaultKey = Keyboard.KEY_NONE)
public int copyItemDataCompressed = Keyboard.KEY_NONE;

@Expose
@ConfigOption(name = "Copy Chest Name", desc = "Copies the chest name on key press in a GUI to clipboard.")
@ConfigEditorKeybind(defaultKey = Keyboard.KEY_NONE)
public int copyChestName = Keyboard.KEY_NONE;

@Expose
@ConfigOption(name = "Copy Chest Data", desc = "Copies everything about the currently open container.")
@ConfigEditorKeybind(defaultKey = Keyboard.KEY_NONE)
public int copyEntireChest = Keyboard.KEY_NONE;

@Expose
@ConfigOption(name = "Copy Inventory Data", desc = "Copies everything about the player's inventory.")
@ConfigEditorKeybind(defaultKey = Keyboard.KEY_NONE)
public int copyPlayerInventory = Keyboard.KEY_NONE;

@Expose
@ConfigOption(name = "Include Unnamed Items", desc = "When copying chest or player inventory data, include items with blank/empty names.")
@ConfigEditorBoolean
public boolean includeUnnamedItems = false;

@Expose
@ConfigOption(name = "Include Null Slots", desc = "When copying chest or player inventory data, include empty item slots.")
@ConfigEditorBoolean
public boolean includeNullSlots = false;

@Expose
@ConfigOption(name = "Include Armor", desc = "When copying player inventory data, include items in your armor slots.")
@ConfigEditorBoolean
public boolean includeArmor = false;
}
80 changes: 80 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/test/TestCopyChestData.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
@file:Suppress("SENSELESS_COMPARISON") // intellij does a little trolling and assumes all ItemStacks will never be null. this suppresses such warnings.
package at.hannibal2.skyhanni.test

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.test.command.CopyItemCommand.grabItemData
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.OSUtils
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.inventory.GuiChest
import net.minecraft.client.gui.inventory.GuiContainer
import net.minecraft.inventory.Slot
import net.minecraft.item.ItemStack
import net.minecraftforge.client.event.GuiScreenEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

object TestCopyChestData {
private val config get() = SkyHanniMod.feature.dev.debug
private val mc = Minecraft.getMinecraft()
@SubscribeEvent
fun onKeybind(event: GuiScreenEvent.KeyboardInputEvent.Post) {
if (!LorenzUtils.inSkyBlock) return
if (!config.copyPlayerInventory.isKeyHeld() && !config.copyEntireChest.isKeyHeld() && !config.copyChestName.isKeyHeld()) return
if (event.gui !is GuiContainer) return
if (config.copyEntireChest.isKeyHeld()) {
copySlotsData(chest = (event.gui as GuiChest).inventorySlots.inventorySlots)
return
} else if (config.copyPlayerInventory.isKeyHeld()) {
copySlotsData(inventory = if (config.includeArmor) mc.thePlayer.inventory.mainInventory + mc.thePlayer.inventory.armorInventory else mc.thePlayer.inventory.mainInventory)
return
} else if (InventoryUtils.openInventoryName().isNotEmpty()) {
OSUtils.copyToClipboard(InventoryUtils.openInventoryName())
LorenzUtils.chat("Chest name copied to clipboard.")
return
}
}
private fun copySlotsData(chest: List<Slot> = emptyList(), inventory: Array<ItemStack> = emptyArray()) {
val copyList = mutableListOf<String>("relevant config:", "includeNullSlots: ${config.includeNullSlots}", "includeUnnamedItems: ${config.includeUnnamedItems}", "includeArmor: ${config.includeArmor}", "")
val inventoryType: String = if (chest.isNotEmpty()) "Chest" else if (inventory.isNotEmpty()) "Inventory" else "Unknown"
if (chest.isNotEmpty()) {
copyList.addAll(listOf<String>("chest name: '${InventoryUtils.openInventoryName()}'", ""))
for (slot in chest) {
val stack = slot.stack
if (stack == null) {
if (config.includeNullSlots) copyList.addAll(listOf("(there is nothing inside slot ${slot.slotIndex}; it is null)", "", ""))
continue
}
if (stack in mc.thePlayer.inventory.mainInventory) break
if ((stack.displayName.isNotEmpty() && stack.displayName.isNotBlank()) || config.includeUnnamedItems) {
copyList.add("slot index: '${slot.slotIndex}'")
copyList.addAll(stack.getStackInfo())
}
}
} else if (inventory.isNotEmpty()) {
copyList.addAll(listOf<String>("your inventory is below.", "", "your hotbar:", ""))
for ((i, stack) in inventory.withIndex()) {
if (i - 1 == 8 && stack != null) copyList.addAll(listOf("note: hotbar ends here", "the rest of your inventory:", "", ""))
if (i - 1 == 35 && config.includeArmor && stack != null) copyList.addAll(listOf("note: the rest of your inventory data ends here", "your armor:", "", ""))
if (stack == null) {
if (config.includeNullSlots) copyList.addAll(listOf("(there is nothing inside slot $i; it is null)", "", ""))
continue
}
if ((stack.displayName.isNotEmpty() && stack.displayName.isNotBlank()) || config.includeUnnamedItems) {
copyList.add("slot index: '$i'")
copyList.addAll(stack.getStackInfo())
}
}
}
OSUtils.copyToClipboard(copyList.joinToString("\n"))
LorenzUtils.chat("$inventoryType data copied into the clipboard! §lMake sure to save it into a .txt file; these tend to get quite long.")
}
private fun ItemStack.getStackInfo(): List<String> {
val returnList = mutableListOf<String>()
returnList.addAll(listOf<String>("stack size: '${this.stackSize}'", "is stackable: '${this.isStackable}'", "item data (begins on next line):"))
returnList.addAll(grabItemData(this))
returnList.addAll(listOf<String>("", ""))
return returnList
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ object CopyItemCommand {
}

fun copyItemToClipboard(itemStack: ItemStack) {
val resultList = grabItemData(itemStack)

val string = resultList.joinToString("\n")
OSUtils.copyToClipboard(string)
LorenzUtils.chat("Item info copied into the clipboard!")
}

fun grabItemData(itemStack: ItemStack): List<String> {
val resultList = mutableListOf<String>()
resultList.add(itemStack.getInternalName().toString())
resultList.add("display name: '" + itemStack.displayName.toString() + "'")
Expand All @@ -51,8 +59,6 @@ object CopyItemCommand {
recurseTag(tagCompound, " ", resultList)
}

val string = resultList.joinToString("\n")
OSUtils.copyToClipboard(string)
LorenzUtils.chat("Item info copied into the clipboard!")
return resultList
}
}

0 comments on commit ab90a3c

Please sign in to comment.