How to change FOV? (using code)

Started by Gabriele007 on

Topic category: Help with Minecraft modding (Java Edition)

Joined Sep 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to change FOV? (using code)

Can someone teach me how to change fov using code? I saw i can use the FOVUpdateEvent but i'm having trouble using it. For the contex, I want to do a keybind that checks if i have a sniper in my hand, and if so it changes the fov.

Joined Aug 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Don't use Better procedure s…
Thu, 12/02/2021 - 17:42

Don't use Better procedure s. It simply causes more problems and crashes.

Joined Sep 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Yeah i tried that and got…
Thu, 12/02/2021 - 19:14

Yeah i tried that and got many error while building, so the only way is to use FOVUpdateEvent

Joined Mar 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I found this on the forge…
Sat, 12/18/2021 - 04:07

I found this on the forge website

net.minecraftforge.client.event,FOVUpdateEvent allows you to set a new FOV using FOVUpdateEvent#setNewfov. Alternatively there exists net.minecraftforge.client.event.EntityViewRenderEvent.FOVModifier which allows you to set a modifier for the player's FOV instead of altering it directly via FOVModifier#setFOV

Joined Sep 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I found this on the forge…
Mon, 12/27/2021 - 19:18

I found this on the forge website

So i finally managed to change fov but the problem is that  the modifier is always "active", it ignores my conditions, here is my code:

import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.client.event.FOVUpdateEvent;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;

@Mod.EventBusSubscriber
public class SniperFOV {
    @SubscribeEvent
    public static void ChangeFOV(FOVUpdateEvent event) {
        event.setNewfov(0.1f);
    }
}