[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
Thu, 01/16/2025 - 13:42 (edited)

Since using the Speed-up Potion to implement the zoom function is simpler,

I would appreciate it if you watch this tutorial just for fun. :)

 

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 Thu, 01/16/2025 - 13:42
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.