S

Make a mod that when someone has a shield on their hand and u press v, V works as a m1 as the same time u press it but make it more customizable in keybinds so for example.someone or something (works on bots) id holdig a shield even of the shield is disabled or they didn't put it up once it's in their hand the v button works as a swap and a left click together

Kodari AI
KodariOct 25 at 8:29 pm 2
ShieldComboAction
A Minecraft Fabric mod for version 1.21.11 that enables a customizable keybind (default V) to perform a combined melee attack and item swap when the player holds a shield in their hand. Works even if the shield is disabled or not raised, and functions for bots. The keybind is fully configurable in the game's keybind settings, allowing players to remap it to any key. When activated, it simultaneously triggers a left-click attack and a swap action, providing a quick combat maneuver for shield users. The mod detects shield presence in the hand regardless of its state and executes the dual action.
  1. Add a configurable client keybind, defaulting to V.

  2. When either hand holds a shield, make the key perform an offhand swap and a normal attack, without requiring the shield to be raised.

  3. Create the minimal Fabric 1.21.11 project files.

Created Shield Combo. Press V while a shield is in either hand to swap hands and perform a normal attack at your crosshair—an entity attack, a block attack, or a swing if nothing is targeted. It works whether or not the shield is raised.

Rebind Shield Swap + Attack under Options → Controls → Shield Combo. The mod acts for the local player; it can attack a targeted bot or NPC like any other entity, but it doesn’t control remote players or bots.

S

No don't swap to the shield just hit at the same time I click v ol

Kodari AI
KodariOct 25 at 8:40 pm 1

Removed the hand swap. V now only performs the attack—hitting the entity or block under your crosshair while you hold a shield. The keybind is labeled Shield Attack.

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

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.item.Items;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.EntityHitResult;
import net.minecraft.util.hit.HitResult;
import org.lwjgl.glfw.GLFW;

public class ShieldComboClient implements ClientModInitializer {
    private static final String MOD_ID = "shieldcombo";
    private static KeyBinding shieldComboKey;

    @Override
    public void onInitializeClient() {
        KeyBinding.Category category = KeyBinding.Category.create(Identifier.of(MOD_ID, "controls"));
        shieldComboKey = KeyBindingHelper.registerKeyBinding(
                new KeyBinding("key.shieldcombo.shield_attack", GLFW.GLFW_KEY_V, category)
        );

        ClientTickEvents.END_CLIENT_TICK.register(client -> {
            while (shieldComboKey.wasPressed()) {
                performCombo(client);
            }
        });
    }

    private static void performCombo(MinecraftClient client) {
        ClientPlayerEntity player = client.player;
        if (player == null || client.interactionManager == null || !isHoldingShield(player)) {
            return;
        }

        HitResult target = client.crosshairTarget;
        if (target instanceof EntityHitResult entityHit) {
            client.interactionManager.attackEntity(player, entityHit.getEntity());
        } else if (target instanceof BlockHitResult blockHit) {
            client.interactionManager.attackBlock(blockHit.getBlockPos(), blockHit.getSide());
        }

        player.swingHand(Hand.MAIN_HAND);
    }

    private static boolean isHoldingShield(ClientPlayerEntity player) {
        return player.getMainHandStack().isOf(Items.SHIELD)
                || player.getOffHandStack().isOf(Items.SHIELD);
    }
}