Hdh
📎 1 file 1,726 chars
📄
pasted-code-1793217001792.txt
txt 14 lines
▶

Mod Description: FaceDistance (Fabric 1.21.11)

FaceDistance is a specialized client-side mod for testing player positioning, hitboxes, and training combat timings in Minecraft 1.21.11. The mod automates the cyclic movement of your character along a single line relative to the selected target.
🔄 Movement Mechanics and Trajectory:
After selecting a player, the mod completely takes over your movement and looking direction, running a continuous loop:
1. Target Lock and Aim: The mod automatically locks your character's camera onto the target player's face. Wherever the target moves, your view remains permanently fixed on their eyes.
2. Close-up Movement: You fly along the straight line of your sight directly into the target's face (the distance shortens to a minimum of 0.3–0.5 blocks).
3. Backward Movement: As soon as you reach the target's face, the movement vector instantly inverts. Your character flies backwards along the exact same line exactly 3 blocks away from the player's face.
4. Infinite Loop: Upon reaching the point 3 blocks back, the movement reverses again, and you fly back into their face. This distance repetition loop of "close-up — back" runs continuously.
5. Dynamic Velocity Adaptation: The mod fully syncs with your current server-side flight speed. If your flight speed on the server is modified (for example, set to a high value like 1000), the mod scales its execution and moves your character at that exact speed without any artificial caps, stuttering, or position desync.
⌨️ Control Commands:
• #target [Player_Nickname] — lock view on the player and start the cyclic movement to their face and back.
• #stop — instantly stop the movement and return manual control over your character.
Kodari AI
KodariOct 28 at 7:59 pm 2
FaceDistance
FaceDistance is a client-side Fabric mod for Minecraft 1.21.11 that automates cyclic movement toward and away from a selected target player's face. After targeting a player via the #target command, the mod locks the camera onto their eyes and continuously flies the character into their face (0.3-0.5 blocks), then reverses 3 blocks back in an infinite loop. It dynamically adapts to server-side flight speed without caps or desync. The #stop command halts movement and restores manual control.
  1. Create the Fabric 1.21.11 client mod scaffold and metadata.

  2. Implement #target <name> / #stop, target tracking, look lock, and a close/back movement loop using the player’s synced flight ability.

  3. Keep it client-side and rely on the server’s normal movement validation; no speed or anti-cheat bypass.

Created the FaceDistance client mod scaffold and implementation. Use #target <playername> to lock onto a nearby player and start the close/back loop, or #stop to release control. These commands are handled locally and aren’t sent to chat.

Movement runs only while the server grants flight and uses the client’s synced flight speed. The server still validates movement, so high speeds may be corrected; this mod does not bypass server movement checks.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
5 175
src/client/java/com/kodari/facedistance/FaceDistanceClient.java
package com.kodari.facedistance;

import java.util.UUID;

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.message.v1.ClientSendMessageEvents;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.util.math.Vec3d;

public final class FaceDistanceClient implements ClientModInitializer {
    private static final double CLOSE_DISTANCE = 0.45;
    private static final double FAR_DISTANCE = 3.0;

    private UUID targetUuid;
    private boolean movingAway;

    @Override
    public void onInitializeClient() {
        ClientSendMessageEvents.ALLOW_CHAT.register(this::handleChatMessage);
        ClientTickEvents.END_CLIENT_TICK.register(this::tick);
    }

    private boolean handleChatMessage(String message) {
        String command = message.trim();
        if (command.equalsIgnoreCase("#stop")) {
            targetUuid = null;
            return false;
        }

        if (command.equalsIgnoreCase("#target") || command.regionMatches(true, 0, "#target ", 0, 8)) {
            String targetName = command.length() > 7 ? command.substring(8).trim() : "";
            MinecraftClient client = MinecraftClient.getInstance();
            targetUuid = null;
            movingAway = false;

            if (!targetName.isEmpty() && client.world != null && client.player != null) {
                for (AbstractClientPlayerEntity candidate : client.world.getPlayers()) {
                    if (!candidate.getUuid().equals(client.player.getUuid())
                            && candidate.getName().getString().equalsIgnoreCase(targetName)) {
                        targetUuid = candidate.getUuid();
                        break;
                    }
                }
            }
            return false;
        }

        return true;
    }

    private void tick(MinecraftClient client) {
        if (targetUuid == null || client.player == null || client.world == null) {
            return;
        }

        AbstractClientPlayerEntity target = null;
        for (AbstractClientPlayerEntity candidate : client.world.getPlayers()) {
            if (candidate.getUuid().equals(targetUuid)) {
                target = candidate;
                break;
            }
        }

        if (target == null) {
            targetUuid = null;
            return;
        }

        Vec3d offset = target.getEyePos().subtract(client.player.getEyePos());
        double distance = offset.length();
        if (distance == 0.0) {
            return;
        }

        double horizontalDistance = Math.sqrt(offset.x * offset.x + offset.z * offset.z);
        client.player.setYaw((float) Math.toDegrees(Math.atan2(offset.z, offset.x)) - 90.0F);
        client.player.setPitch((float) -Math.toDegrees(Math.atan2(offset.y, horizontalDistance)));

        if (!client.player.getAbilities().flying) {
            return;
        }

        if (movingAway && distance >= FAR_DISTANCE) {
            movingAway = false;
        } else if (!movingAway && distance <= CLOSE_DISTANCE) {
            movingAway = true;
        }

        double remainingDistance = movingAway ? FAR_DISTANCE - distance : distance - CLOSE_DISTANCE;
        double speed = Math.min(client.player.getAbilities().getFlySpeed(), remainingDistance);
        Vec3d velocity = offset.normalize().multiply(movingAway ? -speed : speed);
        client.player.setVelocity(velocity);
    }
}