aaliyaan memon

Make a Minecraft mod that detects shield takes axe in hand breaks wait 51milliseconds and hit a following hit with mace this all is called stun slam and this all should happen when i hold x key and when i release it it stops

Kodari AI
KodariTue at 8:31 am 3
StunSlam
StunSlam is a Minecraft Fabric mod that adds a powerful combo mechanic triggered by holding the X key. When activated, the mod continuously monitors the player's actions. It detects when the player takes a hit while holding a shield, then automatically switches to an axe in the main hand, waits exactly 51 milliseconds, and performs a follow-up attack with a mace. This sequence, called a "Stun Slam," executes repeatedly while the X key is held down. Releasing the X key immediately stops the combo loop. The mod integrates seamlessly with vanilla combat mechanics, requiring a shield, axe, and mace in the player's inventory. It provides visual and audio feedback when the combo triggers, enhancing the combat experience with a satisfying, skill-based maneuver.
  • Trigger the combo against the shield-blocking entity under your crosshair while X is held.

  • Use an axe and mace from the hotbar; releasing X cancels a pending follow-up.

Created Stun Slam. Put an axe and mace in your hotbar, aim at a shield-blocking entity, and hold X. Releasing X cancels the follow-up.

The mace hit happens on the first client tick after the 51 ms delay, so its exact timing can vary. The target must remain under your crosshair.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
6 191
src/client/java/com/kodari/stunslam/StunSlamClient.java
package com.kodari.stunslam;

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.keymapping.v1.KeyMappingHelper;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
import net.minecraft.tags.ItemTags;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;

public final class StunSlamClient implements ClientModInitializer {
    private static final long FOLLOW_UP_DELAY_NANOS = 51_000_000L;
    private static final KeyMapping COMBO = KeyMappingHelper.registerKeyMapping(
            new KeyMapping("key.stun_slam.combo", InputConstants.Type.KEYBOARD,
                    InputConstants.KEY_X, KeyMapping.Category.MISC));

    private LivingEntity target;
    private long followUpAt;
    private boolean completed;

    @Override
    public void onInitializeClient() {
        ClientTickEvents.END_CLIENT_TICK.register(this::tick);
    }

    private void tick(Minecraft client) {
        if (!COMBO.isDown() || client.player == null || client.gameMode == null
                || client.gui.screen() != null) {
            reset();
            return;
        }

        if (!(client.crosshairPickEntity instanceof LivingEntity current)) {
            reset();
            return;
        }

        if (target != current) {
            reset();
            target = current;
        }

        Inventory inventory = client.player.getInventory();
        if (followUpAt != 0L) {
            if (System.nanoTime() - followUpAt < 0) {
                return;
            }
            int maceSlot = findMace(inventory);
            if (maceSlot >= 0) {
                inventory.setSelectedSlot(maceSlot);
                attack(client, current);
            }
            followUpAt = 0L;
            completed = true;
            return;
        }

        ItemStack blocking = current.getItemBlockingWith();
        if (blocking == null || !blocking.is(Items.SHIELD)) {
            completed = false;
            return;
        }
        if (completed) {
            return;
        }

        int axeSlot = findAxe(inventory);
        if (axeSlot < 0 || findMace(inventory) < 0) {
            return;
        }
        inventory.setSelectedSlot(axeSlot);
        attack(client, current);
        followUpAt = System.nanoTime() + FOLLOW_UP_DELAY_NANOS;
    }

    private static int findAxe(Inventory inventory) {
        for (int slot = 0; slot < 9; slot++) {
            if (inventory.getItem(slot).is(ItemTags.AXES)) {
                return slot;
            }
        }
        return -1;
    }

    private static int findMace(Inventory inventory) {
        for (int slot = 0; slot < 9; slot++) {
            if (inventory.getItem(slot).is(Items.MACE)) {
                return slot;
            }
        }
        return -1;
    }

    private static void attack(Minecraft client, LivingEntity target) {
        client.gameMode.attack(client.player, target);
        client.player.swing(InteractionHand.MAIN_HAND,
                client.player.getInventory().getSelectedItem().getAttackAnimation(), false);
    }

    private void reset() {
        target = null;
        followUpAt = 0L;
        completed = false;
    }
}