Hdh

⚙️ Target Environment: Minecraft Fabric 1.21.11

🕵️‍♂️ ShadowStalker: "Spy" Mini-Game Mod

ShadowStalker is a fun gameplay modification for Minecraft, designed for friendly mini-games and humorous in-game challenges. It introduces an automated "stalking & following" mechanic, allowing a player to seamlessly shadow a friend by automatically tracking their movements and grabbing their attention with a highly synchronized animation loop.

🕹️ How It Works In-Game

• Target Selection: Find your friend on the server, aim your crosshair at them, and press the B hotkey to lock onto them. • Spy Pursuit Auto-Pilot: Your character instantly activates sprint mode and automatically runs directly behind the selected player, dynamically matching their pathing and movement trajectory. • Dynamic Movement Speed: The pursuit speed is not locked to a fixed value. Instead, the algorithm dynamically fetches the character's maximum available movement speed directly from the Minecraft engine (via attributes, status effects, or external utilities). If the player's movement speed attribute is configured to any standard or extreme value (even up to 1000), the automated tracking system will move the character at that exact maximum speed. • Perfect Positioning: As soon as you catch up to your friend and get right behind their back, the pathfinding auto-pilot stops, locking your coordinates precisely to their trailing position. • High-Frequency Auto-Clicker (Ultra-Shift): Once in position, the mod automatically triggers a high-speed, cyclic toggle of the sneaking key (the system inputs the Shift command on your behalf at an extreme speed—exactly every 2 ticks). The character begins to rapidly crouch and stand up directly behind the target player. • Disengaging the Mode: Pressing the B key again instantly stops all automated scripts and immediately returns full manual control back to the player.

Kodari AI
KodariOct 28 at 9:23 pm 2
ShadowStalker
ShadowStalker is a Fabric mod for Minecraft 1.21.11 that enables automated player-following for mini-games. Press B while aiming at a player to lock onto them, triggering automatic sprint-pursuit that dynamically matches the target's movement path and speed. Upon reaching the target's back, the mod activates a high-frequency sneak-toggle auto-clicker, rapidly crouching and standing every 2 ticks. Pressing B again disengages all automation and restores manual control.
  • Set up a minimal Fabric 1.21.11 client mod project.

  • Register the B toggle and implement target locking, pursuit, and the two-tick sneak cycle.

  • Restore automated key states immediately when the mode is disengaged.

Created the ShadowStalker Fabric client mod. Press B while aiming at another player to pursue a point behind them; once within 0.14 blocks, it toggles sneaking every two ticks. Press B again to disengage and restore the key states and sprint state saved when the mode started.

Pursuit uses vanilla forward and sprint input, so Minecraft’s movement attributes and effects apply rather than a hardcoded speed. It follows a straight line—not obstacle-avoiding pathfinding—and does not force exact coordinates; extreme speeds may overshoot, and the server remains authoritative over movement.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
6 226
src/client/java/com/shadowstalker/ShadowStalkerClient.java
package com.shadowstalker;

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.option.GameOptions;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.hit.EntityHitResult;
import org.lwjgl.glfw.GLFW;

public class ShadowStalkerClient implements ClientModInitializer {
    private static final double TRAILING_DISTANCE = 0.8;
    private static final double POSITION_TOLERANCE = 0.14;

    private static KeyBinding toggleKey;
    private static PlayerEntity target;
    private static boolean active;
    private static boolean originalForward;
    private static boolean originalSprintKey;
    private static boolean originalSneak;
    private static boolean originalSprinting;
    private static boolean inPosition;
    private static boolean sneakPhase;
    private static int sneakTicksRemaining;

    @Override
    public void onInitializeClient() {
        toggleKey = KeyBindingHelper.registerKeyBinding(new KeyBinding(
                "key.shadowstalker.toggle",
                GLFW.GLFW_KEY_B,
                KeyBinding.Category.GAMEPLAY
        ));
        ClientTickEvents.END_CLIENT_TICK.register(ShadowStalkerClient::tick);
    }

    private static void tick(MinecraftClient client) {
        while (toggleKey.wasPressed()) {
            if (active) {
                stop(client);
            } else {
                start(client);
            }
        }

        if (!active) {
            return;
        }

        if (client.player == null || target == null) {
            stop(client);
            return;
        }

        follow(client);
    }

    private static void start(MinecraftClient client) {
        if (client.player == null || !(client.crosshairTarget instanceof EntityHitResult hit)) {
            return;
        }

        if (!(hit.getEntity() instanceof PlayerEntity selected) || selected == client.player) {
            return;
        }

        GameOptions options = client.options;
        target = selected;
        originalForward = options.forwardKey.isPressed();
        originalSprintKey = options.sprintKey.isPressed();
        originalSneak = options.sneakKey.isPressed();
        originalSprinting = client.player.isSprinting();
        inPosition = false;
        sneakPhase = false;
        sneakTicksRemaining = 0;
        active = true;
    }

    private static void follow(MinecraftClient client) {
        var player = client.player;
        double angle = Math.toRadians(target.getYaw());
        double goalX = target.getX() + Math.sin(angle) * TRAILING_DISTANCE;
        double goalZ = target.getZ() - Math.cos(angle) * TRAILING_DISTANCE;
        double dx = goalX - player.getX();
        double dz = goalZ - player.getZ();
        double distanceSquared = dx * dx + dz * dz;
        boolean reached = distanceSquared <= POSITION_TOLERANCE * POSITION_TOLERANCE;

        GameOptions options = client.options;
        if (reached) {
            options.forwardKey.setPressed(false);
            options.sprintKey.setPressed(originalSprintKey);
            player.setSprinting(originalSprinting);

            if (!inPosition) {
                inPosition = true;
                sneakPhase = true;
                sneakTicksRemaining = 2;
                options.sneakKey.setPressed(true);
                return;
            }

            if (--sneakTicksRemaining <= 0) {
                sneakPhase = !sneakPhase;
                sneakTicksRemaining = 2;
                options.sneakKey.setPressed(sneakPhase);
            }
            return;
        }

        inPosition = false;
        options.sneakKey.setPressed(originalSneak);
        options.forwardKey.setPressed(true);
        options.sprintKey.setPressed(true);
        player.setSprinting(true);
        player.setYaw((float) Math.toDegrees(Math.atan2(-dx, dz)));
    }

    private static void stop(MinecraftClient client) {
        GameOptions options = client.options;
        options.forwardKey.setPressed(originalForward);
        options.sprintKey.setPressed(originalSprintKey);
        options.sneakKey.setPressed(originalSneak);
        if (client.player != null) {
            client.player.setSprinting(originalSprinting);
        }

        target = null;
        active = false;
        inPosition = false;
        sneakPhase = false;
        sneakTicksRemaining = 0;
    }
}