O

make a mod that when i click 8 on my keyboard it enables a thing that i can hit players when holding theyre shield and toggle with keybind 8

Kodari AI
KodariJun 4 at 4:18 pm 20
ShieldBreaker
A Fabric 1.21.11 mod that adds a toggleable Shield Breaker mode. Press keybind 8 to toggle the mode on/off. While active, hitting a player who is currently blocking with a shield will bypass the shield and deal damage directly, ignoring the shield's protection. A HUD indicator shows when the mode is active.

Let me read the necessary docs before writing any code.

Now I have everything needed. Here’s the plan:

  • ShieldBreakerMod — registers C2S packet type + server receiver, stores active players in a static set

  • LivingEntityMixin — injects into blockedByShield to return false when attacker has mode active

  • ShieldBreakerClient — registers key 8 binding, sends toggle packet, shows HUD status

  • ShieldBreakerTogglePacket — CustomPayload record

ShieldBreaker
A Fabric 1.21.11 mod that adds a toggleable Shield Breaker mode. Press the configurable keybind (default: 8) to enable it. While active, hitting a player who is blocking with a shield will bypass the shield entirely and deal full damage. A HUD indicator in the top-left shows when the mode is active. The toggle state is synced from client to server via a custom packet.

Here’s what was built:

  • Key 8 toggles Shield Breaker mode on/off — uses the 1.21.9+ KeyBinding.Category.create(Identifier) pattern with the correct 3-arg constructor

  • Shield bypass — a LivingEntityMixin injects into LivingEntity.blockedByShield() and returns false when the attacker is a player with the mode active, meaning full damage goes through regardless of the target holding a shield

  • Packet sync — toggling sends a ShieldBreakerTogglePacket (C2S CustomPayload record) to the server so the server always knows each player’s current state

  • HUD indicator — while active, “⚔ Shield Breaker ON” appears in red bold at the top-left of your screen (hidden when any screen/menu is open)

  • Cleanup — state is cleared from the server map when a player disconnects

O

The compilation failed with this error:

code
Compilation failed with 2 error(s):

ERROR in src/main/java/com/example/shieldbreaker/network/ShieldBreakerTogglePacket.java at line 15: cannot find symbol
        PacketCodec.tuple(PacketCodecs.BOOL, ShieldBreakerTogglePacket::enabled, ShieldBreakerTogglePacket::new);
                                      ^
  symbol: variable BOOL
  location: interface PacketCodecs

ERROR in   src/main/java/com/example/shieldbreaker/network/ShieldBreakerTogglePacket.java at line 15: cannot find symbol
          PacketCodec.tuple(PacketCodecs.BOOL, ShieldBreakerTogglePacket::enabled, ShieldBreakerTogglePacket::new);
                                        ^
  symbol: variable BOOL
  location: interface PacketCodecs


=== COMPILATION ERROR ANALYSIS ===

FILES TO INVESTIGATE:
  - src/main/java/com/example/shieldbreaker/network/ShieldBreakerTogglePacket.java
  -   src/main/java/com/example/shieldbreaker/network/ShieldBreakerTogglePacket.java

Please fix this error by creating a new artifact with the corrected code.

Kodari AI
KodariJun 4 at 4:20 pm 3

PacketCodecs.BOOL → PacketCodecs.BOOLEAN. That’s the correct constant name in 1.21.11’s Yarn mappings.

O

make it all fabric version compatable

Kodari AI
KodariJun 4 at 4:26 pm 12

True cross-version compatibility means targeting a stable baseline (1.20.1) and using APIs that exist across all versions — old-style PacketByteBuf networking, string-based KeyBinding category, no HudElementRegistry (removed 1.21.6+), new Identifier(), Java 17. The HUD swap becomes an action bar message which works everywhere. The shield mixin logic is unchanged.

Here’s what changed for broad compatibility:

What changed
Why
Target Minecraft
1.20.1
, Java 17
Widest supported baseline;
>=1.20.1
in mod depends
Old
PacketByteBuf
networking
CustomPayload
only exists ≥ 1.20.5
new Identifier("mod", "path")
Works on every version;
Identifier.of()
added in 1.20.2
String category
"key.categories.misc"
KeyBinding.Category.create(Identifier)
is 1.21.9+ only
Action bar message on toggle
HudElementRegistry
is 1.21.6+;
HudRenderCallback
was removed in 1.21.6+; action bar works everywhere
Pattern match
instanceof
replaced with cast
Keeps Java 17 compatible (pattern match works in 17 but the cast style is universal)
Deleted
ShieldBreakerTogglePacket.java
No longer needed; packet logic is now inline
Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
Code
9 209
src/client/java/com/example/shieldbreaker/ShieldBreakerClient.java
package com.example.shieldbreaker;

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.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.text.Text;
import org.lwjgl.glfw.GLFW;

public class ShieldBreakerClient implements ClientModInitializer {

    public static final KeyBinding TOGGLE_KEY = KeyBindingHelper.registerKeyBinding(
        new KeyBinding("key.shieldbreaker.toggle", GLFW.GLFW_KEY_8, "key.categories.misc")
    );

    private static boolean active = false;

    @Override
    public void onInitializeClient() {
        ClientTickEvents.END_CLIENT_TICK.register(client -> {
            while (TOGGLE_KEY.wasPressed()) {
                active = !active;
                if (client.player != null) {
                    PacketByteBuf buf = PacketByteBufs.create();
                    buf.writeBoolean(active);
                    ClientPlayNetworking.send(ShieldBreakerMod.TOGGLE_PACKET_ID, buf);

                    client.player.sendMessage(
                        active
                            ? Text.literal("§c§l⚔ Shield Breaker: ON")
                            : Text.literal("§7Shield Breaker: OFF"),
                        true
                    );
                }
            }
        });
    }

    public static boolean isActive() {
        return active;
    }
}