Федор Гусеев

Create a client-side Fabric mod for Minecraft 1.21.4.

Feature: Automatic bow shooting with a toggle key and a visual in-game config menu.

Behavior:

  • Add a configurable keybind (default: R) in Controls under a custom category "AutoBow Mod" to toggle the mod ON/OFF.
  • When ON, holding right-click with a bow automatically cycles: draw → release → draw again.
  • Charge time per shot: randomize between 3 and 5 ticks (3 ticks is minimum for arrow to fire).
  • After each release, add a random cooldown of 0 to 2 ticks.
  • Player aims manually; no auto-aim, no target detection.

Visual Config Menu (IMPORTANT):

  • The mod MUST have a VISUAL GUI config screen, NOT just a JSON config file.
  • Access the menu via Mod Menu integration OR a separate keybind (default: Right Shift).
  • Use Cloth Config API to build the menu.
  • The menu MUST contain:

- Toggle: Enable/Disable mod (ON/OFF switch) - Slider: Min Charge Ticks (range 3–20, default 3) - Slider: Max Charge Ticks (range 3–20, default 5) - Slider: Min Cooldown Ticks (range 0–10, default 0) - Slider: Max Cooldown Ticks (range 0–10, default 2) - Keybind display: shows current toggle key

  • The menu must be opened in-game (pause menu → Mods → AutoBow → Config, or via keybind).

Constraints:

  • Client-side only.
  • Do not alter vanilla bow damage or arrow behavior.
  • Stop cycling when the player releases right-click or has no arrows in inventory.
  • Must compile and run on Fabric 1.21.4.
Kodari AI
KodariOct 16 at 4:43 am 3
AutoBowCycle
Client-side Fabric mod for Minecraft 1.21.4 that automates bow shooting. Toggleable via configurable keybind (default R). When active and holding right-click with a bow, automatically cycles draw-release-draw with randomized charge (3-5 ticks) and cooldown (0-2 ticks). Features a visual config GUI built with Cloth Config API, accessible via Mod Menu or keybind (default Right Shift), offering toggles and sliders for charge/cooldown ranges. Stops when right-click released or arrows depleted. No auto-aim or vanilla behavior changes.
  1. Verify the Minecraft/Fabric keybind, client tick, bow-use, and inventory APIs.

  2. Confirm Cloth Config and Mod Menu integration APIs.

  3. Create the client-only mod, GUI configuration, metadata, and build files.

Implemented the client-only AutoBow mod with an R toggle under AutoBow Mod in Controls. While enabled, holding right-click cycles bow shots with the configured charge and cooldown ranges, and stops when right-click is released or no arrows are available.

The visual settings menu is available through Pause Menu → Mods → AutoBow → Configure. It includes an ON/OFF toggle, all four sliders, and the current toggle key.

Cloth Config note: Cloth Config isn’t available on the supplied 1.21.4 compiler classpath, so the menu uses native Minecraft widgets with Mod Menu integration instead.

Kodari can make mistakes. Review important code before using.
Files
src
manifest.kod
Code
6 290
src/client/java/com/kodari/autobow/AutoBowClient.java
package com.kodari.autobow;

import java.util.concurrent.ThreadLocalRandom;

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.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.BowItem;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.tag.ItemTags;
import net.minecraft.util.Hand;

public final class AutoBowClient implements ClientModInitializer {
    public static boolean enabled;
    public static int minChargeTicks = 3;
    public static int maxChargeTicks = 5;
    public static int minCooldownTicks = 0;
    public static int maxCooldownTicks = 2;
    public static KeyBinding TOGGLE_KEY;

    private static boolean charging;
    private static int chargeTicks;
    private static int targetChargeTicks;
    private static int cooldownTicks;

    @Override
    public void onInitializeClient() {
        TOGGLE_KEY = KeyBindingHelper.registerKeyBinding(new KeyBinding(
                "key.autobow.toggle",
                InputUtil.Type.KEYSYM,
                InputUtil.GLFW_KEY_R,
                "key.categories.autobow"
        ));
        ClientTickEvents.END_CLIENT_TICK.register(AutoBowClient::onEndClientTick);
    }

    private static void onEndClientTick(MinecraftClient client) {
        if (TOGGLE_KEY.wasPressed()) {
            enabled = !enabled;
        }

        if (!enabled) {
            resetCycle();
            return;
        }

        ClientPlayerEntity player = client.player;
        if (player == null || client.interactionManager == null) {
            resetCycle();
            return;
        }

        boolean holdingBow = player.getMainHandStack().getItem() instanceof BowItem;
        if (!client.options.useKey.isPressed() || !holdingBow || !hasArrows(player)) {
            if (charging && isUsingBow(player)) {
                client.interactionManager.stopUsingItem(player);
            }
            resetCycle();
            return;
        }

        if (!charging) {
            if (cooldownTicks > 0) {
                cooldownTicks--;
                return;
            }

            if (isUsingBow(player)) {
                beginCharge(player.getItemUseTime());
                if (chargeTicks >= targetChargeTicks) {
                    releaseShot(client, player);
                }
                return;
            }

            client.interactionManager.interactItem(player, Hand.MAIN_HAND);
            if (isUsingBow(player)) {
                beginCharge(0);
            }
            return;
        }

        if (!isUsingBow(player)) {
            resetCycle();
            return;
        }

        chargeTicks++;
        if (chargeTicks >= targetChargeTicks) {
            releaseShot(client, player);
        }
    }

    private static boolean hasArrows(ClientPlayerEntity player) {
        PlayerInventory inventory = player.getInventory();
        for (int slot = 0; slot < inventory.size(); slot++) {
            ItemStack stack = inventory.getStack(slot);
            if (stack.isIn(ItemTags.ARROWS)) {
                return true;
            }
        }
        return false;
    }

    private static boolean isUsingBow(ClientPlayerEntity player) {
        return player.isUsingItem() && player.getActiveItem().getItem() instanceof BowItem;
    }

    private static void beginCharge(int elapsedTicks) {
        charging = true;
        chargeTicks = elapsedTicks;
        targetChargeTicks = randomBetween(minChargeTicks, maxChargeTicks);
    }

    private static void releaseShot(MinecraftClient client, ClientPlayerEntity player) {
        client.interactionManager.stopUsingItem(player);
        charging = false;
        chargeTicks = 0;
        cooldownTicks = randomBetween(minCooldownTicks, maxCooldownTicks);
    }

    private static int randomBetween(int first, int second) {
        int minimum = Math.min(first, second);
        int maximum = Math.max(first, second);
        return ThreadLocalRandom.current().nextInt(minimum, maximum + 1);
    }

    private static void resetCycle() {
        charging = false;
        chargeTicks = 0;
        targetChargeTicks = 0;
        cooldownTicks = 0;
    }
}