From 1da7050a5b95e6e1cf0111c3a71b042168d3918e Mon Sep 17 00:00:00 2001 From: NopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com> Date: Sat, 21 Sep 2024 18:31:34 +1000 Subject: Make Mining Commissions Blocks Colour actually work with connected textures instead of just turning them off 🙂 (#2559) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mixins/hooks/OptifineConnectedTexturesHook.kt | 35 ++++++++++++++++++++++ .../mixins/transformers/MixinOptifineConfig.java | 18 ----------- .../MixinOptifineConnectedTextures.java | 23 ++++++++++++++ 3 files changed, 58 insertions(+), 18 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/mixins/hooks/OptifineConnectedTexturesHook.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinOptifineConfig.java create mode 100644 src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinOptifineConnectedTextures.java (limited to 'src/main/java/at') diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/hooks/OptifineConnectedTexturesHook.kt b/src/main/java/at/hannibal2/skyhanni/mixins/hooks/OptifineConnectedTexturesHook.kt new file mode 100644 index 000000000..f930e1008 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/mixins/hooks/OptifineConnectedTexturesHook.kt @@ -0,0 +1,35 @@ +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 + + 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 +} + diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinOptifineConfig.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinOptifineConfig.java deleted file mode 100644 index 97b20f19a..000000000 --- a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinOptifineConfig.java +++ /dev/null @@ -1,18 +0,0 @@ -package at.hannibal2.skyhanni.mixins.transformers; - -import at.hannibal2.skyhanni.features.mining.MiningCommissionsBlocksColor; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Pseudo; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Pseudo -@Mixin(targets = "Config", remap = false) -public class MixinOptifineConfig { - - @Inject(method = {"isConnectedTextures", "isConnectedTexturesFancy"}, at = @At("HEAD"), cancellable = true) - private static void isConnectedTextures(CallbackInfoReturnable cir) { - if (MiningCommissionsBlocksColor.INSTANCE.getActive()) cir.setReturnValue(false); - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinOptifineConnectedTextures.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinOptifineConnectedTextures.java new file mode 100644 index 000000000..9f3087e8e --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinOptifineConnectedTextures.java @@ -0,0 +1,23 @@ +package at.hannibal2.skyhanni.mixins.transformers; + +import at.hannibal2.skyhanni.mixins.hooks.OptifineConnectedTexturesHookKt; +import net.minecraft.block.state.IBlockState; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Pseudo; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyArg; + +@Pseudo +@Mixin(targets = "net.optifine.ConnectedTextures", remap = false) +public class MixinOptifineConnectedTextures { + + @ModifyArg(method = "getConnectedTexture", at = @At(value = "INVOKE", target = "getConnectedTextureMultiPass")) + private static IBlockState modifyGetConnectedTextureMultiPass(IBlockState state) { + return OptifineConnectedTexturesHookKt.modifyConnectedTexturesBlockState(state); + } + + @ModifyArg(method = "getConnectedTexture", at = @At(value = "INVOKE", target = "skipConnectedTexture")) + private static IBlockState modifySkipConnectedTexture(IBlockState state) { + return OptifineConnectedTexturesHookKt.modifyConnectedTexturesBlockState(state); + } +} -- cgit