diff --git a/fabric/src/main/java/fr/username404/snowygui/mixins/OkZoomerAlternativeMixin.java b/fabric/src/main/java/fr/username404/snowygui/mixins/OkZoomerAlternativeMixin.java index bd63608..8011d55 100644 --- a/fabric/src/main/java/fr/username404/snowygui/mixins/OkZoomerAlternativeMixin.java +++ b/fabric/src/main/java/fr/username404/snowygui/mixins/OkZoomerAlternativeMixin.java @@ -1,6 +1,6 @@ package fr.username404.snowygui.mixins; -import fr.username404.snowygui.fabric.FabricInitKt; +import fr.username404.snowygui.fabric.OkZoomerCompatKt; import fr.username404.snowygui.gui.feature.Zoom; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -15,8 +15,8 @@ abstract class OkZoomerAlternativeMixin { */ @Inject(remap = false, at = @At("HEAD"), method = "execAction", cancellable = true) public void execAction(CallbackInfo ci) { - if (FabricInitKt.isOkZoomerPresent) { - FabricInitKt.fabricZoom(); + if (OkZoomerCompatKt.isOkZoomerPresent) { + OkZoomerCompatKt.fabricZoom(); } } } diff --git a/fabric/src/main/java/fr/username404/snowygui/mixins/ZoomMixin.java b/fabric/src/main/java/fr/username404/snowygui/mixins/ZoomMixin.java index 283f5c4..4bc25d2 100644 --- a/fabric/src/main/java/fr/username404/snowygui/mixins/ZoomMixin.java +++ b/fabric/src/main/java/fr/username404/snowygui/mixins/ZoomMixin.java @@ -1,6 +1,6 @@ package fr.username404.snowygui.mixins; -import fr.username404.snowygui.fabric.FabricInitKt; +import fr.username404.snowygui.fabric.OkZoomerCompatKt; import fr.username404.snowygui.gui.feature.Zoom; import net.minecraft.client.Camera; import net.minecraft.client.renderer.GameRenderer; @@ -13,7 +13,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; abstract class ZoomMixin { @Inject(at = @At(value = "RETURN"), method = "getFov(Lnet/minecraft/client/Camera;FZ)D", cancellable = true) private void getFov(Camera camera, float f, boolean bl, CallbackInfoReturnable cir) { - if (Zoom.INSTANCE.getToggled() && !FabricInitKt.isOkZoomerPresent) { + if (Zoom.INSTANCE.getToggled() && !OkZoomerCompatKt.isOkZoomerPresent) { cir.setReturnValue(Zoom.getNewZoom(cir.getReturnValue())); } } diff --git a/fabric/src/main/kotlin/fr/username404/snowygui/fabric/FabricInit.kt b/fabric/src/main/kotlin/fr/username404/snowygui/fabric/FabricInit.kt index df96082..a61d956 100644 --- a/fabric/src/main/kotlin/fr/username404/snowygui/fabric/FabricInit.kt +++ b/fabric/src/main/kotlin/fr/username404/snowygui/fabric/FabricInit.kt @@ -4,7 +4,6 @@ import com.mojang.blaze3d.vertex.PoseStack import fr.username404.snowygui.EventSnowy import fr.username404.snowygui.Snowy import fr.username404.snowygui.gui.feature.ButtonImpl -import fr.username404.snowygui.gui.feature.Zoom import net.fabricmc.api.ClientModInitializer import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback.EVENT @@ -40,31 +39,4 @@ class FabricInit: Snowy(), ClientModInitializer { classSet }.toSet() } -} - -@JvmField -var isOkZoomerPresent: Boolean = FabricLoader.getInstance().isModLoaded("okzoomer") -private val okZoomerPairs by lazy { - try { - with(Class.forName("io.github.joaoh1.okzoomer.client.utils.ZoomUtils")) { - (getField("zoomDivisor") to null) to (getField("zoomState") to null) - } - } catch (e: ClassNotFoundException) { - with(Class.forName("io.github.ennuil.okzoomer.utils.ZoomUtils").getDeclaredField("zoomerZoom")) { - get(null).javaClass.run { - (getDeclaredField("zoomDivisor") to this@with.get(null)) to (getDeclaredField("zoom") to this@with.get(null)) - } - } - }.apply { first.first.isAccessible = true; second.first.isAccessible = true; } -} - -fun fabricZoom() { - try { - with(okZoomerPairs) { - first.run { first.setDouble(second, Zoom.zoomFactor) } - second.run { first.setBoolean(second, Zoom.toggled) } - } - } catch (e: Exception) { - isOkZoomerPresent = false - } } \ No newline at end of file diff --git a/fabric/src/main/kotlin/fr/username404/snowygui/fabric/OkZoomerCompat.kt b/fabric/src/main/kotlin/fr/username404/snowygui/fabric/OkZoomerCompat.kt new file mode 100644 index 0000000..21ddc48 --- /dev/null +++ b/fabric/src/main/kotlin/fr/username404/snowygui/fabric/OkZoomerCompat.kt @@ -0,0 +1,31 @@ +package fr.username404.snowygui.fabric + +import fr.username404.snowygui.gui.feature.Zoom +import net.fabricmc.loader.api.FabricLoader + +@JvmField +var isOkZoomerPresent: Boolean = FabricLoader.getInstance().isModLoaded("okzoomer") +private val okZoomerPairs by lazy { + try { + with(Class.forName("io.github.joaoh1.okzoomer.client.utils.ZoomUtils")) { + (getField("zoomDivisor") to null) to (getField("zoomState") to null) + } + } catch (e: ClassNotFoundException) { + with(Class.forName("io.github.ennuil.okzoomer.utils.ZoomUtils").getDeclaredField("zoomerZoom")) { + get(null).javaClass.run { + (getDeclaredField("zoomDivisor") to this@with.get(null)) to (getDeclaredField("zoom") to this@with.get(null)) + } + } + }.apply { first.first.isAccessible = true; second.first.isAccessible = true; } +} + +fun fabricZoom() { + try { + with(okZoomerPairs) { + first.run { first.setDouble(second, Zoom.zoomFactor) } + second.run { first.setBoolean(second, Zoom.toggled) } + } + } catch (e: Exception) { + isOkZoomerPresent = false + } +} \ No newline at end of file