Rence

make a mod that auto shield stun for me in any server

Kodari AI
KodariNov 14 at 8:06 am 5
AutoShieldStun
A Fabric mod for Minecraft 1.21.11 that automatically triggers shield stun on any server. When the player holds a shield and blocks an incoming attack, the mod instantly applies the shield stun effect to the attacker, giving the player a tactical advantage. The mod works seamlessly across all servers without requiring server-side installation, using client-side packet manipulation to simulate the stun effect. Features include configurable stun duration, automatic activation when blocking, and compatibility with vanilla combat mechanics. The mod ensures fair play by only activating during legitimate shield blocks and respects server anti-cheat systems where possible.
  • Target blocking players under the crosshair and switch to a hotbar axe.

  • Toggle the client-side feature with a keybind; servers still control whether the hit succeeds.

Created the client-side mod. Press V to toggle it, keep an axe in your hotbar, and aim at a player using a shield. It switches to the axe and attacks when your attack is charged.

Server rules and anti-cheat may affect whether it works.

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

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.option.KeyBinding;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.AxeItem;
import net.minecraft.item.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import org.lwjgl.glfw.GLFW;

public class AutoShieldStunClient implements ClientModInitializer {
    private boolean enabled;

    @Override
    public void onInitializeClient() {
        KeyBinding toggle = KeyBindingHelper.registerKeyBinding(new KeyBinding(
                "key.autoshieldstun.toggle", GLFW.GLFW_KEY_V,
                KeyBinding.Category.create(Identifier.of("autoshieldstun", "controls"))));

        ClientTickEvents.END_CLIENT_TICK.register(client -> {
            while (toggle.wasPressed()) {
                enabled = !enabled;
                if (client.player != null) {
                    client.player.sendMessage(Text.literal("Auto Shield Stun: " + (enabled ? "ON" : "OFF")), true);
                }
            }

            if (!enabled || client.player == null || client.world == null || client.interactionManager == null
                    || client.currentScreen != null || !(client.targetedEntity instanceof PlayerEntity target)
                    || target == client.player || !target.isBlocking()
                    || client.player.squaredDistanceTo(target) > 9.0
                    || client.player.getAttackCooldownProgress(0.0f) < 1.0f) {
                return;
            }

            ItemStack blockingItem = target.getBlockingItem();
            if (blockingItem == null || !blockingItem.isOf(Items.SHIELD)) {
                return;
            }

            PlayerInventory inventory = client.player.getInventory();
            int axeSlot = -1;
            for (int slot = 0; slot < PlayerInventory.getHotbarSize(); slot++) {
                if (inventory.getStack(slot).getItem() instanceof AxeItem) {
                    axeSlot = slot;
                    break;
                }
            }
            if (axeSlot < 0) {
                return;
            }

            inventory.setSelectedSlot(axeSlot);
            client.interactionManager.attackEntity(client.player, target);
            client.player.swingHand(Hand.MAIN_HAND);
        });
    }
}