aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features/mining
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2024-09-21 10:32:43 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2024-09-21 10:32:43 +0200
commitf056eb5a458ae95dff2cdbd84217e491f72a3d06 (patch)
tree25abff74b164f49e88d736d0b49f52ccdf95e801 /src/main/java/at/hannibal2/skyhanni/features/mining
parent1da7050a5b95e6e1cf0111c3a71b042168d3918e (diff)
downloadskyhanni-f056eb5a458ae95dff2cdbd84217e491f72a3d06.tar.gz
skyhanni-f056eb5a458ae95dff2cdbd84217e491f72a3d06.tar.bz2
skyhanni-f056eb5a458ae95dff2cdbd84217e491f72a3d06.zip
MiningCommissionsBlocksColor.processState
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/mining')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/mining/MiningCommissionsBlocksColor.kt37
1 files changed, 27 insertions, 10 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/MiningCommissionsBlocksColor.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/MiningCommissionsBlocksColor.kt
index 5eaff2b44..5de75e5d1 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/mining/MiningCommissionsBlocksColor.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/mining/MiningCommissionsBlocksColor.kt
@@ -10,7 +10,10 @@ import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
import at.hannibal2.skyhanni.events.TabListUpdateEvent
+import at.hannibal2.skyhanni.features.mining.MiningCommissionsBlocksColor.CommissionBlock.Companion.onColor
+import at.hannibal2.skyhanni.features.mining.OreType.Companion.isOreType
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
+import at.hannibal2.skyhanni.test.command.ErrorManager
import at.hannibal2.skyhanni.utils.ConditionalUtils.onToggle
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.TimeLimitedSet
@@ -28,8 +31,8 @@ object MiningCommissionsBlocksColor {
private val config get() = SkyHanniMod.feature.mining.commissionsBlocksColor
- var enabled = false
- var active = false
+ private var enabled = false
+ private var active = false
private val patternGroup = RepoPattern.group("mining.commissions")
@@ -41,14 +44,13 @@ object MiningCommissionsBlocksColor {
"§a§l(?<name>.*) §r§eCommission Complete! Visit the King §r§eto claim your rewards!",
)
- var color: EnumDyeColor = EnumDyeColor.RED
+ private var color = EnumDyeColor.RED
- private fun glass(state: IBlockState, result: Boolean): IBlockState =
- if (result) {
- state.withProperty(BlockCarpet.COLOR, color)
- } else {
- state.withProperty(BlockCarpet.COLOR, EnumDyeColor.GRAY)
- }
+ private fun glass(state: IBlockState, result: Boolean): IBlockState = if (result) {
+ state.withProperty(BlockCarpet.COLOR, color)
+ } else {
+ state.withProperty(BlockCarpet.COLOR, EnumDyeColor.GRAY)
+ }
private fun block(result: Boolean): IBlockState {
val wool = Blocks.wool.defaultState
@@ -64,7 +66,7 @@ object MiningCommissionsBlocksColor {
private var dirty = false
private var forceDirty = false
- var replaceBlocksMapCache = mutableMapOf<IBlockState, IBlockState>()
+ private var replaceBlocksMapCache = mutableMapOf<IBlockState, IBlockState>()
// TODO Commission API
@SubscribeEvent
@@ -244,4 +246,19 @@ object MiningCommissionsBlocksColor {
if (oreType.isGemstone()) glass(state, highlight) else block(highlight)
}
}
+
+ fun processState(state: IBlockState?): IBlockState? {
+ if (!enabled || !active) return state
+ if (state == null) return null
+ try {
+ return replaceBlocksMapCache.getOrPut(state) {
+ CommissionBlock.entries.firstOrNull {
+ state.isOreType(it.oreType)
+ }?.onColor(state) ?: state
+ }
+ } catch (e: Exception) {
+ ErrorManager.logErrorWithData(e, "Error in MiningCommissionsBlocksColor")
+ return state
+ }
+ }
}