[Tutorial]2024.4 Sniper Zoom In Out Code

Started by dkrdjdi on

Topic category: User side tutorials

Joined May 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
[Tutorial]2024.4 Sniper Zoom In Out Code
Fri, 01/17/2025 - 06:31 (edited)

Since using the Slowness Potion to implement the zoom function is simpler,

I would appreciate it if you watch this tutorial just for fun. :)
*Of course, adjusting the FOV value directly through code gives better zooming effect

 

The completed version looks like this.

https://imgur.com/6VRyV2o

 

Step1. I will create keybindings.

https://imgur.com/TtoPdOd

 

Step2. Zoom-in procedure.

https://imgur.com/jNwArGq

The trigger below is temporarily added and will be removed later in the code.

 

Step3. Zoom-out procedure.

https://imgur.com/TP02oQt

 

Step4. Zoom-in procedure Code.


import net.minecraft.client.Minecraft; //add
import net.minecraft.world.entity.player.Player; //add
import net.minecraft.client.Options; //add

public class ZoomInProcedure {
public static void execute(Entity entity) {
if (entity == null)
return;
if ((entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getItem() == TestModItems.SNIPER.get()) {

entity.setTicksFrozen(0); //delete code
Player player = Minecraft.getInstance().player; //add
Minecraft.getInstance().options.fov().set(30); //add


 

The maximum zoom value is 30~110. Values higher than this will not work.

Edited by dkrdjdi on Fri, 01/17/2025 - 06:31
Joined May 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Step5. Zoom-out procedure…
Thu, 01/16/2025 - 11:24

Step5. Zoom-out procedure Code.

import net.minecraft.client.Minecraft; //add
import net.minecraft.world.entity.player.Player; //add
import net.minecraft.client.Options; //add

public class ZoomOutProcedure {
public static void execute() {
Player player = Minecraft.getInstance().player; //add
if (player != null) { //add
Minecraft.getInstance().options.fov().set(70); //add

It’s complete.

Joined May 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
https://imgur.com/ESsfkda  …
Fri, 01/17/2025 - 03:00

https://imgur.com/ESsfkda

 

Due to a bug where the FOV value starts at 30 upon rejoining, you can fix this issue by using the corresponding trigger block when creating the ZoomIn procedure.

Joined May 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
This works and very easy to…
Tue, 01/28/2025 - 20:08

This works and very easy to follow. Thank you!