Skip to content

Commit

Permalink
Feature: Inventory Focus Mode (#2694)
Browse files Browse the repository at this point in the history
Co-authored-by: jani270 <69345714+jani270@users.noreply.github.com>
  • Loading branch information
Thunderblade73 and jani270 authored Oct 9, 2024
1 parent 4c7409c commit 6b01ce6
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 2 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6b01ce6

Please sign in to comment.