Cortex

Create a Minecraft mod for single-player worlds that automatically attacks nearby hostile mobs. Let players configure the attack range, target types, and randomized delays and input patterns so the behavior isn’t perfectly repetitive. Explain whether it can continue working while the game window is unfocused, and implement that only through supported Minecraft or mod-loader APIs—don’t simulate input in other applications or bypass anti-cheat systems. If the Minecraft version or mod loader isn’t specified, recommend a suitable option and state your assumptions. Provide the complete source code, setup instructions, and a brief explanation of how to test and configure the mod.

Kodari AI
KodariOct 18 at 12:47 pm 2
AutoCombatAssistant
Creates a Fabric mod for Minecraft 1.21.4 that automatically targets and attacks nearby hostile mobs in single-player worlds. Players configure attack range, target type filters, and randomized attack delays and input patterns to avoid repetitive behavior. The mod operates via server-side tick events and entity interactions, continuing to function when the game window is unfocused through supported Minecraft APIs without simulating external input or bypassing anti-cheat systems. Includes full source code, setup instructions, and configuration guidance.
  1. Create the Fabric 1.21.4 client mod with a single-player-only guard and a toggle key.

  2. Add a properties config for range, entity-type IDs, randomized attack delays, and occasional pauses.

  3. Explain unfocused-window behavior and give setup and test steps.

Created Solo Sentinel, a client-side Fabric 1.21.4 mod. Press R to toggle it; it attacks the nearest visible, configured entity in range when the vanilla attack cooldown is ready. It runs only in integrated single-player worlds and never targets players.

Configuration is generated at config/solosentinel.properties. You can set the range, target entity IDs, randomized attack delays, and chance and length of extra pauses. Changes apply after restarting Minecraft.

Unfocused window: The mod uses Minecraft’s client tick and interaction APIs, not simulated keyboard or mouse input. It can act only while Minecraft keeps ticking. Vanilla may pause a single-player world when the window loses focus; the mod does not override that behavior. The vanilla pause-on-lost-focus setting is toggled with F3+P.

Setup and test: Compile the project in Kodari, download the successful build, and place the jar in the mods folder for your Fabric 1.21.4 profile alongside Fabric API. In a single-player survival world, press R near a visible hostile mob to test it. The README includes the full configuration details.

Cortex

can you make it for multiplayer to

Kodari AI
KodariOct 18 at 1:24 pm 2

Enabled Solo Sentinel in both single-player and multiplayer by removing the integrated-server-only check. It still targets configured mobs only, uses Minecraft’s normal attack interaction, and does not simulate input or evade anti-cheat. Multiplayer servers remain authoritative and may reject attacks or prohibit automation—use it only where server rules allow.

Compile the project in Kodari and install the jar with Fabric API on your Fabric 1.21.4 profile. The README now covers multiplayer testing and server-rule cautions.

Cortex

Can you make an gui now for it that i can put on how random it needs to hit (make ontop of the gui say Daddy dond3r)

Kodari AI
KodariOct 18 at 1:30 pm 1
  1. Inspect the existing toggle/config flow and the Fabric 1.21.4 screen/widget APIs.

  2. Add a GUI opened by the mod’s key, headed “Daddy dond3r”, with a control for hit randomness.

  3. Update the usage notes and explain that server rules still apply.

Added the Daddy dond3r settings screen. Press G to open it; adjust the Hit randomness slider live, toggle attacking in the screen, or keep using R. The slider setting is saved to the config: 0% uses steady midpoint delays and disables randomized pauses; 100% uses the full configured delay and pause variation.

Use the mod only on multiplayer servers that permit automated attacks; server rules still apply.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
README.md
settings.gradle
Code
8 417
src/main/java/com/kodari/solosentinel/SoloSentinelClient.java
package com.kodari.solosentinel;

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.network.ClientPlayerEntity;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.registry.Registries;
import net.minecraft.text.Text;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Box;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashSet;
import java.util.Locale;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;

public final class SoloSentinelClient implements ClientModInitializer {
    private static final Logger LOGGER = LoggerFactory.getLogger("solosentinel");
    private static final KeyBinding TOGGLE_KEY = KeyBindingHelper.registerKeyBinding(
            new KeyBinding("key.solosentinel.toggle", InputUtil.Type.KEYSYM, 82, "key.category.solosentinel")
    );
    private static final KeyBinding CONFIG_KEY = KeyBindingHelper.registerKeyBinding(
            new KeyBinding("key.solosentinel.config", InputUtil.Type.KEYSYM, 71, "key.category.solosentinel")
    );

    private static Config config;
    private static Path configPath;
    private static boolean configLoaded;
    private static boolean enabled;
    private static int ticksUntilNextAttack;

    @Override
    public void onInitializeClient() {
        ClientTickEvents.END_CLIENT_TICK.register(SoloSentinelClient::onClientTick);
        LOGGER.info("Solo Sentinel initialized. Toggle with the configured key (default: R).");
    }

    private static void onClientTick(MinecraftClient client) {
        if (!configLoaded) {
            configPath = client.runDirectory.toPath().resolve("config").resolve("solosentinel.properties");
            config = loadConfig(configPath);
            configLoaded = true;
        }

        if (CONFIG_KEY.wasPressed() && client.player != null) {
            client.setScreen(new SoloSentinelConfigScreen());
        }

        if (TOGGLE_KEY.wasPressed()) {
            enabled = !enabled;
            ticksUntilNextAttack = 0;
            if (client.player != null) {
                client.player.sendMessage(Text.literal(enabled
                        ? "Solo Sentinel enabled. Use only where server rules allow it."
                        : "Solo Sentinel disabled."), true);
            }
        }

        if (!enabled || client.player == null || client.world == null
                || client.interactionManager == null || client.currentScreen != null || !client.player.isAlive()) {
            return;
        }

        if (ticksUntilNextAttack > 0) {
            ticksUntilNextAttack--;
            return;
        }

        ClientPlayerEntity player = client.player;
        if (player.getAttackCooldownProgress(0.0F) < 1.0F) {
            return;
        }

        double rangeSquared = config.attackRange * config.attackRange;
        Box searchBox = player.getBoundingBox().expand(config.attackRange);
        Entity target = null;
        double nearestDistanceSquared = rangeSquared;

        for (Entity candidate : client.world.getOtherEntities(player, searchBox,
                entity -> isValidTarget(entity, player, rangeSquared))) {
            double distanceSquared = player.squaredDistanceTo(candidate);
            if (target == null || distanceSquared < nearestDistanceSquared) {
                target = candidate;
                nearestDistanceSquared = distanceSquared;
            }
        }

        if (target == null) {
            return;
        }

        client.interactionManager.attackEntity(player, target);
        player.swingHand(Hand.MAIN_HAND);
        ticksUntilNextAttack = nextDelayTicks();
    }

    private static boolean isValidTarget(Entity entity, ClientPlayerEntity player, double rangeSquared) {
        if (entity instanceof PlayerEntity || !entity.isAlive() || entity.isRemoved()
                || player.squaredDistanceTo(entity) > rangeSquared || !player.canSee(entity)) {
            return false;
        }

        Identifier typeId = Registries.ENTITY_TYPE.getId(entity.getType());
        return typeId != null && config.targetTypes.contains(typeId.toString());
    }

    private static int nextDelayTicks() {
        int randomness = config.randomnessPercent;
        int delay = randomizedDelay(config.minDelayTicks, config.maxDelayTicks, randomness);
        int pauseChance = config.pauseChancePercent * randomness / 100;
        if (ThreadLocalRandom.current().nextInt(100) < pauseChance) {
            delay += randomizedDelay(config.minPauseTicks, config.maxPauseTicks, randomness);
        }
        return delay;
    }

    private static int randomizedDelay(int minimum, int maximum, int randomnessPercent) {
        int width = (int) Math.round((maximum - minimum) * randomnessPercent / 100.0);
        int effectiveMinimum = (minimum + maximum - width) / 2;
        return randomBetween(effectiveMinimum, effectiveMinimum + width);
    }

    static int getRandomnessPercent() {
        return config.randomnessPercent;
    }

    static boolean isEnabled() {
        return enabled;
    }

    static void setEnabled(boolean value) {
        enabled = value;
        ticksUntilNextAttack = 0;
    }

    static void setRandomnessPercent(int value) {
        int randomnessPercent = Math.max(0, Math.min(100, value));
        config = new Config(config.attackRange, config.targetTypes, config.minDelayTicks, config.maxDelayTicks,
                randomnessPercent, config.pauseChancePercent, config.minPauseTicks, config.maxPauseTicks);

        Properties properties = new Properties();
        try {
            try (var reader = Files.newBufferedReader(configPath)) {
                properties.load(reader);
            }
            properties.setProperty("randomness_percent", Integer.toString(randomnessPercent));
            try (var writer = Files.newBufferedWriter(configPath)) {
                properties.store(writer, "Solo Sentinel settings.");
            }
        } catch (IOException exception) {
            LOGGER.error("Could not save Solo Sentinel randomness setting at {}", configPath, exception);
        }
    }

    private static int randomBetween(int minimum, int maximum) {
        return ThreadLocalRandom.current().nextInt(minimum, maximum + 1);
    }

    private static Config loadConfig(Path path) {
        Properties properties = defaultProperties();
        try {
            Files.createDirectories(path.getParent());
            if (Files.exists(path)) {
                try (var reader = Files.newBufferedReader(path)) {
                    properties.load(reader);
                }
            } else {
                try (var writer = Files.newBufferedWriter(path)) {
                    properties.store(writer, "Solo Sentinel settings. Changes apply after restarting Minecraft.");
                }
            }
        } catch (IOException exception) {
            LOGGER.error("Could not read or create Solo Sentinel config at {}", path, exception);
        }

        double range = boundedDouble(properties, "range", 4.5, 1.0, 16.0);
        int minDelay = boundedInt(properties, "min_delay_ticks", 7, 1, 1200);
        int maxDelay = Math.max(minDelay, boundedInt(properties, "max_delay_ticks", 13, 1, 1200));
        int minPause = boundedInt(properties, "min_pause_ticks", 10, 1, 1200);
        int maxPause = Math.max(minPause, boundedInt(properties, "max_pause_ticks", 25, 1, 1200));
        int pauseChance = boundedInt(properties, "pause_chance_percent", 15, 0, 100);
        int randomness = boundedInt(properties, "randomness_percent", 100, 0, 100);

        return new Config(range, parseTargetTypes(properties.getProperty("target_types", "")),
                minDelay, maxDelay, randomness, pauseChance, minPause, maxPause);
    }