Der'Rick

Code a Minecraft auto mace mod for version 1.21.11 that automatically maces my opponent when in range. Use the breach mace when below 7 blocks and use wind burst mace when 7 blocks or higher. Code it so that when they hold up their shield the auto mace will automatically preform a 2-tick stun slam for me. Also, code a feature that will automatically swap to my breach mace whenever I do a critical hit with my axe or sword, and if they are holding a shield, code it to where it auto stuns their shield. Make this mod toggleable by coding it to where all I have to do to activate it is type /automace in the server chat.

Kodari AI
KodariOct 12 at 10:09 pm 6
AutoMaceCombat
An automatic mace combat assistant mod for Minecraft 1.21.11. It automatically attacks opponents with the breach mace when within 7 blocks and the wind burst mace at 7 blocks or more. When the opponent raises a shield, it performs a 2-tick stun slam. It also auto-swaps to the breach mace on critical hits with axe or sword, stunning shields if held. Toggleable via the /automace chat command.

I’ll look up the vanilla and Fabric API signatures first, then write the mod.Mace smash needs fall distance above 1.5, and vanilla maces don’t disable shields on their own. Before writing, I’ll check the remaining signatures.Most signatures are confirmed. I still need the packages for a few types and whether World.getPlayers() exists.

Plan:

  1. Build files: settings.gradle, gradle.properties, build.gradle, fabric.mod.json.

  2. AutoMaceClient: registers /automace, the attack hook for crit detection, and the tick loop.

  3. AutoMaceController: target selection, mace swapping by range, smash timing, and the 2-tick axe stun on shields.

The AutoMace mod is written as a client-side Fabric 1.21.11 project. Compile it with Compile in the top bar, then Download the jar from the build window. No server install is needed, and it adds no items, so there’s nothing extra to obtain in survival.

How it works

  • Toggle: /automace flips the mod on or off and posts a chat confirmation. It’s a client command, so it works on any server.

  • Target: the nearest other player within 16 blocks. Mobs are ignored.

  • Mace choice: breach mace below 7 blocks, wind burst mace at 7 blocks or more. If the preferred mace isn’t in your hotbar, it uses any mace it finds there.

  • Smash: it attacks when the opponent is within reach and your attack cooldown is ready. A mace hit only gets its bonus when you’re falling more than 1.5 blocks, so when you’re on the ground it jumps to set that up.

  • Shield stun: when the opponent is holding a shield, it runs a 2-tick stun before the slam. On tick 0 it swaps to an axe and hits, then on tick 2 it swaps back to the mace. The axe hit disables the shield for 5 seconds. I read “2-tick stun slam” as this sequence.

  • Crit swap: a critical hit with an axe or sword switches you to the breach mace on the next tick.

Limitations to know

  • Vanilla maces don’t disable shields. Their shield-disable time is zero, so the stun needs an axe in your hotbar. Without one, the mod just smashes.

  • It doesn’t walk you toward the opponent. The 7-block split only picks which mace to use. You still have to close the distance, because hits only land within reach.

  • It takes over your hotbar selection whenever a mace is in the hotbar and an opponent is within 16 blocks. Keep the breach mace, wind burst mace and an axe in hotbar slots 1–9.

  • Stun timing: a stun can’t repeat for 5 seconds, because re-stunning sooner would keep resetting the mace cooldown.

I haven’t run a build, so the first compile is the real check. If it fails, use Auto-fix in the chat.

Files:

  • build.gradle

  • settings.gradle

  • gradle.properties

  • src/main/resources/fabric.mod.json

  • src/client/java/com/example/automace/AutoMaceClient.java

  • src/client/java/com/example/automace/AutoMaceController.java

Kodari can make mistakes. Review important code before using.
Files
src
AutoMace
build.gradle
gradle.properties
settings.gradle
Code
7 330
src/client/java/com/example/automace/AutoMaceClient.java
package com.example.automace;

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.event.player.AttackEntityCallback;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;

public class AutoMaceClient implements ClientModInitializer {
    @Override
    public void onInitializeClient() {
        ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) ->
                dispatcher.register(ClientCommandManager.literal("automace").executes(context -> {
                    boolean enabled = AutoMaceController.toggle();
                    context.getSource().sendFeedback(Text.literal("AutoMace " + (enabled ? "enabled" : "disabled")));
                    return 1;
                })));

        AttackEntityCallback.EVENT.register((player, world, hand, entity, hitResult) -> {
            AutoMaceController.onAttack(player, hand, entity);
            return ActionResult.PASS;
        });

        ClientTickEvents.END_CLIENT_TICK.register(AutoMaceController::tick);
    }
}