Hdh
📎 1 file 2,287 chars
📄
pasted-code-1793123169610.txt
txt 15 lines
▶
Project Name: PlayerItemCopier (Client-side Mod for Fabric 1.21.11)
📌 Core Feature
This mod adds a single, streamlined feature: instantly copying an item directly from another player's hand. Whenever you look at another player and press the X key, the item they are currently holding in their main hand is instantly duplicated and placed directly into your active hotbar slot.
🛠 How It Works (Mod Logic)
1. Keybinding Setup: The mod registers a brand-new hotkey (X) in the game options. You can easily rebind this to any other key later using Minecraft's standard "Controls" menu.
2. Crosshair Targeting: When you press X, the mod checks exactly what your crosshair is pointing at. If you are looking at empty space, blocks, or non-player entities (like a cow), nothing happens except for a brief notification telling you to aim at a player.
3. Creative Mode Security Check: This is a crucial rule built into the mod. It functions only if you are currently in Creative Mode. If you try to use it in Survival or Adventure mode, the mod safely blocks the action and displays a text message stating you don't have permission.
4. Exact Data Replication: When aimed at a player, the mod reads the item in their hand and generates a 100% identical copy. The item's custom display name, enchantments, and all associated properties are extracted and transferred completely as they are seen by the client, regardless of any server-side plugins or systems. It copies absolutely all visible and hidden item data and components available to the player:
	• Enchantments (including custom levels or combinations over the vanilla limits).
	• Custom item names, colored text, lore, and descriptions.
	• Tool durability, remaining potion charges, banner patterns, or firework effects.
	• Any custom data components added by server-side plugins that are present on the item.
5. Inventory Update: The cloned item is instantly pushed into your currently selected hotbar slot, overwriting whatever was there. The client then sends a creative inventory action to the server, making the item fully real and ready to use.
🚀 Project Generation and Creating the Ready .jar File
Please automatically write the program code for this mod, compile it, and create an installation-ready file with the .jar extension.
Kodari AI
KodariOct 27 at 5:54 pm 2
PlayerItemCopier
Client-side Fabric mod for Minecraft 1.21.11 that duplicates items from other players' hands with a single keypress. Press X while aiming at a player in Creative Mode to copy their held item's complete data—enchantments, custom names, lore, durability, and all components—into your active hotbar slot. Includes crosshair targeting validation, Creative Mode security checks, user notifications for invalid targets, and rebindable keybinding. The copied item is synced to the server via creative inventory actions, making it fully functional.
  1. Create a minimal Fabric 1.21.11 client mod project and register the X keybind.

  2. Implement crosshair targeting, creative-mode gating, item-stack copying, hotbar replacement, and feedback.

  3. Explain the in-platform steps to compile and download the JAR.

  1. Added the Fabric 1.21.11 client mod. Press X while aiming at a player to copy their main-hand item into your selected hotbar slot; the key is rebindable in Controls. It only works in Creative mode.

  2. The mod copies item components available to your client and submits the update through the normal creative inventory action. The server remains authoritative, so this cannot bypass server permissions or recover data the client does not have.

  3. To get the JAR: click Compile in the desktop top bar, or ⋮ → Compile Project on mobile; click Compile in the window; when it succeeds, click Download on the build or the Download playeritemcopier.jar button in chat.

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

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.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.hit.EntityHitResult;
import org.lwjgl.glfw.GLFW;

public final class PlayerItemCopierClient implements ClientModInitializer {
    private static final KeyBinding COPY_ITEM_KEY = KeyBindingHelper.registerKeyBinding(
            new KeyBinding(
                    "key.playeritemcopier.copy",
                    GLFW.GLFW_KEY_X,
                    KeyBinding.Category.create(Identifier.of("playeritemcopier", "general"))
            )
    );

    @Override
    public void onInitializeClient() {
        ClientTickEvents.END_CLIENT_TICK.register(client -> {
            while (COPY_ITEM_KEY.wasPressed()) {
                copyTargetItem(client);
            }
        });
    }

    private static void copyTargetItem(MinecraftClient client) {
        if (client.player == null || client.interactionManager == null) {
            return;
        }

        if (!client.player.getAbilities().creativeMode) {
            client.player.sendMessage(Text.translatable("message.playeritemcopier.creative_only"), true);
            return;
        }

        if (!(client.crosshairTarget instanceof EntityHitResult hit)
                || !(hit.getEntity() instanceof PlayerEntity target)) {
            client.player.sendMessage(Text.translatable("message.playeritemcopier.aim_at_player"), true);
            return;
        }

        ItemStack targetStack = target.getMainHandStack();
        if (targetStack.isEmpty()) {
            client.player.sendMessage(Text.translatable("message.playeritemcopier.empty_hand"), true);
            return;
        }

        int selectedSlot = client.player.getInventory().getSelectedSlot();
        ItemStack copiedStack = targetStack.copy();
        client.player.getInventory().setStack(selectedSlot, copiedStack);
        client.interactionManager.clickCreativeStack(copiedStack, 36 + selectedSlot);
        client.player.sendMessage(Text.translatable("message.playeritemcopier.copied"), true);
    }
}