Vishal Kumar

Create a complete, stable Minecraft Fabric mod for Minecraft 1.21.11.

MOD NAME: Trial MOD ID: trial JAR NAME: Trial.jar

IMPORTANT:

Build a working mod. Do not leave placeholder code, incomplete methods, fake APIs, or TODO sections. The project must compile successfully.

  1. TWO COMPLETELY SEPARATE KEYBINDS

Add two independent keybinds:

  1. “Use Mace”
  2. “Use Spear”

They MUST be separate keybinds.

The player must be able to assign different keyboard keys to them from:

Options → Controls → Key Binds

Do NOT combine them into one keybind.

  1. KEY PRESS BEHAVIOR

Each key press triggers exactly ONE activation.

For example:

Press “Use Mace” once → perform one Mace action.

Press “Use Mace” again → perform another Mace action.

Same for Spear.

IMPORTANT:

  • Do NOT make it a toggle.
  • Do NOT switch between Mace and Spear automatically.
  • Do NOT continuously activate while the key is held.
  • Holding the key must NOT repeatedly trigger the action.
  • One physical key press = one activation.
  1. PLAYER CAN HOLD ANY HOTBAR ITEM

The player may currently be holding anything in their selected hotbar slot:

  • Food
  • Bucket
  • Block
  • Tool
  • Weapon
  • Any other item

The mod must remember the player's exact selected hotbar slot and currently held item before performing the action.

  1. USE MACE KEY

When the player presses the separate “Use Mace” key:

  1. Find an existing Mace in the player's inventory/hotbar.
  2. Temporarily equip/use that actual Mace.
  3. Perform the normal Minecraft Mace attack/action.
  4. Use the real Mace mechanics and real attributes.
  5. After the action, restore the exact hotbar slot and item the player was holding before pressing the key.

Example:

Player is holding a Water Bucket. ↓ Press “Use Mace”. ↓ Mace is temporarily used. ↓ Mace attack is performed normally. ↓ Player is holding the same Water Bucket again.

If the player does not have a Mace: → Do nothing and leave the currently held item unchanged.

  1. USE SPEAR KEY

When the player presses the separate “Use Spear” key:

  1. Find an existing Spear in the player's inventory/hotbar.
  2. Temporarily equip/use that actual Spear.
  3. Perform the normal Minecraft Spear action/attack.
  4. Use the real Spear mechanics and real attributes.
  5. After the action, restore the exact hotbar slot and item the player was holding before pressing the key.

Example:

Player is holding food. ↓ Press “Use Spear”. ↓ Spear is temporarily used. ↓ Normal Spear action is performed. ↓ Player is holding the same food again.

If the player does not have a Spear: → Do nothing and leave the currently held item unchanged.

  1. REAL WEAPON ATTRIBUTES — CRITICAL

The mod must NOT fake or hard-code weapon statistics.

When the Mace or Spear is temporarily used, Minecraft must treat it as the actual equipped weapon for that action.

Correctly preserve/apply all relevant vanilla attributes and item modifiers, including where applicable:

  • Attack Damage
  • Attack Speed
  • Reach
  • Weapon-specific modifiers
  • Other vanilla attribute modifiers

The action must use the actual Mace/Spear attributes from the item itself.

Do NOT permanently modify the player's attributes.

Do NOT leave temporary attributes behind after the action.

Do NOT duplicate attribute modifiers.

Do NOT create fake damage.

  1. INVENTORY SAFETY

The mod must never:

  • Delete items
  • Duplicate items
  • Create fake weapons
  • Replace the player's original item
  • Permanently change the selected hotbar slot
  • Corrupt the inventory
  • Lose the Mace/Spear
  • Change unrelated inventory slots

Only use an existing Mace/Spear from the player's inventory/hotbar.

  1. VANILLA MECHANICS

Respect normal Minecraft mechanics.

Do not bypass:

  • Attack cooldown
  • Weapon durability
  • Normal hit/use behavior
  • Reach restrictions
  • Item restrictions
  • Other relevant vanilla mechanics

The result should behave as close as possible to manually selecting the Mace/Spear and using it.

  1. MULTIPLAYER / SERVER SYNC

Implement the keybind and weapon action correctly for Fabric multiplayer.

Client input must be synchronized with the server when necessary.

Prevent client/server inventory or selected-slot desynchronization.

Do not rely only on client-side visual changes for an action that must actually occur on the server.

  1. SAFE FAILURE

If:

  • No Mace exists
  • No Spear exists
  • The player cannot perform the action
  • The action is invalid

Then safely do nothing.

Do not crash.

Do not change the player's currently held item.

  1. FABRIC VERSION

Target:

Minecraft: 1.21.11 Mod Loader: Fabric Use APIs and mappings compatible with Minecraft 1.21.11.

Do not use obsolete APIs from older Minecraft versions.

  1. FINAL BEHAVIOR

The final system must work exactly like this:

PLAYER HOLDS ANY ITEM ↓ PRESS “USE MACE” ↓ REAL MACE IS TEMPORARILY USED ↓ NORMAL MACE ACTION WITH REAL ATTRIBUTES ↓ ORIGINAL ITEM/SELECTED SLOT RESTORED

OR:

PLAYER HOLDS ANY ITEM ↓ PRESS “USE SPEAR” ↓ REAL SPEAR IS TEMPORARILY USED ↓ NORMAL SPEAR ACTION WITH REAL ATTRIBUTES ↓ ORIGINAL ITEM/SELECTED SLOT RESTORED

MACE AND SPEAR MUST HAVE TWO COMPLETELY SEPARATE KEYBINDS.

NO TOGGLE.

NO AUTOMATIC SWITCHING.

NO REPEATED ACTIVATION WHILE HOLDING THE KEY.

ONE KEY PRESS = ONE ACTION.

Finally, compile the project successfully and provide the working Trial.jar file.

Kodari AI
KodariOct 5 at 5:26 am 2
DualWeaponHotswap
Adds two separate keybinds for using Mace and Spear weapons in Minecraft Fabric 1.21.11. When pressed, the mod temporarily equips the corresponding weapon from the player's inventory, performs the vanilla attack action with real weapon attributes, then restores the original hotbar slot and item. Each key press triggers exactly one action with no toggle or repeat behavior. Works with any held item and safely does nothing if the weapon is unavailable.
  1. Register two independent client keybinds and trigger each only once per press.

  2. Use vanilla-selected Mace/Spear mechanics without mutating unrelated inventory, then restore the selected hotbar slot.

  3. Create the Fabric 1.21.11 project metadata and required item-independent resources.

Created the Trial client mod with separate Use Mace and Use Spear keybinds (default V and B). Each uses vanilla’s attack path, temporarily swaps in an existing weapon from the inventory, and restores the original item and selected hotbar slot. Held-key repeats are filtered.

To build and download Trial.jar in Kodari:

  1. Click Compile in the top bar (on phone: ⋮ → Compile Project).

  2. Click Compile in the window that opens.

  3. After it succeeds, click Download on the build or Download Trial.jar in chat.

Vishal Kumar

I want to get my trial mode changed

Kodari AI
KodariOct 5 at 5:42 am 1

What would you like changed in the Trial mod—its keybinds, weapon behavior, or something else? Describe how you want it to work.

Vishal Kumar

I am telling you what to change

Kodari AI
KodariOct 5 at 5:43 am 1

Go ahead—tell me what you want changed in the Trial mod, and I’ll update it.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
8 263
src/client/java/com/kodari/trial/TrialClient.java
package com.kodari.trial;

import com.kodari.trial.mixin.MinecraftClientInvoker;
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.option.KeyBinding;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.slot.Slot;
import net.minecraft.screen.slot.SlotActionType;
import net.minecraft.util.Identifier;
import org.lwjgl.glfw.GLFW;

public final class TrialClient implements ClientModInitializer {
    private static final KeyBinding.Category CATEGORY = KeyBinding.Category.create(Identifier.of("trial", "controls"));
    private static final KeyBinding USE_MACE = KeyBindingHelper.registerKeyBinding(
            new KeyBinding("key.trial.use_mace", GLFW.GLFW_KEY_V, CATEGORY)
    );
    private static final KeyBinding USE_SPEAR = KeyBindingHelper.registerKeyBinding(
            new KeyBinding("key.trial.use_spear", GLFW.GLFW_KEY_B, CATEGORY)
    );

    private static boolean maceWasDown;
    private static boolean spearWasDown;

    @Override
    public void onInitializeClient() {
        ClientTickEvents.END_CLIENT_TICK.register(TrialClient::onClientTick);
    }

    private static void onClientTick(MinecraftClient client) {
        boolean maceDown = USE_MACE.isPressed();
        boolean maceQueued = drainQueuedPresses(USE_MACE);
        boolean useMace = !maceWasDown && (maceDown || maceQueued);
        maceWasDown = maceDown;

        boolean spearDown = USE_SPEAR.isPressed();
        boolean spearQueued = drainQueuedPresses(USE_SPEAR);
        boolean useSpear = !spearWasDown && (spearDown || spearQueued);
        spearWasDown = spearDown;

        if (client.player == null || client.interactionManager == null || client.currentScreen != null) {
            return;
        }

        if (useMace) {
            activateWeapon(client, false);
        }
        if (useSpear) {
            activateWeapon(client, true);
        }
    }

    private static boolean drainQueuedPresses(KeyBinding keyBinding) {
        boolean queued = false;
        while (keyBinding.wasPressed()) {
            queued = true;
        }
        return queued;
    }

    private static void activateWeapon(MinecraftClient client, boolean spear) {
        var player = client.player;
        PlayerInventory inventory = player.getInventory();
        int weaponInventorySlot = findWeaponSlot(inventory, spear);
        if (weaponInventorySlot < 0) {
            return;
        }

        int selectedHotbarSlot = inventory.getSelectedSlot();
        if (weaponInventorySlot == selectedHotbarSlot) {
            ((MinecraftClientInvoker) (Object) client).trial$doAttack();
            return;
        }

        ScreenHandler handler = player.currentScreenHandler;
        int handlerSlotId = findHandlerSlot(handler, inventory, weaponInventorySlot);
        if (handlerSlotId < 0) {
            return;
        }

        client.interactionManager.clickSlot(
                handler.syncId,
                handlerSlotId,
                selectedHotbarSlot,
                SlotActionType.SWAP,
                player
        );
        try {
            ((MinecraftClientInvoker) (Object) client).trial$doAttack();
        } finally {
            client.interactionManager.clickSlot(
                    handler.syncId,
                    handlerSlotId,
                    selectedHotbarSlot,
                    SlotActionType.SWAP,
                    player
            );
        }
    }

    private static int findWeaponSlot(PlayerInventory inventory, boolean spear) {
        for (int slot = 0; slot < 36; slot++) {
            if (isWeapon(inventory.getStack(slot), spear)) {
                return slot;
            }
        }
        return -1;
    }

    private static boolean isWeapon(ItemStack stack, boolean spear) {
        var item = stack.getItem();
        if (!spear) {
            return item == Items.MACE;
        }
        return item == Items.WOODEN_SPEAR
                || item == Items.STONE_SPEAR
                || item == Items.COPPER_SPEAR
                || item == Items.IRON_SPEAR
                || item == Items.GOLDEN_SPEAR
                || item == Items.DIAMOND_SPEAR
                || item == Items.NETHERITE_SPEAR;
    }

    private static int findHandlerSlot(ScreenHandler handler, PlayerInventory inventory, int inventorySlot) {
        for (int slotId = 0; slotId < handler.slots.size(); slotId++) {
            Slot slot = handler.getSlot(slotId);
            if (slot.inventory == inventory && slot.getIndex() == inventorySlot) {
                return slotId;
            }
        }
        return -1;
    }
}