LuaLogix Sparhawk

Make a minecraft mod that is for singleplayer use, what it does is, with anchors and glowstone , if you hold the ` key, it places anchors in a safe anchor motion, like this: you place 2 anchors in front of you, and the one thats farther from you that wont do as much damage, you will light it with glowstone and then switch back to the anchor. make sure that it moves your crosshair to the blocks, and also sends valid packets. This is for a singleplayer world for fighting mobs in it. make it client side. also make it really fast, but its also random delays 15-30 ms

Kodari AI
KodariSep 17 at 11:16 pm 2
AnchorCombatAssist
Client-side Minecraft mod for singleplayer combat. When holding the grave key, it rapidly places two anchor blocks in front of the player in a safe motion, then lights the farther anchor with glowstone before switching back to the anchor item. The mod automatically moves the crosshair to target blocks and sends valid placement packets. Features randomized 15-30ms delays between actions for fast, human-like execution, optimized for mob fighting in singleplayer worlds.

Created the Fabric 1.21.4 client-side mod project.

  • Hold the grave/backtick key () to trigger the sequence.

  • Places two respawn anchors ahead of the player.

  • Aims the crosshair at each target.

  • Charges the farther anchor with glowstone.

  • Restores the respawn-anchor slot.

  • Uses ClientPlayerInteractionManager for valid interaction packets.

  • Applies randomized 15–30 ms action delays.

  • Includes Gradle, Fabric metadata, Java 21 configuration, and MIT license.

LuaLogix Sparhawk

lets compile it

Kodari AI
KodariSep 17 at 11:31 pm 1

This environment has no Gradle installation or Gradle wrapper, so I can’t run the compilation here. The project currently contains build.gradle but no gradlew.

On your machine, from the project root, run:

Shell
java -version
gradle build

For Fabric 1.21.4, Java 21 is required. If you have Gradle installed but the command differs:

Shell
./gradlew build

The compiled mod should appear under:

Plain Text
build/libs/
LuaLogix Sparhawk

./gradlew : The term './gradlew' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

At line:1 char:1 + ./gradlew build + ~~~~~~~~~

Kodari AI
KodariSep 17 at 11:37 pm 1

The project has no Gradle wrapper files (gradlew or gradlew.bat), so that command cannot work yet.

On Windows PowerShell:

  1. Install Java 21 if needed, then install Gradle:

Powershell
winget install --id Gradle.Gradle -e

Close and reopen PowerShell, then verify:

Powershell
java -version
gradle --version
  1. From the project root, compile directly:

Powershell
gradle build

The mod JAR should be generated in:

Plain Text
build\libs\
  1. Optionally create the wrapper for future builds:

Powershell
gradle wrapper
.\gradlew.bat build

PowerShell uses .\gradlew.bat, not ./gradlew, on Windows.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
LICENSE
settings.gradle
Code
6 341
src/main/java/com/kodari/safeanchor/SafeAnchorClient.java
package com.kodari.safeanchor;

import java.util.concurrent.ThreadLocalRandom;

import org.lwjgl.glfw.GLFW;

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.block.BlockState;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;

public final class SafeAnchorClient implements ClientModInitializer {
    private static final long MIN_DELAY_MILLIS = 15L;
    private static final long MAX_DELAY_MILLIS = 30L;

    private static KeyBinding activateKey;
    private static Action action = Action.IDLE;
    private static BlockPos farAnchor;
    private static BlockPos nearAnchor;
    private static int originalSlot;
    private static long nextActionAt;
    private static boolean activeLastTick;

    @Override
    public void onInitializeClient() {
        activateKey = KeyBindingHelper.registerKeyBinding(new KeyBinding(
                "key.safe_anchor_motion.activate",
                InputUtil.Type.KEYSYM,
                GLFW.GLFW_KEY_GRAVE_ACCENT,
                "category.safe_anchor_motion"));
        ClientTickEvents.END_CLIENT_TICK.register(SafeAnchorClient::tick);
    }

    private static void tick(MinecraftClient client) {
        boolean active = activateKey.isPressed();
        if (!active) {
            if (activeLastTick) {
                cancel(client);
            }
            activeLastTick = false;
            return;
        }

        if (!activeLastTick) {
            start(client);
        }
        activeLastTick = true;

        if (action == Action.IDLE || System.nanoTime() < nextActionAt) {
            return;
        }

        execute(client);
    }

    private static void start(MinecraftClient client) {
        ClientPlayerEntity player = client.player;
        if (player == null || client.world == null || client.currentScreen != null || player.isSpectator()) {
            action = Action.IDLE;
            return;
        }

        PlayerInventory inventory = player.getInventory();
        int anchorSlot = findSlot(inventory, Items.RESPAWN_ANCHOR);
        if (anchorSlot < 0) {
            action = Action.IDLE;
            return;
        }

        originalSlot = inventory.selectedSlot;
        Direction direction = player.getHorizontalFacing();
        BlockPos origin = player.getBlockPos();
        nearAnchor = origin.offset(direction, 2);
        farAnchor = origin.offset(direction, 3);

        if (!canPlace(client, nearAnchor) || !canPlace(client, farAnchor)) {
            action = Action.IDLE;
            return;
        }

        inventory.selectedSlot = anchorSlot;
        action = Action.PLACE_FAR;
        nextActionAt = System.nanoTime();
    }

    private static void execute(MinecraftClient client) {
        ClientPlayerEntity player = client.player;
        if (player == null || client.world == null || client.currentScreen != null) {
            action = Action.IDLE;
            return;
        }

        switch (action) {
            case PLACE_FAR -> {
                placeAnchor(client, farAnchor);
                action = Action.PLACE_NEAR;
            }
            case PLACE_NEAR -> {
                placeAnchor(client, nearAnchor);
                action = findSlot(player.getInventory(), Items.GLOWSTONE) >= 0
                        ? Action.CHARGE_FAR
                        : Action.RESTORE_ANCHOR;
            }
            case CHARGE_FAR -> {
                int glowstoneSlot = findSlot(player.getInventory(), Items.GLOWSTONE);
                if (glowstoneSlot >= 0) {
                    player.getInventory().selectedSlot = glowstoneSlot;
                    aimAt(player, farAnchor.toCenterPos());
                    client.interactionManager.interactBlock(player, Hand.MAIN_HAND, hitOn(farAnchor));
                }
                action = Action.RESTORE_ANCHOR;
            }
            case RESTORE_ANCHOR -> {
                player.getInventory().selectedSlot = findSlot(player.getInventory(), Items.RESPAWN_ANCHOR);
                action = Action.IDLE;
            }
            case IDLE -> {
            }
        }

        if (action != Action.IDLE) {
            nextActionAt = System.nanoTime() + randomDelayNanos();
        }
    }

    private static void placeAnchor(MinecraftClient client, BlockPos target) {
        ClientPlayerEntity player = client.player;
        if (player == null || client.interactionManager == null) {
            action = Action.IDLE;
            return;
        }

        BlockPos support = target.down();
        aimAt(player, target.toCenterPos());
        client.interactionManager.interactBlock(player, Hand.MAIN_HAND, new BlockHitResult(
                support.toCenterPos().add(0.0, 0.5, 0.0),
                Direction.UP,
                support,
                false));
    }

    private static boolean canPlace(MinecraftClient client, BlockPos target) {
        BlockState targetState = client.world.getBlockState(target);
        BlockState supportState = client.world.getBlockState(target.down());
        return targetState.isAir() && !supportState.isAir();
    }

    private static BlockHitResult hitOn(BlockPos position) {
        return new BlockHitResult(
                position.toCenterPos().add(0.0, 0.5, 0.0),
                Direction.UP,
                position,
                false);
    }

    private static void aimAt(ClientPlayerEntity player, Vec3d target) {
        Vec3d delta = target.subtract(player.getEyePos());
        double horizontalDistance = Math.sqrt(delta.x * delta.x + delta.z * delta.z);
        float yaw = (float) (Math.atan2(delta.z, delta.x) * 180.0 / Math.PI) - 90.0F;
        float pitch = (float) -(Math.atan2(delta.y, horizontalDistance) * 180.0 / Math.PI);
        player.setYaw(yaw);
        player.setPitch(pitch);
    }

    private static int findSlot(PlayerInventory inventory, net.minecraft.item.Item item) {
        for (int slot = 0; slot < inventory.main.size(); slot++) {
            ItemStack stack = inventory.main.get(slot);
            if (stack.isOf(item) && !stack.isEmpty()) {
                return slot;
            }
        }
        return -1;
    }

    private static long randomDelayNanos() {
        long milliseconds = ThreadLocalRandom.current().nextLong(MIN_DELAY_MILLIS, MAX_DELAY_MILLIS + 1);
        return milliseconds * 1_000_000L;
    }

    private static void cancel(MinecraftClient client) {
        if (client.player != null && action != Action.IDLE) {
            client.player.getInventory().selectedSlot = originalSlot;
        }
        action = Action.IDLE;
        farAnchor = null;
        nearAnchor = null;
    }