diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2024-09-21 10:32:43 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2024-09-21 10:32:43 +0200 |
commit | f056eb5a458ae95dff2cdbd84217e491f72a3d06 (patch) | |
tree | 25abff74b164f49e88d736d0b49f52ccdf95e801 | |
parent | 1da7050a5b95e6e1cf0111c3a71b042168d3918e (diff) | |
download | skyhanni-f056eb5a458ae95dff2cdbd84217e491f72a3d06.tar.gz skyhanni-f056eb5a458ae95dff2cdbd84217e491f72a3d06.tar.bz2 skyhanni-f056eb5a458ae95dff2cdbd84217e491f72a3d06.zip |
MiningCommissionsBlocksColor.processState
3 files changed, 32 insertions, 54 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 + } + } } diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/hooks/BlockRendererDispatcherHook.kt b/src/main/java/at/hannibal2/skyhanni/mixins/hooks/BlockRendererDispatcherHook.kt index f72d56739..cf4e4ba40 100644 --- a/src/main/java/at/hannibal2/skyhanni/mixins/hooks/BlockRendererDispatcherHook.kt +++ b/src/main/java/at/hannibal2/skyhanni/mixins/hooks/BlockRendererDispatcherHook.kt @@ -1,10 +1,6 @@ package at.hannibal2.skyhanni.mixins.hooks import at.hannibal2.skyhanni.features.mining.MiningCommissionsBlocksColor -import at.hannibal2.skyhanni.features.mining.MiningCommissionsBlocksColor.CommissionBlock.Companion.onColor -import at.hannibal2.skyhanni.features.mining.MiningCommissionsBlocksColor.replaceBlocksMapCache -import at.hannibal2.skyhanni.features.mining.OreType.Companion.isOreType -import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.LorenzUtils import net.minecraft.block.state.IBlockState import net.minecraft.client.renderer.BlockRendererDispatcher @@ -21,24 +17,13 @@ fun modifyGetModelFromBlockState( pos: BlockPos?, cir: CallbackInfoReturnable<IBakedModel>, ) { - if (state == null || pos == null) return - var returnState: IBlockState = state + if (pos == null) return if (!LorenzUtils.inSkyBlock) return - try { - if (MiningCommissionsBlocksColor.enabled && MiningCommissionsBlocksColor.active) { - returnState = replaceBlocksMapCache.getOrPut(state) { - MiningCommissionsBlocksColor.CommissionBlock.entries.firstOrNull { - state.isOreType(it.oreType) - }?.onColor(state) ?: state - } - } - } catch (e: Exception) { - ErrorManager.logErrorWithData(e, "Error in MiningCommissionsBlocksColor") - } + val returnState = MiningCommissionsBlocksColor.processState(state) - if (returnState !== state) { + if (returnState != state) { cir.returnValue = blockRendererDispatcher.blockModelShapes.getModelForState(returnState) } } diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/hooks/OptifineConnectedTexturesHook.kt b/src/main/java/at/hannibal2/skyhanni/mixins/hooks/OptifineConnectedTexturesHook.kt index f930e1008..fe4619cf2 100644 --- a/src/main/java/at/hannibal2/skyhanni/mixins/hooks/OptifineConnectedTexturesHook.kt +++ b/src/main/java/at/hannibal2/skyhanni/mixins/hooks/OptifineConnectedTexturesHook.kt @@ -1,35 +1,11 @@ package at.hannibal2.skyhanni.mixins.hooks import at.hannibal2.skyhanni.features.mining.MiningCommissionsBlocksColor -import at.hannibal2.skyhanni.features.mining.MiningCommissionsBlocksColor.CommissionBlock.Companion.onColor -import at.hannibal2.skyhanni.features.mining.MiningCommissionsBlocksColor.replaceBlocksMapCache -import at.hannibal2.skyhanni.features.mining.OreType.Companion.isOreType -import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.LorenzUtils import net.minecraft.block.state.IBlockState -fun modifyConnectedTexturesBlockState(state: IBlockState): IBlockState { - if (state == null) return state - var returnState: IBlockState = state - +fun modifyConnectedTexturesBlockState(state: IBlockState?): IBlockState? { if (!LorenzUtils.inSkyBlock) return state - - try { - if (MiningCommissionsBlocksColor.enabled && MiningCommissionsBlocksColor.active) { - returnState = replaceBlocksMapCache.getOrPut(state) { - MiningCommissionsBlocksColor.CommissionBlock.entries.firstOrNull { - state.isOreType(it.oreType) - }?.onColor(state) ?: state - } - } - } catch (e: Exception) { - ErrorManager.logErrorWithData(e, "Error in MiningCommissionsBlocksColor") - } - - if (returnState !== state) { - - return returnState - } - return state + return MiningCommissionsBlocksColor.processState(state) } |