Bernardo Gonçalves

um mod do Fabric para a versão 1.21 onde o jogador duplica o item que tem na mão se ficar a agachar-se durante 1 segundo

Kodari AI
KodariOct 23 at 7:39 pm 1
DuckSquatDuplicator
Fabric mod for Minecraft 1.21 that duplicates the item held in the player's hand when they crouch (hold the crouch key) for a continuous duration of 1 second. Once the crouch timer reaches the threshold, the held item is duplicated in the player's inventory. The mod tracks crouch state per player, resets the timer if the player stops crouching or switches items, and provides a configurable cooldown to prevent rapid duplication. Works in both single-player and multiplayer, with server-side validation to prevent cheating.

Criei o mod Fabric para Minecraft 1.21: após 20 ticks agachado (aproximadamente 1 segundo), duplica uma cópia do stack na mão principal. A duplicação acontece uma vez por agachamento; se o inventário estiver cheio, o item restante cai no chão.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
5 136
src/main/java/com/kodari/sneakduplication/SneakDuplication.java
package com.kodari.sneakduplication;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.PlayerTickEvents;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.minecraft.item.ItemStack;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public class SneakDuplication implements ModInitializer {
    private static final int DUPLICATION_DELAY_TICKS = 20;
    private static final Map<UUID, Integer> SNEAK_TICKS = new HashMap<>();

    @Override
    public void onInitialize() {
        PlayerTickEvents.END_PLAYER_TICK.register(player -> {
            UUID playerId = player.getUuid();

            if (!player.isSneaking()) {
                SNEAK_TICKS.remove(playerId);
                return;
            }

            ItemStack heldItem = player.getMainHandStack();
            if (heldItem.isEmpty()) {
                SNEAK_TICKS.remove(playerId);
                return;
            }

            int sneakTicks = SNEAK_TICKS.getOrDefault(playerId, 0);
            if (sneakTicks >= DUPLICATION_DELAY_TICKS) {
                return;
            }

            sneakTicks++;
            if (sneakTicks < DUPLICATION_DELAY_TICKS) {
                SNEAK_TICKS.put(playerId, sneakTicks);
                return;
            }

            ItemStack duplicate = heldItem.copy();
            player.getInventory().insertStack(duplicate);
            if (!duplicate.isEmpty()) {
                player.dropItem(duplicate, false);
            }
            SNEAK_TICKS.put(playerId, DUPLICATION_DELAY_TICKS);
        });

        ServerPlayConnectionEvents.DISCONNECT.register((handler, server) ->
                SNEAK_TICKS.remove(handler.player.getUuid()));
    }
}