Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Custom Zoom Key


Recommended Posts

To make a zoom key, you need to add some event listeners. We can do it this way. Here is the event listener code:

@SubscribeEvent
public static void onFovChange(FOVUpdateEvent fovEvent) {
    // Update the original FOV variable
    if(YourMainClass.originalFov != fovEvent.getNewfov() && fovEvent.getNewfov() != YourMainClass.zoomedInFOV)
        YourMainClass.originalFov=fovEvent.getNewfov();
}

@SubscribeEvent
public static void onKeyPress(KeyboardKeyPressedEvent keyEvent) {
    if(keyEvent.getKeyCode()==YourMainClass.zoomKeyCode)
            YourMainClass.mc.gameSettings.fov=YourMainClass.zoomedInFOV;
}
    
@SubscribeEvent
public static void onKeyRelease(KeyboardKeyReleasedEvent keyEvent) {
    if(keyEvent.getKeyCode()==YourMainClass.zoomKeyCode)
            YourMainClass.mc.gameSettings.fov=YourMainClass.originalFov;
}

 

Now we need to define some variables in our main class. This is the code:

public static Minecraft mc=Minecraft.getInstance();

public final static int zoomKeyCode=GLFW.GLFW_KEY_(key here);
public final static int zoomedInFOV=40;

// The next line of code goes in the FMLCommonSetupEvent event function

originalFov=mcInstance.gameSettings.fov;

 

Wait, we also need to register some events. If you are making the SubscribeEvent functions static, you can do it with this:

MinecraftForge.EVENT_BUS.register(YourEventListener.class)

 

If you are making the SubscribeEvent functions non-static, you can do it with this:

MinecraftForge.EVENT_BUS.register(new YourEventListener())

 

There we go! This is a custom zoom key.

Edited by andrussy44
Make it meet the "tutorial requirements". For example, I used "wee
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.