Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
CustomFOV
Browse files Browse the repository at this point in the history
Adds customizability for FOV setting, and option to prevent FOV changes through a mixin
  • Loading branch information
Kefpull committed Dec 2, 2024
1 parent 26711b5 commit 0a7545f
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@


import com.google.common.base.Predicates;
import keystrokesmod.module.ModuleManager;
import keystrokesmod.module.impl.render.CustomFOV;
import keystrokesmod.module.impl.other.RotationHandler;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.EntityRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItemFrame;
import net.minecraft.util.*;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.List;

Expand Down Expand Up @@ -111,4 +115,26 @@ public void getMouseOver(float p_getMouseOver_1_, CallbackInfo ci) {

ci.cancel();
}


/**
* @author kefpull
* @reason attempt 1 have an option for CustomFOV to do the same thing as optifine's "Dynamic FOV:off". Hopefully this does not break the whole entire client :).
* I know we're supposed to use an event or something like that, so I will do that if I can.
* <p>
* Source for method: line 412 in EntityRenderer.class
*/
@Inject(method = "getFOVModifier", at = @At("RETURN"), cancellable = true)
public void onGetFOVModifier(@NotNull CallbackInfoReturnable<Float> cir) {

if (ModuleManager.customFOV != null && ModuleManager.customFOV.forceStatic != null) {

if (ModuleManager.customFOV.isEnabled() && ModuleManager.customFOV.forceStatic.isToggled()) {
cir.setReturnValue(CustomFOV.getDesiredFOV());
}

}
}


}
2 changes: 2 additions & 0 deletions src/main/java/keystrokesmod/module/ModuleManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class ModuleManager {
public static NoCameraClip noCameraClip;
public static AutoPlay autoPlay;
public static CustomName customName;
public static CustomFOV customFOV;
public static CommandChat commandChat;
public static Phase phase;
public static PingSpoof pingSpoof;
Expand Down Expand Up @@ -272,6 +273,7 @@ public void register() {
this.addModule(new ChestESP());
this.addModule(customCape = new CustomCape());
this.addModule(customName = new CustomName());
this.addModule(customFOV = new CustomFOV());
this.addModule(freeLook = new FreeLook());
this.addModule(fullBright = new FullBright());
this.addModule(hud = new HUD());
Expand Down
70 changes: 70 additions & 0 deletions src/main/java/keystrokesmod/module/impl/render/CustomFOV.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package keystrokesmod.module.impl.render;


//import keystrokesmod.event.FOVUpdateEvent;
import keystrokesmod.module.Module;
import keystrokesmod.module.setting.impl.ButtonSetting;
import keystrokesmod.module.setting.impl.DescriptionSetting;
import keystrokesmod.module.setting.impl.SliderSetting;
import keystrokesmod.utility.Utils;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import org.jetbrains.annotations.NotNull;
import net.minecraftforge.client.event.FOVUpdateEvent;


public class CustomFOV extends Module {

private static final SliderSetting baseFOV = new SliderSetting("FOV: ", 70, 1, 179, 1);
public final ButtonSetting forceStatic = new ButtonSetting("Static", false);


private float savedFOVSetting = 70.0F;
public CustomFOV() {
super("CustomFOV", category.render, "Allows you to change FOV beyond Minecraft defaults");
//this.registerSetting(new DescriptionSetting("Currently very broken"));
this.registerSetting(baseFOV);
this.registerSetting(forceStatic);
// line wrapping in the future, maybe?
this.registerSetting(new DescriptionSetting("Note that \"static\" also"));
this.registerSetting(new DescriptionSetting("affects the viewmodel and"));
this.registerSetting(new DescriptionSetting("anything like zoom."));
}

public static float getDesiredFOV() {
return (float) baseFOV.getInput();
}

public void onEnable() {

savedFOVSetting = mc.gameSettings.fovSetting;
Utils.sendMessage("Saved FOV as: " + savedFOVSetting);
}

public void onDisable() {
mc.gameSettings.fovSetting = savedFOVSetting;
Utils.sendMessage("Loaded FOV as: " + savedFOVSetting);
}
@SubscribeEvent(priority = EventPriority.LOWEST)
public void onUpdate() {

mc.gameSettings.fovSetting = (float) baseFOV.getInput();

}

public void onFOVChange(@NotNull FOVUpdateEvent event) {
Utils.sendMessage("FOV Change");
if(forceStatic.isToggled()){
Utils.sendMessage("FOV Change");
}
}


/* public static class DesiredFOV {
public final float DesiredFOV = (float) baseFOV.getInput();
}
*/
}

0 comments on commit 0a7545f

Please sign in to comment.