2

I am trying to add a sniper rifle to Minecraft with an addon, and I would like to add a zoom effect for sneaking players holding it. The only spyglass JSON files I've found have been related to the modeling and texture. I have found that the spyglass adjusts the FOV to 1/10 of whatever the player currently has it set to, and that reminded me of the setting FOV Can Be Altered By Gameplay.

These things have brought me to three possibilities for adding zoom to an item.

  1. Adding something to the item's JSON file so it zooms when sneaking.
  2. Detecting sneaking with a script using GameTest features.
  3. Or somehow altering the FOV.

How would I do any of these things, or is there another solution I haven't considered?

1 Answer 1

1

I used a script module to detect what the payer is holding, and apply slowness 256 to them (which zooms in the FOV quite a bit). Unfortunately, this solution is not ideal as it prevents all player movement, and makes the mouse extremely sensitive, but it get's the job done.

import { world, MinecraftEffectTypes } from "mojang-minecraft";

world.events.tick.subscribe(function (e) {
  var players = world.getPlayers();                            // get active players
  for (var p of players) {                                     // loop through the iterator
    var inv = p.getComponent("minecraft:inventory").container; // get the player inventory
    var selected = inv.getItem(p.selectedSlot);                // get the ItemStack for the currently held item
    if (typeof selected !== "undefined") {                     // make sure there is something there. If this isn't here the game generates 20 errors per second.
      if (selected.id === "guns:sniper" && p.isSneaking) {     // if the player is holding an item with the id `guns:sniper` and they are sneaking,
        p.addEffect(MinecraftEffectTypes.slowness, 5, 255, false);  // add the effect
      }
    }
  }
});

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .