diff options
| author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-02-16 20:31:04 +0100 |
|---|---|---|
| committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-02-16 20:31:04 +0100 |
| commit | 07351036391533533cd059ef6910c6bc1efeb36f (patch) | |
| tree | 723c655ac358227b98548a4e81f1eafd00636265 /src/main/java/at/hannibal2/skyhanni/data | |
| parent | 67011d64534f855959ab33abc56e83eec713e924 (diff) | |
| download | skyhanni-07351036391533533cd059ef6910c6bc1efeb36f.tar.gz skyhanni-07351036391533533cd059ef6910c6bc1efeb36f.tar.bz2 skyhanni-07351036391533533cd059ef6910c6bc1efeb36f.zip | |
Show copper to coin prices inside the Sky Mart inventory.
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/data')
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/InventoryData.kt | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/InventoryData.kt b/src/main/java/at/hannibal2/skyhanni/data/InventoryData.kt new file mode 100644 index 000000000..3495f2177 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/data/InventoryData.kt @@ -0,0 +1,72 @@ +package at.hannibal2.skyhanni.data + +import at.hannibal2.skyhanni.events.GuiContainerEvent +import at.hannibal2.skyhanni.events.InventoryCloseEvent +import at.hannibal2.skyhanni.events.InventoryOpenEvent +import at.hannibal2.skyhanni.events.PacketEvent +import net.minecraft.item.ItemStack +import net.minecraft.network.play.server.S2DPacketOpenWindow +import net.minecraft.network.play.server.S2FPacketSetSlot +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class InventoryData { + private var currentInventory: Inventory? = null + + @SubscribeEvent + fun onCloseWindow(event: GuiContainerEvent.CloseWindowEvent) { + close() + } + + private fun close() { + currentInventory?.let { + InventoryCloseEvent(it).postAndCatch() + currentInventory = null + } + } + + @SubscribeEvent + fun onChatPacket(event: PacketEvent.ReceiveEvent) { + val packet = event.packet + + if (packet is S2DPacketOpenWindow) { + val windowId = packet.windowId + val title = packet.windowTitle.unformattedText + val slotCount = packet.slotCount + close() + + currentInventory = Inventory(windowId, title, slotCount) + } + + if (packet is S2FPacketSetSlot) { + currentInventory?.let { + if (it.windowId != packet.func_149175_c()) return + + val slot = packet.func_149173_d() + if (slot < it.slotCount) { + val itemStack = packet.func_149174_e() + if (itemStack != null) { + it.items[slot] = itemStack + } + } else { + done(it) + return + } + + if (it.items.size == it.slotCount) { + done(it) + } + } + } + } + + private fun done(inventory: Inventory) { + InventoryOpenEvent(inventory).postAndCatch() + } + + class Inventory( + val windowId: Int, + val title: String, + val slotCount: Int, + val items: MutableMap<Int, ItemStack> = mutableMapOf() + ) +}
\ No newline at end of file |
