Move the okzoomer-related functions and variables to a new file named OkZoomerCompat.kt
This commit is contained in:
parent
8724a3d755
commit
93877b14cb
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue