Add Ok Zoomer compatibility
This commit is contained in:
parent
9df48959b5
commit
4bc41e3b38
|
@ -5,8 +5,8 @@ import net.minecraft.client.Minecraft
|
|||
|
||||
@ButtonInfo(Category.MISC, shouldSave = false)
|
||||
object Zoom: ButtonImpl() {
|
||||
internal var smoothCameraOnZoom: Boolean by Configuration
|
||||
internal var zoomFactor: Double by Configuration
|
||||
var smoothCameraOnZoom: Boolean by Configuration
|
||||
var zoomFactor: Double by Configuration
|
||||
@JvmStatic
|
||||
fun getNewZoom(fov: Double): Double = fov / zoomFactor
|
||||
public override fun execAction() {
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package fr.username404.snowygui.mixins;
|
||||
|
||||
import fr.username404.snowygui.fabric.FabricInitKt;
|
||||
import fr.username404.snowygui.gui.feature.Zoom;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(Zoom.class)
|
||||
abstract class OkZoomerAlternativeMixin {
|
||||
/**
|
||||
* @author Username404
|
||||
* @reason Needed to use the Ok Zoomer mod when it is present
|
||||
*/
|
||||
@Inject(remap = false, at = @At("HEAD"), method = "execAction", cancellable = true)
|
||||
public void execAction(CallbackInfo ci) {
|
||||
if (FabricInitKt.isOkZoomerPresent) {
|
||||
FabricInitKt.fabricZoom();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package fr.username404.snowygui.mixins;
|
||||
|
||||
import fr.username404.snowygui.fabric.FabricInitKt;
|
||||
import fr.username404.snowygui.gui.feature.Zoom;
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
|
@ -12,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()) {
|
||||
if (Zoom.INSTANCE.getToggled() && !FabricInitKt.isOkZoomerPresent) {
|
||||
cir.setReturnValue(Zoom.getNewZoom(cir.getReturnValue()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ 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
|
||||
|
@ -39,4 +40,31 @@ 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 {
|
||||
(getField("zoomDivisor") to this@with) to (getField("zoom") to this@with)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun fabricZoom() {
|
||||
try {
|
||||
with(okZoomerPairs) {
|
||||
first.run { first.setDouble(second, Zoom.zoomFactor) }
|
||||
second.run { first.setBoolean(second, Zoom.toggled) }
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
isOkZoomerPresent = false
|
||||
}
|
||||
}
|
|
@ -3,7 +3,8 @@
|
|||
"package": "fr.username404.snowygui.mixins",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"client": [
|
||||
"ZoomMixin"
|
||||
"ZoomMixin",
|
||||
"OkZoomerAlternativeMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
|
Loading…
Reference in New Issue