How to change FOV? (using code)

Started by Gabriele007 on

Topic category: Help with modding (Java Edition)

Last seen on 15:14, 17. Apr 2024
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.

Last seen on 15:14, 17. Apr 2024
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

Last seen on 13:58, 21. Jan 2023
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

Last seen on 15:14, 17. Apr 2024
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);
    }
}