diff options
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/data')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/InventoryData.kt | 34 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/ToolTipData.kt | 21 |
2 files changed, 49 insertions, 6 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/InventoryData.kt b/src/main/java/at/hannibal2/skyhanni/data/InventoryData.kt index 0f372269a..d3630c159 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/InventoryData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/InventoryData.kt @@ -1,17 +1,16 @@ 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 at.hannibal2.skyhanni.events.* 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 +import net.minecraftforge.fml.common.gameevent.TickEvent class InventoryData { private var currentInventory: Inventory? = null private var acceptItems = false + private var lateEvent: LateInventoryOpenEvent? = null @SubscribeEvent fun onCloseWindow(event: GuiContainerEvent.CloseWindowEvent) { @@ -26,6 +25,15 @@ class InventoryData { } @SubscribeEvent + fun onTick(event: TickEvent.ClientTickEvent) { + if (event.phase != TickEvent.Phase.START) return + lateEvent?.let { + it.postAndCatch() + lateEvent = null + } + } + + @SubscribeEvent fun onChatPacket(event: PacketEvent.ReceiveEvent) { val packet = event.packet @@ -40,7 +48,21 @@ class InventoryData { } if (packet is S2FPacketSetSlot) { - if (!acceptItems) return + if (!acceptItems) { + 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 + lateEvent = LateInventoryOpenEvent(it) + } + } + } + return + } currentInventory?.let { if (it.windowId != packet.func_149175_c()) return @@ -71,6 +93,6 @@ class InventoryData { val windowId: Int, val title: String, val slotCount: Int, - val items: MutableMap<Int, ItemStack> = mutableMapOf() + val items: MutableMap<Int, ItemStack> = mutableMapOf(), ) }
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/data/ToolTipData.kt b/src/main/java/at/hannibal2/skyhanni/data/ToolTipData.kt new file mode 100644 index 000000000..70ed2ead6 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/data/ToolTipData.kt @@ -0,0 +1,21 @@ +package at.hannibal2.skyhanni.data + +import at.hannibal2.skyhanni.events.LorenzToolTipEvent +import net.minecraft.inventory.Slot +import net.minecraftforge.event.entity.player.ItemTooltipEvent +import net.minecraftforge.fml.common.eventhandler.EventPriority +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class ToolTipData { + + @SubscribeEvent(priority = EventPriority.LOWEST) + fun onTooltip(event: ItemTooltipEvent) { + val toolTip = event.toolTip ?: return + val slot = lastSlot ?: return + LorenzToolTipEvent(slot, event.itemStack, toolTip).postAndCatch() + } + + companion object { + var lastSlot: Slot? = null + } +}
\ No newline at end of file |