diff options
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/misc/ChestValue.kt | 40 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/RecalculatingValue.kt | 16 |
2 files changed, 42 insertions, 14 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/ChestValue.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/ChestValue.kt index cced77692..f603734f8 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/ChestValue.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/ChestValue.kt @@ -24,6 +24,7 @@ import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.awt.Color import java.io.File +import kotlin.time.Duration.Companion.seconds class ChestValue { @@ -123,7 +124,8 @@ class ChestValue { text, tips, stack = stack, - indexes = index) + indexes = index + ) add(" ยง7- ") if (config.showStacks) add(stack) add(renderable) @@ -221,19 +223,29 @@ class ChestValue { COMPACT("Aligned") } - private fun String.isValidStorage() = Minecraft.getMinecraft().currentScreen is GuiChest && (( - this == "Chest" || - this == "Large Chest") || - (contains("Minion") && !contains("Recipe") && LorenzUtils.skyBlockIsland == IslandType.PRIVATE_ISLAND) || - this == "Personal Vault") || - ((contains("Backpack") && contains("Slot #") || startsWith("Ender Chest (")) - && !isNeuStorageEnabled()) - - private fun isNeuStorageEnabled(): Boolean { - val file = File(OtherMod.NEU.configPath) - if (!file.exists()) return false - return ConfigManager.gson.fromJson(APIUtil.readFile(File(OtherMod.NEU.configPath)), - com.google.gson.JsonObject::class.java)["storageGUI"].asJsonObject["enableStorageGUI3"].asBoolean + private fun String.isValidStorage(): Boolean { + if (Minecraft.getMinecraft().currentScreen !is GuiChest) return false + + if ((contains("Backpack") && contains("Slot #") || startsWith("Ender Chest (")) && + !isNeuStorageEnabled.getValue() + ) { + return true + } + + val inMinion = contains("Minion") && !contains("Recipe") && + LorenzUtils.skyBlockIsland == IslandType.PRIVATE_ISLAND + return this == "Chest" || this == "Large Chest" || inMinion || this == "Personal Vault" + } + + private val isNeuStorageEnabled = RecalculatingValue(1.seconds) { + val configPath = OtherMod.NEU.configPath + if (File(configPath).exists()) { + val json = ConfigManager.gson.fromJson( + APIUtil.readFile(File(configPath)), + com.google.gson.JsonObject::class.java + ) + json["storageGUI"].asJsonObject["enableStorageGUI3"].asBoolean + } else false } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/RecalculatingValue.kt b/src/main/java/at/hannibal2/skyhanni/utils/RecalculatingValue.kt new file mode 100644 index 000000000..7c734c57e --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/utils/RecalculatingValue.kt @@ -0,0 +1,16 @@ +package at.hannibal2.skyhanni.utils + +import kotlin.time.Duration + +class RecalculatingValue<T>(private val expireTime: Duration, val calculation: () -> T) { + private var currentValue = calculation() + private var lastAccessTime = SimpleTimeMark.farPast() + + fun getValue(): T { + if (lastAccessTime.passedSince() > expireTime) { + currentValue = calculation() + lastAccessTime = SimpleTimeMark.now() + } + return currentValue + } +}
\ No newline at end of file |