diff options
Diffstat (limited to 'src/main')
10 files changed, 80 insertions, 27 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 } + } + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/plots/GardenPlotIcon.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/plots/GardenPlotIcon.kt index 45a55824e..130de6926 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/plots/GardenPlotIcon.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/plots/GardenPlotIcon.kt @@ -4,12 +4,12 @@ import at.hannibal2.skyhanni.events.GuiContainerEvent import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent import at.hannibal2.skyhanni.events.LorenzToolTipEvent +import at.hannibal2.skyhanni.events.render.gui.ReplaceItemEvent import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.NEUItems.getItemStack -import io.github.moulberry.notenoughupdates.events.ReplaceItemEvent import io.github.moulberry.notenoughupdates.util.Utils import net.minecraft.client.player.inventory.ContainerLocalMenu import net.minecraft.init.Items @@ -70,15 +70,15 @@ object GardenPlotIcon { } if (event.inventory is ContainerLocalMenu) { - if (event.slotNumber == 53) { - event.replaceWith(editStack) + if (event.slot == 53) { + event.replace(editStack) } - if (plotList.isNotEmpty() && plotList.contains(event.slotNumber)) { - if (lastClickedSlotId == event.slotNumber) { + if (plotList.isNotEmpty() && plotList.contains(event.slot)) { + if (lastClickedSlotId == event.slot) { lastClickedSlotId = -1 return } - event.replaceWith(cachedStack[event.slotNumber]) + event.replace(cachedStack[event.slot]) } } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt index 8fe8bee3c..406f85298 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt @@ -4,6 +4,7 @@ import at.hannibal2.skyhanni.data.SackAPI.getAmountInSacks import at.hannibal2.skyhanni.events.GuiContainerEvent import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.garden.visitor.VisitorOpenEvent +import at.hannibal2.skyhanni.events.render.gui.ReplaceItemEvent import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.HypixelCommands import at.hannibal2.skyhanni.utils.ItemUtils.itemName @@ -14,7 +15,6 @@ import at.hannibal2.skyhanni.utils.NEUItems.allIngredients import at.hannibal2.skyhanni.utils.NEUItems.getItemStack import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.StringUtils.removeColor -import io.github.moulberry.notenoughupdates.events.ReplaceItemEvent import io.github.moulberry.notenoughupdates.util.Utils import net.minecraft.entity.player.InventoryPlayer import net.minecraftforge.fml.common.eventhandler.EventPriority @@ -95,8 +95,8 @@ class GardenVisitorSupercraft { if (!hasIngredients) return if (event.inventory is InventoryPlayer) return - if (event.slotNumber == 31) { - event.replaceWith(superCraftItem) + if (event.slot == 31) { + event.replace(superCraftItem) } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/auctionhouse/AuctionHouseOpenPriceWebsite.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/auctionhouse/AuctionHouseOpenPriceWebsite.kt index e28361188..bc3d52a7f 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/auctionhouse/AuctionHouseOpenPriceWebsite.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/auctionhouse/AuctionHouseOpenPriceWebsite.kt @@ -4,6 +4,7 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.GuiContainerEvent import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent +import at.hannibal2.skyhanni.events.render.gui.ReplaceItemEvent import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.NEUItems.getItemStack @@ -11,7 +12,6 @@ import at.hannibal2.skyhanni.utils.OSUtils import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern -import io.github.moulberry.notenoughupdates.events.ReplaceItemEvent import io.github.moulberry.notenoughupdates.util.Utils import net.minecraft.entity.player.InventoryPlayer import net.minecraft.item.ItemStack @@ -65,9 +65,9 @@ class AuctionHouseOpenPriceWebsite { if (!isEnabled()) return if (event.inventory is InventoryPlayer) return - if (event.slotNumber == 8) { + if (event.slot == 8) { displayItem?.let { - event.replaceWith(it) + event.replace(it) } } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarOpenPriceWebsite.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarOpenPriceWebsite.kt index 395df582e..2e680450d 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarOpenPriceWebsite.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarOpenPriceWebsite.kt @@ -2,12 +2,12 @@ package at.hannibal2.skyhanni.features.inventory.bazaar import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.GuiContainerEvent +import at.hannibal2.skyhanni.events.render.gui.ReplaceItemEvent import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.NEUItems.getItemStack import at.hannibal2.skyhanni.utils.OSUtils import at.hannibal2.skyhanni.utils.SimpleTimeMark -import io.github.moulberry.notenoughupdates.events.ReplaceItemEvent import io.github.moulberry.notenoughupdates.util.Utils import net.minecraft.entity.player.InventoryPlayer import net.minecraftforge.fml.common.eventhandler.EventPriority @@ -36,8 +36,8 @@ class BazaarOpenPriceWebsite { BazaarApi.currentlyOpenedProduct ?: return if (event.inventory is InventoryPlayer) return - if (event.slotNumber == 22) { - event.replaceWith(item) + if (event.slot == 22) { + event.replace(item) } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryShortcut.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryShortcut.kt index d3bb031b2..2e0f85edf 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryShortcut.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryShortcut.kt @@ -4,11 +4,11 @@ import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.events.GuiContainerEvent import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent +import at.hannibal2.skyhanni.events.render.gui.ReplaceItemEvent import at.hannibal2.skyhanni.utils.HypixelCommands import at.hannibal2.skyhanni.utils.ItemUtils import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.SimpleTimeMark -import io.github.moulberry.notenoughupdates.events.ReplaceItemEvent import net.minecraft.client.player.inventory.ContainerLocalMenu import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -53,8 +53,8 @@ class ChocolateFactoryShortcut { @SubscribeEvent fun replaceItem(event: ReplaceItemEvent) { - if (event.inventory is ContainerLocalMenu && showItem && event.slotNumber == 15) { - event.replaceWith(item) + if (event.inventory is ContainerLocalMenu && showItem && event.slot == 15) { + event.replace(item) } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/DeepCavernsGuide.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/DeepCavernsGuide.kt index 94bb86d03..52549bee6 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/mining/DeepCavernsGuide.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/DeepCavernsGuide.kt @@ -11,6 +11,7 @@ import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent import at.hannibal2.skyhanni.events.IslandChangeEvent import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent import at.hannibal2.skyhanni.events.RepositoryReloadEvent +import at.hannibal2.skyhanni.events.render.gui.ReplaceItemEvent import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.ColorUtils.toChromaColor import at.hannibal2.skyhanni.utils.ConditionalUtils @@ -19,7 +20,6 @@ import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.NEUItems.getItemStack import at.hannibal2.skyhanni.utils.ParkourHelper -import io.github.moulberry.notenoughupdates.events.ReplaceItemEvent import io.github.moulberry.notenoughupdates.util.Utils import net.minecraft.client.player.inventory.ContainerLocalMenu import net.minecraftforge.fml.common.eventhandler.EventPriority @@ -123,8 +123,8 @@ class DeepCavernsGuide { @SubscribeEvent fun replaceItem(event: ReplaceItemEvent) { if (show) return - if (event.inventory is ContainerLocalMenu && showStartIcon && event.slotNumber == 49) { - event.replaceWith(startIcon) + if (event.inventory is ContainerLocalMenu && showStartIcon && event.slot == 49) { + event.replace(startIcon) } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/limbo/LimboPlaytime.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/limbo/LimboPlaytime.kt index d5a8a3765..2698c0e94 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/limbo/LimboPlaytime.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/limbo/LimboPlaytime.kt @@ -4,6 +4,7 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.ProfileStorageData import at.hannibal2.skyhanni.events.InventoryOpenEvent import at.hannibal2.skyhanni.events.LorenzToolTipEvent +import at.hannibal2.skyhanni.events.render.gui.ReplaceItemEvent import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.round import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName @@ -12,7 +13,6 @@ import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.RegexUtils.matches import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern -import io.github.moulberry.notenoughupdates.events.ReplaceItemEvent import io.github.moulberry.notenoughupdates.util.Utils import net.minecraft.client.player.inventory.ContainerLocalMenu import net.minecraft.item.ItemStack @@ -50,7 +50,7 @@ object LimboPlaytime { if (!enabled) return if (event.inventory !is ContainerLocalMenu) return if (event.inventory.name != "Detailed /playtime") return - if (event.slotNumber != 43) return + if (event.slot != 43) return val playtime = storage?.playtime ?: 0 if (playtime < 60) return @@ -62,7 +62,7 @@ object LimboPlaytime { *createItemLore() ) } - event.replaceWith(limboItem) + event.replace(limboItem) } private fun createItemLore(): Array<String> = when { diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/EnigmaSoulWaypoints.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/EnigmaSoulWaypoints.kt index 01a16b6df..2f8ed7e1a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/EnigmaSoulWaypoints.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/EnigmaSoulWaypoints.kt @@ -7,6 +7,7 @@ import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent import at.hannibal2.skyhanni.events.RepositoryReloadEvent +import at.hannibal2.skyhanni.events.render.gui.ReplaceItemEvent import at.hannibal2.skyhanni.features.rift.RiftAPI import at.hannibal2.skyhanni.test.GriffinUtils.drawWaypointFilled import at.hannibal2.skyhanni.utils.ChatUtils @@ -20,7 +21,6 @@ import at.hannibal2.skyhanni.utils.NEUItems.getItemStack import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText import at.hannibal2.skyhanni.utils.RenderUtils.highlight import at.hannibal2.skyhanni.utils.StringUtils.removeColor -import io.github.moulberry.notenoughupdates.events.ReplaceItemEvent import io.github.moulberry.notenoughupdates.util.Utils import net.minecraft.client.gui.inventory.GuiChest import net.minecraft.client.player.inventory.ContainerLocalMenu @@ -53,8 +53,8 @@ object EnigmaSoulWaypoints { if (!isEnabled()) return if (inventoryUnfound.isEmpty()) return - if (event.inventory is ContainerLocalMenu && inInventory && event.slotNumber == 31) { - event.replaceWith(item) + if (event.inventory is ContainerLocalMenu && inInventory && event.slot == 31) { + event.replace(item) } } diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/gui/MixinInventoryBasic.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/gui/MixinInventoryBasic.java new file mode 100644 index 000000000..7fdb2d604 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/gui/MixinInventoryBasic.java @@ -0,0 +1,22 @@ +package at.hannibal2.skyhanni.mixins.transformers.gui; + +import at.hannibal2.skyhanni.events.render.gui.ReplaceItemEvent; +import net.minecraft.inventory.InventoryBasic; +import net.minecraft.item.ItemStack; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(InventoryBasic.class) +public class MixinInventoryBasic { + + @Shadow + private ItemStack[] inventoryContents; + + @Inject(method = "getStackInSlot", at = @At("HEAD"), cancellable = true) + public void getStackInSlot(int index, CallbackInfoReturnable<ItemStack> cir) { + ReplaceItemEvent.postEvent((InventoryBasic) (Object) this, this.inventoryContents, index, cir); + } +} |