From 8ef128eb5910021475d89187c4e59e268e5c065e Mon Sep 17 00:00:00 2001 From: "Plamen K. Kosseff" Date: Fri, 30 Aug 2024 18:12:20 +0300 Subject: [PATCH] Start of major refactoring. --- .../mc/ipnext/mixin/MixinInGameHud.java | 2 +- .../ipnext/compat/integrations/ChippedExt.kt | 32 -------- .../compat/integrations/Integrations.kt | 3 - .../mc/ipnext/mixin/MixinInGameHud.java | 2 +- .../mc/ipnext/mixin/MixinInGameHud.java | 2 +- .../org/anti_ad/mc/ipnext/access/IPNImpl.kt | 2 +- .../org/anti_ad/mc/ipnext/config/Configs.kt | 2 +- .../mc/ipnext/event/ClientEventHandler.kt | 1 + .../mc/ipnext/event/LockSlotsHandler.kt | 19 ++++- .../mc/ipnext/event/LockedSlotKeeper.kt | 1 + .../mc/ipnext/event/ProfileSwitchHandler.kt | 1 + .../mc/ipnext/event/SlotHighlightHandler.kt | 2 +- .../{ => autorefill}/AutoRefillHandler.kt | 13 ++- .../org/anti_ad/mc/ipnext/gui/ConfigScreen.kt | 2 +- .../mc/ipnext/gui/base/InventoryOverlay.kt | 45 +++++------ .../gui/inject/ContainerScreenEventHandler.kt | 6 +- .../ipnext/input/CancellableInputHandler.kt | 2 +- .../anti_ad/mc/ipnext/input/InputHandler.kt | 1 - .../inventory/GeneralInventoryActions.kt | 6 +- .../inventory/sandbox/ContainerSandbox.kt | 11 ++- .../mc/ipnext/parser/CustomDataFileLoader.kt | 2 +- .../mc/ipn/events/api/ActionExecutor.kt | 80 +++++++++++++++++++ .../ipn/features}/scrolling/ScrollingUtils.kt | 39 +++++---- 23 files changed, 168 insertions(+), 108 deletions(-) delete mode 100644 platforms/forge-1.21/src/main/java/org/anti_ad/mc/ipnext/compat/integrations/ChippedExt.kt rename platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/event/{ => autorefill}/AutoRefillHandler.kt (99%) create mode 100644 platforms/shared-1.20.5+/src/main/kotlin/org/anti_ad/mc/ipn/events/api/ActionExecutor.kt rename platforms/shared-1.20.5+/src/main/{java/org/anti_ad/mc/ipnext/inventory => kotlin/org/anti_ad/mc/ipn/features}/scrolling/ScrollingUtils.kt (96%) diff --git a/platforms/fabric-1.21/src/main/java/org/anti_ad/mc/ipnext/mixin/MixinInGameHud.java b/platforms/fabric-1.21/src/main/java/org/anti_ad/mc/ipnext/mixin/MixinInGameHud.java index 1a7d66d6c..f1ea5aeed 100644 --- a/platforms/fabric-1.21/src/main/java/org/anti_ad/mc/ipnext/mixin/MixinInGameHud.java +++ b/platforms/fabric-1.21/src/main/java/org/anti_ad/mc/ipnext/mixin/MixinInGameHud.java @@ -24,7 +24,7 @@ import net.minecraft.client.gui.hud.InGameHud; import net.minecraft.client.render.RenderTickCounter; import org.anti_ad.mc.common.gui.NativeContext; -import org.anti_ad.mc.ipnext.event.AutoRefillHandler; +import org.anti_ad.mc.ipnext.event.autorefill.AutoRefillHandler; import org.anti_ad.mc.ipnext.event.LockSlotsHandler; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; diff --git a/platforms/forge-1.21/src/main/java/org/anti_ad/mc/ipnext/compat/integrations/ChippedExt.kt b/platforms/forge-1.21/src/main/java/org/anti_ad/mc/ipnext/compat/integrations/ChippedExt.kt deleted file mode 100644 index e0e3a0d0e..000000000 --- a/platforms/forge-1.21/src/main/java/org/anti_ad/mc/ipnext/compat/integrations/ChippedExt.kt +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Inventory Profiles Next - * - * Copyright (c) 2023 Plamen K. Kosseff - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package org.anti_ad.mc.ipnext.compat.integrations - -import earth.terrarium.chipped.common.menu.ChippedMenu -import net.minecraft.client.player.LocalPlayer -import org.anti_ad.mc.common.vanilla.Vanilla -import org.anti_ad.mc.ipnext.ingame.`(syncId)` - -typealias ChippedMenu = ChippedMenu - -fun ChippedMenu.`(selectRecipe)`(id: Int) { - clickMenuButton(Vanilla.player(), id) - Vanilla.mc().gameMode?.handleInventoryButtonClick(`(syncId)`, id) -} diff --git a/platforms/forge-1.21/src/main/java/org/anti_ad/mc/ipnext/compat/integrations/Integrations.kt b/platforms/forge-1.21/src/main/java/org/anti_ad/mc/ipnext/compat/integrations/Integrations.kt index 5f1f85181..d2bf5efa1 100644 --- a/platforms/forge-1.21/src/main/java/org/anti_ad/mc/ipnext/compat/integrations/Integrations.kt +++ b/platforms/forge-1.21/src/main/java/org/anti_ad/mc/ipnext/compat/integrations/Integrations.kt @@ -26,9 +26,6 @@ object Integrations { val carpetEmptyShulkersStackSize = 1 fun init(): Boolean { - trySwallow { - ChippedIntegration.init() - } return false } } diff --git a/platforms/forge-1.21/src/main/java/org/anti_ad/mc/ipnext/mixin/MixinInGameHud.java b/platforms/forge-1.21/src/main/java/org/anti_ad/mc/ipnext/mixin/MixinInGameHud.java index 1932dc6a9..d573c997d 100644 --- a/platforms/forge-1.21/src/main/java/org/anti_ad/mc/ipnext/mixin/MixinInGameHud.java +++ b/platforms/forge-1.21/src/main/java/org/anti_ad/mc/ipnext/mixin/MixinInGameHud.java @@ -25,7 +25,7 @@ import net.minecraft.client.gui.GuiGraphics; import org.anti_ad.mc.common.gui.NativeContext; -import org.anti_ad.mc.ipnext.event.AutoRefillHandler; +import org.anti_ad.mc.ipnext.event.autorefill.AutoRefillHandler; import org.anti_ad.mc.ipnext.event.LockSlotsHandler; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; diff --git a/platforms/neoforge-1.21/src/main/java/org/anti_ad/mc/ipnext/mixin/MixinInGameHud.java b/platforms/neoforge-1.21/src/main/java/org/anti_ad/mc/ipnext/mixin/MixinInGameHud.java index fd05435fd..7fd998e7c 100644 --- a/platforms/neoforge-1.21/src/main/java/org/anti_ad/mc/ipnext/mixin/MixinInGameHud.java +++ b/platforms/neoforge-1.21/src/main/java/org/anti_ad/mc/ipnext/mixin/MixinInGameHud.java @@ -24,7 +24,7 @@ import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiGraphics; import org.anti_ad.mc.common.gui.NativeContext; -import org.anti_ad.mc.ipnext.event.AutoRefillHandler; +import org.anti_ad.mc.ipnext.event.autorefill.AutoRefillHandler; import org.anti_ad.mc.ipnext.event.LockSlotsHandler; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; diff --git a/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/access/IPNImpl.kt b/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/access/IPNImpl.kt index f187ea7e7..8f278d924 100644 --- a/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/access/IPNImpl.kt +++ b/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/access/IPNImpl.kt @@ -25,7 +25,7 @@ import org.anti_ad.mc.common.vanilla.Vanilla import org.anti_ad.mc.ipn.api.access.IContainerClicker import org.anti_ad.mc.ipn.api.access.IPN import org.anti_ad.mc.ipnext.config.ModSettings -import org.anti_ad.mc.ipnext.event.AutoRefillHandler +import org.anti_ad.mc.ipnext.event.autorefill.AutoRefillHandler import org.anti_ad.mc.ipnext.event.LockSlotsHandler import org.anti_ad.mc.ipnext.event.LockedSlotKeeper import org.anti_ad.mc.ipnext.ingame.vCursorStack diff --git a/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/config/Configs.kt b/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/config/Configs.kt index 5f836923f..62d12f124 100644 --- a/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/config/Configs.kt +++ b/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/config/Configs.kt @@ -52,7 +52,7 @@ import org.anti_ad.mc.ipnext.integration.MergePriority import org.anti_ad.mc.ipnext.config.defaults.AUTO_REFILL_WAIT_TICK_DEFAULT import org.anti_ad.mc.ipnext.config.defaults.AUTO_REFILL_WAIT_TICK_MINIMUM import org.anti_ad.mc.ipnext.debug.GenerateTagsAsJson -import org.anti_ad.mc.ipnext.event.AutoRefillHandler +import org.anti_ad.mc.ipnext.event.autorefill.AutoRefillHandler import org.anti_ad.mc.ipnext.event.LockedSlotKeeper import org.anti_ad.mc.ipnext.gui.ConfigScreeHelper.keyToggleBool import org.anti_ad.mc.ipnext.item.ItemTypeExtensionsObject diff --git a/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/event/ClientEventHandler.kt b/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/event/ClientEventHandler.kt index 4898231d4..9b5de5ede 100644 --- a/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/event/ClientEventHandler.kt +++ b/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/event/ClientEventHandler.kt @@ -32,6 +32,7 @@ import org.anti_ad.mc.ipnext.config.GuiSettings import org.anti_ad.mc.ipnext.config.LockedSlotsSettings import org.anti_ad.mc.ipnext.config.ModSettings import org.anti_ad.mc.ipnext.config.Tweaks +import org.anti_ad.mc.ipnext.event.autorefill.AutoRefillHandler import org.anti_ad.mc.ipnext.parser.CustomDataFileLoader import org.anti_ad.mc.ipnext.specific.event.PClientEventHandler import org.anti_ad.mc.ipnext.versionCheckUrl diff --git a/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/event/LockSlotsHandler.kt b/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/event/LockSlotsHandler.kt index c97666511..ddf2e6f4a 100644 --- a/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/event/LockSlotsHandler.kt +++ b/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/event/LockSlotsHandler.kt @@ -45,7 +45,6 @@ import org.anti_ad.mc.ipnext.config.ModSettings import org.anti_ad.mc.ipnext.config.SwitchType.HOLD import org.anti_ad.mc.ipnext.config.SwitchType.TOGGLE import org.anti_ad.mc.ipnext.gui.base.InventoryOverlay -import org.anti_ad.mc.ipnext.gui.base.InventoryOverlay.Companion.backgroundSprite import org.anti_ad.mc.ipnext.ingame.`(containerBounds)` import org.anti_ad.mc.ipnext.ingame.`(invSlot)` import org.anti_ad.mc.ipnext.ingame.`(inventoryOrNull)` @@ -54,6 +53,7 @@ import org.anti_ad.mc.ipnext.ingame.`(scaledHeight)` import org.anti_ad.mc.ipnext.ingame.`(scaledWidth)` import org.anti_ad.mc.ipnext.ingame.`(selectedSlot)` import org.anti_ad.mc.ipnext.ingame.`(slots)` +import org.anti_ad.mc.ipnext.ingame.`(topLeft)` import org.anti_ad.mc.ipnext.ingame.`(window)` import org.anti_ad.mc.ipnext.ingame.vPlayerSlotOf import org.anti_ad.mc.ipnext.item.maxCount @@ -78,6 +78,21 @@ object LockSlotsHandler: InventoryOverlay { override val enabledBackground: Boolean get() = ModSettings.ENABLE_LOCK_SLOTS.booleanValue && LockedSlotsSettings.SHOW_LOCKED_SLOTS_BACKGROUND.booleanValue + override val slotLocations: Map + get() { + val screen = Vanilla.screen() as? ContainerScreen<*> ?: return mapOf() + @Suppress("USELESS_ELVIS") + val container = Vanilla.container() ?: return mapOf() + return container.`(slots)`.mapNotNull { slot -> + val playerSlot = vPlayerSlotOf(slot, + screen) + val topLeft =slot.`(topLeft)` + val inv = playerSlot.`(inventoryOrNull)` ?: return@mapNotNull null + return@mapNotNull if (inv is PlayerInventory) playerSlot.`(invSlot)` to topLeft else null + }.toMap() + } + + val lockedInvSlotsStoredValue = mutableSetOf() // locked invSlot list val lockedInvSlots: Iterable @@ -141,7 +156,7 @@ object LockSlotsHandler: InventoryOverlay { - fun postRender(context: NativeContext) { // display config + override fun postRender(context: NativeContext) { // display config } override fun drawForeground(context: NativeContext) { diff --git a/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/event/LockedSlotKeeper.kt b/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/event/LockedSlotKeeper.kt index 7185dc4ee..0ee6d0d76 100644 --- a/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/event/LockedSlotKeeper.kt +++ b/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/event/LockedSlotKeeper.kt @@ -30,6 +30,7 @@ import org.anti_ad.mc.common.vanilla.VanillaUtil import org.anti_ad.mc.ipnext.config.Debugs import org.anti_ad.mc.ipnext.config.LockedSlotsSettings import org.anti_ad.mc.ipnext.config.ModSettings +import org.anti_ad.mc.ipnext.event.autorefill.AutoRefillHandler import org.anti_ad.mc.ipnext.ingame.`(itemStack)` import org.anti_ad.mc.ipnext.ingame.`(itemType)` import org.anti_ad.mc.ipnext.ingame.`(selectedSlot)` diff --git a/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/event/ProfileSwitchHandler.kt b/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/event/ProfileSwitchHandler.kt index 56448280c..c1ab7748f 100644 --- a/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/event/ProfileSwitchHandler.kt +++ b/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/event/ProfileSwitchHandler.kt @@ -39,6 +39,7 @@ import org.anti_ad.mc.common.vanilla.VanillaUtil import org.anti_ad.mc.ipnext.config.EditProfiles import org.anti_ad.mc.ipnext.config.GuiSettings import org.anti_ad.mc.ipnext.config.Hotkeys +import org.anti_ad.mc.ipnext.event.autorefill.AutoRefillHandler import org.anti_ad.mc.ipnext.ingame.`(itemStack)` import org.anti_ad.mc.ipnext.ingame.`(selectedSlot)` import org.anti_ad.mc.ipnext.ingame.`(slots)` diff --git a/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/event/SlotHighlightHandler.kt b/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/event/SlotHighlightHandler.kt index d8bc92c6b..e5bfa37ea 100644 --- a/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/event/SlotHighlightHandler.kt +++ b/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/event/SlotHighlightHandler.kt @@ -78,7 +78,7 @@ object SlotHighlightHandler: InventoryOverlay { override fun drawConfig(context: NativeContext) { } - fun postRender(context: NativeContext) { + override fun postRender(context: NativeContext) { } diff --git a/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/event/AutoRefillHandler.kt b/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/event/autorefill/AutoRefillHandler.kt similarity index 99% rename from platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/event/AutoRefillHandler.kt rename to platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/event/autorefill/AutoRefillHandler.kt index c78de4229..1df960787 100644 --- a/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/event/AutoRefillHandler.kt +++ b/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/event/autorefill/AutoRefillHandler.kt @@ -1,8 +1,7 @@ /* * Inventory Profiles Next * - * Copyright (c) 2019-2020 jsnimda <7615255+jsnimda@users.noreply.github.com> - * Copyright (c) 2021-2022 Plamen K. Kosseff + * Copyright (c) 2021-2024 Plamen K. Kosseff * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,7 +19,7 @@ @file:Suppress("UnusedImport") -package org.anti_ad.mc.ipnext.event +package org.anti_ad.mc.ipnext.event.autorefill import org.anti_ad.mc.alias.client.gui.screen.ingame.ContainerScreen import org.anti_ad.mc.alias.client.gui.screen.ingame.InventoryScreen @@ -58,8 +57,10 @@ import org.anti_ad.mc.ipnext.config.ModSettings import org.anti_ad.mc.ipnext.config.ThresholdUnit.ABSOLUTE import org.anti_ad.mc.ipnext.config.ThresholdUnit.PERCENTAGE import org.anti_ad.mc.ipnext.config.ToolReplaceVisualNotification +import org.anti_ad.mc.ipnext.event.LockedSlotKeeper +import org.anti_ad.mc.ipnext.event.MouseTracer +import org.anti_ad.mc.ipnext.event.Sounds import org.anti_ad.mc.ipnext.gui.base.InventoryOverlay -import org.anti_ad.mc.ipnext.gui.base.InventoryOverlay.Companion.TEXTURE import org.anti_ad.mc.ipnext.ingame.`(containerBounds)` import org.anti_ad.mc.ipnext.ingame.`(equipmentSlot)` import org.anti_ad.mc.ipnext.ingame.`(id)` @@ -831,6 +832,10 @@ object AutoRefillHandler: InventoryOverlay { } + override fun postRender(context: NativeContext) { + + } + override fun drawBackground(context: NativeContext) { } diff --git a/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/gui/ConfigScreen.kt b/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/gui/ConfigScreen.kt index 561108f07..6e2af2425 100644 --- a/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/gui/ConfigScreen.kt +++ b/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/gui/ConfigScreen.kt @@ -44,7 +44,7 @@ import org.anti_ad.mc.ipnext.config.Hotkeys import org.anti_ad.mc.ipnext.config.ModSettings import org.anti_ad.mc.ipnext.config.Modpacks import org.anti_ad.mc.ipnext.config.SaveLoadManager -import org.anti_ad.mc.ipnext.event.AutoRefillHandler +import org.anti_ad.mc.ipnext.event.autorefill.AutoRefillHandler import org.anti_ad.mc.common.input.KeybindSettings import org.anti_ad.mc.common.input.KeybindSettings.Companion.INGAME_DEFAULT diff --git a/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/gui/base/InventoryOverlay.kt b/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/gui/base/InventoryOverlay.kt index 4adddca9f..e4a37f522 100644 --- a/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/gui/base/InventoryOverlay.kt +++ b/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/gui/base/InventoryOverlay.kt @@ -20,20 +20,14 @@ package org.anti_ad.mc.ipnext.gui.base -import org.anti_ad.mc.alias.client.gui.screen.ingame.ContainerScreen -import org.anti_ad.mc.alias.inventory.PlayerInventory + import org.anti_ad.mc.common.gui.NativeContext import org.anti_ad.mc.common.math2d.Point import org.anti_ad.mc.common.math2d.Rectangle -import org.anti_ad.mc.common.vanilla.Vanilla import org.anti_ad.mc.common.vanilla.render.glue.IdentifierHolder import org.anti_ad.mc.common.vanilla.render.glue.Sprite -import org.anti_ad.mc.ipnext.ingame.`(invSlot)` -import org.anti_ad.mc.ipnext.ingame.`(inventoryOrNull)` -import org.anti_ad.mc.ipnext.ingame.`(slots)` -import org.anti_ad.mc.ipnext.ingame.`(topLeft)` -import org.anti_ad.mc.ipnext.ingame.vPlayerSlotOf + interface InventoryOverlay { @@ -41,26 +35,25 @@ interface InventoryOverlay { val enabledBackground: Boolean companion object { - val TEXTURE = IdentifierHolder("inventoryprofilesnext", "textures/gui/overlay_new.png") - val backgroundSprite = Sprite(TEXTURE, Rectangle(40, 8, 32, 32)) + @JvmField + val COMP_TEXTURE = IdentifierHolder("inventoryprofilesnext", "textures/gui/overlay_new.png") + @JvmField + val compBackgroundSprite = Sprite(COMP_TEXTURE, Rectangle(40, 8, 32, 32)) + @JvmField + val internal8x8 = Point(8,8) } + @Suppress("PropertyName") + val TEXTURE: IdentifierHolder + get() = COMP_TEXTURE + + val backgroundSprite: Sprite + get() = compBackgroundSprite + val eightByEight: Point - get() = Point(8,8) + get() = internal8x8 val slotLocations: Map - get() { - val screen = Vanilla.screen() as? ContainerScreen<*> ?: return mapOf() - @Suppress("USELESS_ELVIS") - val container = Vanilla.container() ?: return mapOf() - return container.`(slots)`.mapNotNull { slot -> - val playerSlot = vPlayerSlotOf(slot, - screen) - val topLeft =slot.`(topLeft)` - val inv = playerSlot.`(inventoryOrNull)` ?: return@mapNotNull null - return@mapNotNull if (inv is PlayerInventory) playerSlot.`(invSlot)` to topLeft else null - }.toMap() - } fun onForegroundRender(context: NativeContext) { if (!enabledForeground) return @@ -73,6 +66,12 @@ interface InventoryOverlay { drawBackground(context) } + fun onPostRender(context: NativeContext) { + if (!enabledForeground && !enabledBackground) return + postRender(context) + } + + fun postRender(context: NativeContext) fun drawForeground(context: NativeContext) fun drawConfig(context: NativeContext) fun drawBackground(context: NativeContext) diff --git a/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/gui/inject/ContainerScreenEventHandler.kt b/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/gui/inject/ContainerScreenEventHandler.kt index c31b979a6..19a4848cb 100644 --- a/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/gui/inject/ContainerScreenEventHandler.kt +++ b/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/gui/inject/ContainerScreenEventHandler.kt @@ -34,7 +34,7 @@ import org.anti_ad.mc.common.vanilla.Vanilla import org.anti_ad.mc.ipn.api.IPNButton import org.anti_ad.mc.ipnext.config.GuiSettings import org.anti_ad.mc.ipnext.config.ModSettings -import org.anti_ad.mc.ipnext.event.AutoRefillHandler +import org.anti_ad.mc.ipnext.event.autorefill.AutoRefillHandler import org.anti_ad.mc.ipnext.event.LockSlotsHandler import org.anti_ad.mc.ipnext.event.SlotHighlightHandler import org.anti_ad.mc.ipnext.event.villagers.VillagerTradeManager @@ -140,8 +140,8 @@ object ContainerScreenEventHandler { } fun postRender(context: NativeContext) { - LockSlotsHandler.postRender(context) - SlotHighlightHandler.postRender(context) + LockSlotsHandler.onPostRender(context) + SlotHighlightHandler.onPostRender(context) ContainerClicker.postScreenRender(context) currentWidgets?.let { TooltipsManager.renderAll(context) diff --git a/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/input/CancellableInputHandler.kt b/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/input/CancellableInputHandler.kt index 554152a69..d04dafc23 100644 --- a/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/input/CancellableInputHandler.kt +++ b/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/input/CancellableInputHandler.kt @@ -23,7 +23,7 @@ package org.anti_ad.mc.ipnext.input import org.anti_ad.mc.common.IInputHandler import org.anti_ad.mc.common.config.options.ConfigKeyToggleBoolean import org.anti_ad.mc.common.extensions.tryCatch -import org.anti_ad.mc.ipnext.event.AutoRefillHandler +import org.anti_ad.mc.ipnext.event.autorefill.AutoRefillHandler import org.anti_ad.mc.ipnext.event.LockSlotsHandler import org.anti_ad.mc.ipnext.event.ProfileSwitchHandler import org.anti_ad.mc.ipnext.event.villagers.VillagerTradeManager diff --git a/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/input/InputHandler.kt b/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/input/InputHandler.kt index 930078ffc..edfe983ef 100644 --- a/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/input/InputHandler.kt +++ b/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/input/InputHandler.kt @@ -33,7 +33,6 @@ import org.anti_ad.mc.ipnext.config.Debugs import org.anti_ad.mc.ipnext.config.Hotkeys import org.anti_ad.mc.ipnext.config.ModSettings import org.anti_ad.mc.ipnext.debug.ModpackInputHandler -import org.anti_ad.mc.ipnext.event.AutoRefillHandler import org.anti_ad.mc.ipnext.gui.ConfigScreeHelper import org.anti_ad.mc.ipnext.gui.ConfigScreen import org.anti_ad.mc.ipnext.gui.DebugScreen diff --git a/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/inventory/GeneralInventoryActions.kt b/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/inventory/GeneralInventoryActions.kt index 10ee6427a..cc867842e 100644 --- a/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/inventory/GeneralInventoryActions.kt +++ b/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/inventory/GeneralInventoryActions.kt @@ -21,7 +21,6 @@ package org.anti_ad.mc.ipnext.inventory import org.anti_ad.mc.alias.inventory.PlayerInventory -import org.anti_ad.mc.alias.nbt.NbtHelper import org.anti_ad.mc.alias.nbt.NbtHelper_toFormattedString import org.anti_ad.mc.alias.screen.BeaconContainer import org.anti_ad.mc.alias.screen.Container @@ -57,8 +56,8 @@ import org.anti_ad.mc.ipnext.inventory.action.moveMatchTo import org.anti_ad.mc.ipnext.inventory.action.refillStacksTo import org.anti_ad.mc.ipnext.inventory.action.restockFrom import org.anti_ad.mc.ipnext.inventory.action.sort -import org.anti_ad.mc.ipnext.inventory.scrolling.ScrollDirection -import org.anti_ad.mc.ipnext.inventory.scrolling.ScrollingUtils +import org.anti_ad.mc.ipn.features.scrolling.ScrollDirection +import org.anti_ad.mc.ipn.features.scrolling.ScrollingUtils import org.anti_ad.mc.ipnext.item.ComponentUtils.toFullNbtOrNull import org.anti_ad.mc.ipnext.item.EMPTY import org.anti_ad.mc.ipnext.item.ItemStack @@ -66,7 +65,6 @@ import org.anti_ad.mc.ipnext.item.fullItemInfoAsJson import org.anti_ad.mc.ipnext.item.isEmpty import org.anti_ad.mc.ipnext.item.itemId import org.anti_ad.mc.ipnext.item.rule.Rule -import org.anti_ad.mc.ipnext.item.vanillaStack object GeneralInventoryActions { diff --git a/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/inventory/sandbox/ContainerSandbox.kt b/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/inventory/sandbox/ContainerSandbox.kt index 27ee5f56d..72acbae59 100644 --- a/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/inventory/sandbox/ContainerSandbox.kt +++ b/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/inventory/sandbox/ContainerSandbox.kt @@ -95,12 +95,11 @@ class ContainerSandbox(items: MutableItemTracker, // fun copy() = ContainerSandbox(items.copyAsMutable(), clicks) } -data class SandboxClick( - val clickIndex: Int, - val slotIndex: Int, - val button: Int, - val previousClick: SandboxClick? = null -) +data class SandboxClick(val clickIndex: Int, + val slotIndex: Int, + val button: Int, + val previousClick: SandboxClick? = null) + fun SandboxClick?.toList(): List { val list = mutableListOf() diff --git a/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/parser/CustomDataFileLoader.kt b/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/parser/CustomDataFileLoader.kt index 66f56fc83..443098c03 100644 --- a/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/parser/CustomDataFileLoader.kt +++ b/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/parser/CustomDataFileLoader.kt @@ -50,7 +50,7 @@ import org.anti_ad.mc.common.extensions.ifTrue import org.anti_ad.mc.common.extensions.loggingPath import org.anti_ad.mc.common.extensions.sanitized import org.anti_ad.mc.ipnext.NotificationManager -import org.anti_ad.mc.ipnext.event.AutoRefillHandler +import org.anti_ad.mc.ipnext.event.autorefill.AutoRefillHandler import org.anti_ad.mc.ipnext.event.ProfileSwitchHandler import org.anti_ad.mc.ipnext.event.villagers.VillagerDataManager import java.nio.file.Path diff --git a/platforms/shared-1.20.5+/src/main/kotlin/org/anti_ad/mc/ipn/events/api/ActionExecutor.kt b/platforms/shared-1.20.5+/src/main/kotlin/org/anti_ad/mc/ipn/events/api/ActionExecutor.kt new file mode 100644 index 000000000..4de16f99e --- /dev/null +++ b/platforms/shared-1.20.5+/src/main/kotlin/org/anti_ad/mc/ipn/events/api/ActionExecutor.kt @@ -0,0 +1,80 @@ +/* + * Inventory Profiles Next + * + * Copyright (c) 2024 Plamen K. Kosseff + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package org.anti_ad.mc.ipn.events.api + +fun interface Action { + fun doIt(context: T): R? +} + +abstract class ActionExecutor { + + protected val actions: MutableList, () -> Boolean>> = mutableListOf() + + private fun add(action: Action, condition: () -> Boolean) { + actions.add(Pair(action, condition)) + } + + open fun doIt(context: T): R? { + for ((action, condition) in actions) { + if (condition()) { + action.doIt(context)?.let { + if (it !is Unit) return it + } + } + } + return null + } + + open val adder: PredicateActionBuilder + get() { + return PredicateActionBuilder() + } + + open inner class PredicateActionBuilder { + + open lateinit var condition: () -> Boolean + lateinit var action: Action + + open fun action(action: Action): PredicateActionBuilder { + this.action = action + return this + } + open fun predicate(condition: () -> Boolean): PredicateActionBuilder { + this.condition = condition + return this + } + + fun build() { + add(action, condition) + } + } +} + +class SimpleActionExecutor : ActionExecutor() + +class PredicateActionGroup(val predicate: () -> Boolean): ActionExecutor(), Action { + + override fun doIt(context: T): R? { + if (predicate()) { + return super.doIt(context) + } + return null + } +} diff --git a/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/inventory/scrolling/ScrollingUtils.kt b/platforms/shared-1.20.5+/src/main/kotlin/org/anti_ad/mc/ipn/features/scrolling/ScrollingUtils.kt similarity index 96% rename from platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/inventory/scrolling/ScrollingUtils.kt rename to platforms/shared-1.20.5+/src/main/kotlin/org/anti_ad/mc/ipn/features/scrolling/ScrollingUtils.kt index 97ea6f1cd..75625c3cd 100644 --- a/platforms/shared-1.20.5+/src/main/java/org/anti_ad/mc/ipnext/inventory/scrolling/ScrollingUtils.kt +++ b/platforms/shared-1.20.5+/src/main/kotlin/org/anti_ad/mc/ipn/features/scrolling/ScrollingUtils.kt @@ -1,7 +1,7 @@ /* * Inventory Profiles Next * - * Copyright (c) 2022 Plamen K. Kosseff + * Copyright (c) 2022-2024 Plamen K. Kosseff * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package org.anti_ad.mc.ipnext.inventory.scrolling +package org.anti_ad.mc.ipn.features.scrolling import org.anti_ad.mc.alias.screen.slot.Slot import org.anti_ad.mc.ipnext.Log @@ -53,7 +53,7 @@ enum class ScrollDirection { object ScrollingUtils { - inline val doIncludeHotbar: Boolean + private inline val doIncludeHotbar: Boolean get() { return if (ModSettings.ALWAYS_INCLUDE_HOTBAR.booleanValue) { !ModSettings.INCLUDE_HOTBAR_MODIFIER.isPressing() @@ -91,10 +91,10 @@ object ScrollingUtils { ScrollDirection.TO_PLAYER -> { player } - ScrollDirection.TO_CHEST -> { + ScrollDirection.TO_CHEST -> { chest } - ScrollDirection.BOTH -> { + ScrollDirection.BOTH -> { chest } } @@ -120,13 +120,13 @@ object ScrollingUtils { val vanillaContainer = Vanilla.container() val source = when(direction) { - ScrollDirection.TO_CHEST -> { + ScrollDirection.TO_CHEST -> { player.getItemArea(vanillaContainer, slots) } ScrollDirection.TO_PLAYER -> { chest.getItemArea(vanillaContainer, slots) } - ScrollDirection.BOTH -> { + ScrollDirection.BOTH -> { (player + chest).getItemArea(vanillaContainer, slots) } } @@ -152,7 +152,7 @@ object ScrollingUtils { val (source, target) = when (direction) { - ScrollDirection.TO_CHEST -> if (!LockedSlotsSettings.LOCK_SLOTS_DISABLE_USER_INTERACTION.booleanValue + ScrollDirection.TO_CHEST -> if (!LockedSlotsSettings.LOCK_SLOTS_DISABLE_USER_INTERACTION.booleanValue && slotIndex in fullPlayer.getItemArea(vanillaContainer, slots).slotIndices) { Pair((player + focusedSlot).getItemArea(vanillaContainer, slots), @@ -162,7 +162,7 @@ object ScrollingUtils { targetIn.getItemArea(vanillaContainer, slots)) } - ScrollDirection.TO_PLAYER-> if (!LockedSlotsSettings.LOCK_SLOTS_DISABLE_USER_INTERACTION.booleanValue + ScrollDirection.TO_PLAYER -> if (!LockedSlotsSettings.LOCK_SLOTS_DISABLE_USER_INTERACTION.booleanValue && slotIndex in fullPlayer.getItemArea(vanillaContainer, slots).slotIndices) { Pair(chest.getItemArea(vanillaContainer, slots), @@ -172,7 +172,7 @@ object ScrollingUtils { targetIn.getItemArea(vanillaContainer, slots)) } - ScrollDirection.BOTH -> if (!LockedSlotsSettings.LOCK_SLOTS_DISABLE_USER_INTERACTION.booleanValue + ScrollDirection.BOTH -> if (!LockedSlotsSettings.LOCK_SLOTS_DISABLE_USER_INTERACTION.booleanValue && slotIndex in fullPlayer.getItemArea(vanillaContainer, slots).slotIndices) { Pair((player + focusedSlot + chest).getItemArea(vanillaContainer, slots), @@ -209,11 +209,11 @@ object ScrollingUtils { } private fun AreaTypes.doDefaultAction(direction: ScrollDirection, - slot: Slot, - targetIn: AreaType, - slots: List, - player: AreaType, - chest: AreaType) { + slot: Slot, + targetIn: AreaType, + slots: List, + player: AreaType, + chest: AreaType) { withFocusedItemFullStackDo(direction, slot, targetIn, slots, player, chest) { targetArea, source, itemType, slotIndex -> findSourceAndTargetAndDo(targetArea, source, slots, itemType, doLastSlotIndex = slotIndex) { sourceId, targetId -> ContainerClicker.leftClick(sourceId) @@ -430,8 +430,7 @@ object ScrollingUtils { } fun scrollSingleSpread(direction: ScrollDirection = ScrollDirection.TO_CHEST, - includeHotbar: Boolean = doIncludeHotbar - ) { + includeHotbar: Boolean = doIncludeHotbar) { var minCount = 65 withEnvironmentDo(direction, includeHotbar) { stack, target, slots, player, chest, _ -> if (stack.isEmpty()) { @@ -481,8 +480,8 @@ object ScrollingUtils { val source = when (direction) { ScrollDirection.TO_PLAYER -> chest - ScrollDirection.TO_CHEST -> player - ScrollDirection.BOTH -> player + chest + ScrollDirection.TO_CHEST -> player + ScrollDirection.BOTH -> player + chest }.getItemArea(vanillaContainer,slots) findSourceAndDo(source, slots, oldItemType) { sourceId -> @@ -710,6 +709,4 @@ object ScrollingUtils { action(sourceId) } } - - }