diff options
author | Linnea Gräf <nea@nea.moe> | 2024-10-05 12:06:23 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-10-05 12:06:23 +0200 |
commit | 977620f1b5218cc8a041742f970974a4bfff29cc (patch) | |
tree | 214dad2ae3f9e59304dc20e5891278d01d301629 /src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt | |
parent | c689c21f3757faaa43afa2402e9e49a06c1e894f (diff) | |
download | money-ledger-977620f1b5218cc8a041742f970974a4bfff29cc.tar.gz money-ledger-977620f1b5218cc8a041742f970974a4bfff29cc.tar.bz2 money-ledger-977620f1b5218cc8a041742f970974a4bfff29cc.zip |
Diffstat (limited to 'src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt')
-rw-r--r-- | src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt | 74 |
1 files changed, 38 insertions, 36 deletions
diff --git a/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt b/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt index 3da0a07..fa0d8fa 100644 --- a/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt +++ b/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt @@ -6,44 +6,46 @@ import net.minecraft.nbt.NBTTagCompound import net.minecraftforge.client.event.GuiScreenEvent import net.minecraftforge.common.MinecraftForge import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import org.lwjgl.input.Mouse class ItemIdProvider { - @SubscribeEvent - fun onMouseInput(event: GuiScreenEvent.MouseInputEvent.Pre) { - MinecraftForge.EVENT_BUS.post(BeforeGuiAction(event.gui)) - } - - @SubscribeEvent - fun onKeyInput(event: GuiScreenEvent.KeyboardInputEvent.Pre) { - MinecraftForge.EVENT_BUS.post(BeforeGuiAction(event.gui)) - } - - private val knownNames = mutableMapOf<String, String>() - - @SubscribeEvent - fun saveInventoryIds(event: BeforeGuiAction) { - val chest = (event.gui as? GuiChest) ?: return - val slots = chest.inventorySlots as ContainerChest - val chestName = slots.lowerChestInventory.name.unformattedString() - val isOrderMenu = chestName == "Your Bazaar Orders" || chestName == "Co-op Bazaar Orders" - slots.inventorySlots.forEach { - val stack = it.stack ?: return@forEach - val nbt = stack.tagCompound ?: NBTTagCompound() - val display = nbt.getCompoundTag("display") - var name = display.getString("Name").unformattedString() - if (isOrderMenu) - name = name.removePrefix("BUY ").removePrefix("SELL ") - name = name.trim() - val id = stack.getInternalId() - if (id != null && name.isNotBlank()) { - knownNames[name] = id - } - } - } - - fun findForName(name: String): String? { - return knownNames[name] - } + @SubscribeEvent + fun onMouseInput(event: GuiScreenEvent.MouseInputEvent.Pre) { + if (Mouse.getEventButton() == -1) return + MinecraftForge.EVENT_BUS.post(BeforeGuiAction(event.gui)) + } + + @SubscribeEvent + fun onKeyInput(event: GuiScreenEvent.KeyboardInputEvent.Pre) { + MinecraftForge.EVENT_BUS.post(BeforeGuiAction(event.gui)) + } + + private val knownNames = mutableMapOf<String, String>() + + @SubscribeEvent + fun saveInventoryIds(event: BeforeGuiAction) { + val chest = (event.gui as? GuiChest) ?: return + val slots = chest.inventorySlots as ContainerChest + val chestName = slots.lowerChestInventory.name.unformattedString() + val isOrderMenu = chestName == "Your Bazaar Orders" || chestName == "Co-op Bazaar Orders" + slots.inventorySlots.forEach { + val stack = it.stack ?: return@forEach + val nbt = stack.tagCompound ?: NBTTagCompound() + val display = nbt.getCompoundTag("display") + var name = display.getString("Name").unformattedString() + if (isOrderMenu) + name = name.removePrefix("BUY ").removePrefix("SELL ") + name = name.trim() + val id = stack.getInternalId() + if (id != null && name.isNotBlank()) { + knownNames[name] = id + } + } + } + + fun findForName(name: String): String? { + return knownNames[name] + } }
\ No newline at end of file |