Move the okzoomer-related functions and variables to a new file named OkZoomerCompat.kt

This commit is contained in:
Username404 2021-07-16 16:37:33 +02:00
parent 8724a3d755
commit 93877b14cb
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
4 changed files with 36 additions and 33 deletions

View File

@ -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();
}
}
}

View File

@ -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<Double> cir) {
if (Zoom.INSTANCE.getToggled() && !FabricInitKt.isOkZoomerPresent) {
if (Zoom.INSTANCE.getToggled() && !OkZoomerCompatKt.isOkZoomerPresent) {
cir.setReturnValue(Zoom.getNewZoom(cir.getReturnValue()));
}
}

View File

@ -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
}
}

View File

@ -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
}
}