diff options
author | Linnea Gräf <nea@nea.moe> | 2024-02-15 19:06:46 +0100 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-02-15 19:06:46 +0100 |
commit | aa8ca77ae239b9b6be140911524d70ba2b46c42d (patch) | |
tree | 14a91f9756853b1162a6725bb9100ab04061c2c2 /src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt | |
parent | 3e19b97b52fae7422f8b0654da9341bf8c2393cb (diff) | |
download | LocalTransactionLedger-aa8ca77ae239b9b6be140911524d70ba2b46c42d.tar.gz LocalTransactionLedger-aa8ca77ae239b9b6be140911524d70ba2b46c42d.tar.bz2 LocalTransactionLedger-aa8ca77ae239b9b6be140911524d70ba2b46c42d.zip |
Add auction support
Diffstat (limited to 'src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt')
-rw-r--r-- | src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt b/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt index 8ad8d26..988e317 100644 --- a/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt +++ b/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt @@ -1,37 +1,37 @@ package moe.nea.ledger -import net.minecraft.client.gui.GuiScreen import net.minecraft.client.gui.inventory.GuiChest import net.minecraft.inventory.ContainerChest import net.minecraft.nbt.NBTTagCompound import net.minecraftforge.client.event.GuiScreenEvent +import net.minecraftforge.common.MinecraftForge import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class ItemIdProvider { @SubscribeEvent fun onMouseInput(event: GuiScreenEvent.MouseInputEvent.Pre) { - saveInventoryIds(event.gui) + MinecraftForge.EVENT_BUS.post(BeforeGuiAction(event.gui)) } @SubscribeEvent fun onKeyInput(event: GuiScreenEvent.KeyboardInputEvent.Pre) { - saveInventoryIds(event.gui) + MinecraftForge.EVENT_BUS.post(BeforeGuiAction(event.gui)) } private val knownNames = mutableMapOf<String, String>() - fun saveInventoryIds(gui: GuiScreen) { - val chest = (gui as? GuiChest) ?: return + @SubscribeEvent + fun saveInventoryIds(event: BeforeGuiAction) { + val chest = (event.gui as? GuiChest) ?: return val slots = chest.inventorySlots as ContainerChest slots.inventorySlots.forEach { val stack = it.stack ?: return@forEach val nbt = stack.tagCompound ?: NBTTagCompound() val display = nbt.getCompoundTag("display") val name = display.getString("Name").unformattedString() - val extraAttributes = nbt.getCompoundTag("ExtraAttributes") - val id = extraAttributes.getString("id") - if (id.isNotBlank() && name.isNotBlank()) { + val id = stack.getInternalId() + if (id != null && name.isNotBlank()) { knownNames[name] = id } } |