thijs3468-coder

can you make a minecraft java mod, that adds a pvp AI if i press right shift, then the AI takes over my player and plays for me in a pvp battle, this mod is a client side mod. The AI needs to play natural. Thank you

Kodari AI
KodariAug 26 at 4:04 pm 1
PvPAutopilot
Client-side Fabric mod for Minecraft 1.21.1 that adds an AI autopilot for PvP combat. When the player presses right Shift, the AI takes control of the player character and fights autonomously. The AI uses natural movement patterns, strafing, jumping, and attack timing to mimic human behavior. It analyzes enemy positions, manages health, and switches targets dynamically. The mod integrates with the game's rendering and input systems to provide seamless, realistic combat automation.
  1. Set up a Fabric 1.21.11 client-only mod with a Right Shift toggle.

  2. Add client-side combat control that selects, approaches, attacks, and defends against nearby hostile players.

  3. Add the required metadata, keybind, client tick logic, and resources.

Created a Fabric 1.21.11 client-side PvP AI mod.

  • Right Shift toggles the AI on/off.

  • Automatically finds the nearest nearby player within 16 blocks.

  • Smoothly aims at the target.

  • Approaches targets, strafes during combat, occasionally jumps, sprints, and attacks when cooldown allows.

  • Releases movement controls when disabled or when no target is available.

  • Includes Fabric/Loom setup, metadata, keybinding registration, and English translations.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
7 287
src/client/java/com/kodari/pvpai/PvpAiClient.java
package com.kodari.pvpai;

import com.mojang.blaze3d.platform.InputConstants;
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.KeyBinding;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import org.lwjgl.glfw.GLFW;

public final class PvpAiClient implements ClientModInitializer {
    public static final String MOD_ID = "pvp_ai";
    private static final KeyBinding.Category CATEGORY = KeyBinding.Category.create(
            Identifier.of(MOD_ID, "controls"));
    private static final KeyBinding TOGGLE_KEY = new KeyBinding(
            "key.pvp_ai.toggle", GLFW.GLFW_KEY_RIGHT_SHIFT, CATEGORY);

    private final PvpCombatController controller = new PvpCombatController();
    private boolean enabled;

    @Override
    public void onInitializeClient() {
        KeyBindingHelper.registerKeyBinding(TOGGLE_KEY);
        ClientTickEvents.END_CLIENT_TICK.register(this::onClientTick);
    }

    private void onClientTick(MinecraftClient client) {
        while (TOGGLE_KEY.wasPressed()) {
            enabled = !enabled;
            if (enabled) {
                showStatus(client, "PvP AI enabled");
            } else {
                controller.stop(client);
                showStatus(client, "PvP AI disabled");
            }
        }

        if (enabled) {
            controller.tick(client);
        } else {
            controller.releaseControls(client);
        }
    }

    private static void showStatus(MinecraftClient client, String message) {
        if (client.inGameHud != null) {
            client.inGameHud.setOverlayMessage(Text.literal(message), false);
        }
    }
}