From 6b01ce6c00663b929893e091646971e71becc3be Mon Sep 17 00:00:00 2001 From: Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> Date: Wed, 9 Oct 2024 13:28:21 +0200 Subject: Feature: Inventory Focus Mode (#2694) Co-authored-by: jani270 <69345714+jani270@users.noreply.github.com> --- .../config/features/inventory/FocusModeConfig.java | 22 ++++++++++++++ .../config/features/inventory/InventoryConfig.java | 5 ++++ .../skyhanni/features/inventory/FocusMode.kt | 35 ++++++++++++++++++++++ .../at/hannibal2/skyhanni/utils/InventoryUtils.kt | 2 ++ 4 files changed, 64 insertions(+) create mode 100644 src/main/java/at/hannibal2/skyhanni/config/features/inventory/FocusModeConfig.java create mode 100644 src/main/java/at/hannibal2/skyhanni/features/inventory/FocusMode.kt (limited to 'src') diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/FocusModeConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/FocusModeConfig.java new file mode 100644 index 000000000..3211354fe --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/FocusModeConfig.java @@ -0,0 +1,22 @@ +package at.hannibal2.skyhanni.config.features.inventory; + +import at.hannibal2.skyhanni.config.FeatureToggle; +import com.google.gson.annotations.Expose; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorKeybind; +import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; +import org.lwjgl.input.Keyboard; + +public class FocusModeConfig { + + @Expose + @ConfigOption(name = "Enabled", desc = "In focus mode you only see the name of the item instead of the whole description.") + @ConfigEditorBoolean + @FeatureToggle + public boolean enabled = false; + + @Expose + @ConfigOption(name = "Toggle Key", desc = "Key to toggle the focus mode on and off.") + @ConfigEditorKeybind(defaultKey = Keyboard.KEY_NONE) + public int toggleKey = Keyboard.KEY_NONE; +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/InventoryConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/InventoryConfig.java index 6e064ced6..71ab7c792 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/InventoryConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/InventoryConfig.java @@ -84,6 +84,11 @@ public class InventoryConfig { @Accordion public PersonalCompactorConfig personalCompactor = new PersonalCompactorConfig(); + @Expose + @ConfigOption(name = "Focus Mode", desc="") + @Accordion + public FocusModeConfig focusMode = new FocusModeConfig(); + @Expose @ConfigOption(name = "RNG Meter", desc = "") @Accordion diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/FocusMode.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/FocusMode.kt new file mode 100644 index 000000000..c02f29933 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/FocusMode.kt @@ -0,0 +1,35 @@ +package at.hannibal2.skyhanni.features.inventory + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.LorenzTickEvent +import at.hannibal2.skyhanni.events.LorenzToolTipEvent +import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.utils.InventoryUtils +import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyClicked +import at.hannibal2.skyhanni.utils.LorenzUtils +import net.minecraftforge.fml.common.eventhandler.EventPriority +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +@SkyHanniModule +object FocusMode { + + private val config get() = SkyHanniMod.feature.inventory.focusMode + + private var toggle = true + + @SubscribeEvent(priority = EventPriority.LOWEST) + fun onLorenzToolTip(event: LorenzToolTipEvent) { + if (!isEnabled() || !toggle) return + if(event.toolTip.isEmpty()) return + event.toolTip = mutableListOf(event.toolTip.first()) + } + + @SubscribeEvent + fun onLorenzTick(event: LorenzTickEvent) { + if (!isEnabled()) return + if (!config.toggleKey.isKeyClicked()) return + toggle = !toggle + } + + fun isEnabled() = LorenzUtils.inSkyBlock && InventoryUtils.inContainer() && config.enabled +} diff --git a/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt index 7ff17f965..0f025e50b 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt @@ -41,6 +41,8 @@ object InventoryUtils { fun inInventory() = Minecraft.getMinecraft().currentScreen is GuiChest + fun inContainer() = Minecraft.getMinecraft().currentScreen is GuiContainer + fun ContainerChest.getInventoryName() = this.lowerChestInventory.displayName.unformattedText.trim() fun getWindowId(): Int? = (Minecraft.getMinecraft().currentScreen as? GuiChest)?.inventorySlots?.windowId -- cgit