How to change FOV? (using code)

Started by Gabriele007 on

Topic category: Help with Minecraft modding (Java Edition)

Active 1 year ago
Joined Sep 2021
Points:
594

User statistics:

  • Modifications: 3
  • Forum topics: 7
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 16
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.

Active 1 week ago
Joined Aug 2016
Points:
3304

User statistics:

  • Modifications: 9
  • Forum topics: 63
  • Wiki pages: 20
  • MCreator plugins: 11
  • Comments: 2927
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.

Active 1 year ago
Joined Sep 2021
Points:
594

User statistics:

  • Modifications: 3
  • Forum topics: 7
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 16
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

Active 2 years ago
Joined Mar 2021
Points:
684

User statistics:

  • Modifications: 0
  • Forum topics: 4
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 190
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

Active 1 year ago
Joined Sep 2021
Points:
594

User statistics:

  • Modifications: 3
  • Forum topics: 7
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 16
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);
    }
}