diff options
author | CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> | 2024-05-30 18:01:24 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-30 10:01:24 +0200 |
commit | b2733f13841363c9417c0eb79d7240990eb36bcb (patch) | |
tree | 4b407da2aac70e8976f1731186b9f99fcd18d248 /src/main/java/at/hannibal2/skyhanni/events | |
parent | 2fad00835fdb9d84a19c56c63a34c8a736a9aa5c (diff) | |
download | skyhanni-b2733f13841363c9417c0eb79d7240990eb36bcb.tar.gz skyhanni-b2733f13841363c9417c0eb79d7240990eb36bcb.tar.bz2 skyhanni-b2733f13841363c9417c0eb79d7240990eb36bcb.zip |
Backend: Make skyhanni ReplaceItemEvent (#1866)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Co-authored-by: hannibal2 <24389977+hannibal002@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/events')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/events/render/gui/ReplaceItemEvent.kt | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/events/render/gui/ReplaceItemEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/render/gui/ReplaceItemEvent.kt new file mode 100644 index 000000000..ca2f2efbb --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/events/render/gui/ReplaceItemEvent.kt @@ -0,0 +1,31 @@ +package at.hannibal2.skyhanni.events.render.gui + +import at.hannibal2.skyhanni.events.LorenzEvent +import net.minecraft.inventory.IInventory +import net.minecraft.inventory.InventoryBasic +import net.minecraft.item.ItemStack +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable + +class ReplaceItemEvent(val inventory: IInventory, val originalItem: ItemStack, val slot: Int) : LorenzEvent() { + var replacement: ItemStack? = null + private set + + fun replace(replacement: ItemStack?) { + this.replacement = replacement + } + + companion object { + @JvmStatic + fun postEvent( + inventory: InventoryBasic, + inventoryContents: Array<ItemStack?>, + slot: Int, + cir: CallbackInfoReturnable<ItemStack>, + ) { + val originalItem = inventoryContents.getOrNull(slot) ?: return + val event = ReplaceItemEvent(inventory, originalItem, slot) + event.postAndCatch() + event.replacement?.let { cir.returnValue = it } + } + } +} |