realprinario-ctrl

Create a mod for Fabric 26.2 Name: "ShadowSwap" What is it?

A auto-spear swapper mod that when the key is pressed, it swaps to the nearest spear on your hotbar and clicks. (Lunge Swapping) It has in built delay to bypass anticheat whilst still keeping that snappy swapping.

You can edit the keybind in the Menu of Minecraft Keybinds (default Left CRTL)

Kodari AI
KodariOct 7 at 12:10 am 1
ShadowSwap
ShadowSwap is a Fabric mod that enables instant spear lunge-swapping in Minecraft. When the configured keybind (default Left Control) is pressed, the mod automatically scans the player's hotbar for the nearest spear, swaps to it, and performs a lunge attack. It includes a built-in configurable delay system to bypass anti-cheat detection while maintaining snappy, responsive swapping. The keybind is fully customizable through Minecraft's standard keybind settings menu, allowing players to assign their preferred key. The mod enhances combat fluidity for spear users, providing seamless weapon transitions during PvP or PvE encounters without manual hotbar management.
  1. Set up the Fabric 26.2 project and client entrypoint.

  2. Register a Left Ctrl keybind visible in Minecraft’s Controls menu.

  3. On press, select the nearest spear in the hotbar and trigger its use with a short built-in delay.

Created ShadowSwap for Fabric 26.2. Press Left Ctrl to select the nearest vanilla spear in your hotbar and use it after a 2-tick delay. You can change the key in Options → Controls.

realprinario-ctrl

Its not supposed to use the spear, its supposed to left click your mouse to lunge.

Kodari AI
KodariOct 7 at 8:57 pm 2

Changed ShadowSwap to queue a vanilla left-mouse click after the 2-tick delay instead of calling useItem. The spear’s attack—and its Lunge effect when applicable—now runs through the normal attack path.

realprinario-ctrl

It has to be in the same ticket it's not actually swapping at lunging at all

Kodari AI
KodariOct 7 at 9:15 pm 2
  • Process the keybind at the start of the client tick.

  • Select the nearest hotbar spear and queue vanilla left-click input for that same tick.

  • Remove the extra delay so the selected spear is active when Minecraft handles the click.

Updated ShadowSwap to select the nearest spear and queue a vanilla left-click in the same client tick. The previous 2-tick delay is removed, so Minecraft processes the click after the slot swap.

realprinario-ctrl

It also needs to swap back to your latest hotbar slot

Lets say I use it while I'm holding something in sot 4, it: Switches to the spear, then back to slot 4.

Kodari AI
KodariOct 7 at 9:17 pm 1
  • Save the selected hotbar slot before switching to the nearest spear.

  • Restore that slot at client-tick end, after vanilla has processed the queued left click.

ShadowSwap now remembers the selected hotbar slot, switches to the nearest spear for the queued left-click, then restores the original slot at the end of that client tick—after Minecraft processes the attack.

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

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.world.InteractionHand;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;

public class ShadowSwapClient implements ClientModInitializer {
	private static final KeyMapping LUNGE_SWAP_KEY = KeyMappingHelper.registerKeyMapping(
		new KeyMapping("key.shadowswap.lunge_swap", InputConstants.Type.KEYSYM, 341, KeyMapping.Category.MISC)
	);
	private int slotToRestore = -1;

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

	private void onStartClientTick(Minecraft client) {
		if (client.player == null || client.gameMode == null) {
			while (LUNGE_SWAP_KEY.consumeClick()) {
			}
			return;
		}

		if (LUNGE_SWAP_KEY.consumeClick()) {
			Inventory inventory = client.player.getInventory();
			int spearSlot = findNearestSpear(inventory);
			if (spearSlot >= 0) {
				slotToRestore = inventory.getSelectedSlot();
				inventory.setSelectedSlot(spearSlot);
				KeyMapping.click(InputConstants.Type.MOUSE.getOrCreate(0));
			}
		}
	}

	private void onEndClientTick(Minecraft client) {
		if (slotToRestore < 0) {
			return;
		}

		int selectedSlot = slotToRestore;
		slotToRestore = -1;
		if (client.player != null) {
			client.player.getInventory().setSelectedSlot(selectedSlot);
		}
	}

	private static int findNearestSpear(Inventory inventory) {
		int selectedSlot = inventory.getSelectedSlot();
		int nearestSlot = -1;
		int nearestDistance = Integer.MAX_VALUE;

		for (int slot = 0; slot < 9; slot++) {
			if (isSpear(inventory.getItem(slot))) {
				int distance = Math.abs(slot - selectedSlot);
				if (distance < nearestDistance) {
					nearestDistance = distance;
					nearestSlot = slot;
				}
			}
		}

		return nearestSlot;
	}

	private static boolean isSpear(ItemStack stack) {
		Item item = stack.getItem();
		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;
	}
}