Miller Kids

make me an autototem that works on servers like donut smp but it only puts the totem in my offhand when i open my inv with y on my controller or the inv open button on my keyboard it better get past anti cheats and i need to be able to customize the time it tkes to be put in my offhand when my inv is open

Kodari AI
KodariMon at 6:49 pm 2
AutoTotemSwap
Client-side Fabric mod that automatically places a totem of undying into the player's offhand when inventory is opened via the inventory key (Y on controller or E on keyboard). Features configurable delay timing for the swap operation, designed to work on servers with anti-cheat systems by mimicking natural player behavior. Includes config file for customizing swap delay in milliseconds, with a simple toggle system to enable or disable the auto-swap functionality. Works seamlessly with vanilla inventory mechanics and respects server-side validation.
  • Equip through a normal inventory slot click, only while your inventory is open.

  • Add a persistent, adjustable delay via a client-side command.

  • Server anti-cheat compatibility can’t be guaranteed.

Created the client-side AutoTotem. It swaps a totem from your inventory into your offhand only while your player inventory is open, regardless of whether you opened it with a keyboard or controller.

Set the delay with /autototem delay <milliseconds>; the default is 500 ms. The setting persists across restarts. It uses a normal inventory click, but compatibility with any server’s anti-cheat is not guaranteed.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
5 196
src/client/java/com/kodari/autototem/InventoryAutoTotemClient.java
package com.kodari.autototem;

import com.mojang.brigadier.arguments.IntegerArgumentType;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.ingame.InventoryScreen;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.Items;
import net.minecraft.screen.slot.Slot;
import net.minecraft.screen.slot.SlotActionType;
import net.minecraft.text.Text;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Properties;

public class InventoryAutoTotemClient implements ClientModInitializer {
    private static final int DEFAULT_DELAY_MS = 500;
    private static final int MAX_DELAY_MS = 60000;
    private final Path configPath = FabricLoader.getInstance().getConfigDir().resolve("inventory-autototem.properties");
    private int delayMs = DEFAULT_DELAY_MS;
    private long waitingSince = -1;
    private long lastAttempt = -1;

    @Override
    public void onInitializeClient() {
        loadConfig();
        ClientTickEvents.END_CLIENT_TICK.register(this::tick);
        ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(
            ClientCommandManager.literal("autototem")
                .executes(context -> {
                    context.getSource().sendFeedback(Text.literal("AutoTotem delay: " + delayMs + " ms. Set it with /autototem delay <milliseconds>."));
                    return 1;
                })
                .then(ClientCommandManager.literal("delay")
                    .then(ClientCommandManager.argument("milliseconds", IntegerArgumentType.integer(0, MAX_DELAY_MS))
                        .executes(context -> {
                            delayMs = IntegerArgumentType.getInteger(context, "milliseconds");
                            waitingSince = -1;
                            boolean saved = saveConfig();
                            context.getSource().sendFeedback(Text.literal("AutoTotem delay set to " + delayMs + " ms" + (saved ? "." : " (could not save settings).")));
                            return 1;
                        })))
        ));
    }

    private void tick(MinecraftClient client) {
        if (client.player == null || client.interactionManager == null
                || !(client.currentScreen instanceof InventoryScreen)
                || client.player.currentScreenHandler != client.player.playerScreenHandler
                || client.player.getOffHandStack().isOf(Items.TOTEM_OF_UNDYING)) {
            waitingSince = -1;
            return;
        }

        long now = System.nanoTime();
        if (waitingSince == -1) {
            waitingSince = now;
        }
        if (now - waitingSince < delayMs * 1_000_000L
                || (lastAttempt != -1 && now - lastAttempt < 1_000_000_000L)) {
            return;
        }

        PlayerInventory inventory = client.player.getInventory();
        for (Slot slot : client.player.currentScreenHandler.slots) {
            if (slot.inventory == inventory && slot.getIndex() >= 0 && slot.getIndex() < 36
                    && inventory.getStack(slot.getIndex()).isOf(Items.TOTEM_OF_UNDYING)) {
                client.interactionManager.clickSlot(client.player.currentScreenHandler.syncId, slot.id, 40,
                    SlotActionType.SWAP, client.player);
                lastAttempt = now;
                waitingSince = -1;
                return;
            }
        }
    }

    private void loadConfig() {
        if (!Files.isRegularFile(configPath)) {
            return;
        }
        Properties properties = new Properties();
        try (InputStream input = Files.newInputStream(configPath)) {
            properties.load(input);
            int value = Integer.parseInt(properties.getProperty("delay_ms", Integer.toString(DEFAULT_DELAY_MS)));
            delayMs = Math.max(0, Math.min(MAX_DELAY_MS, value));
        } catch (IOException | IllegalArgumentException ignored) {
            delayMs = DEFAULT_DELAY_MS;
        }
    }

    private boolean saveConfig() {
        Properties properties = new Properties();
        properties.setProperty("delay_ms", Integer.toString(delayMs));
        try {
            Files.createDirectories(configPath.getParent());
            try (OutputStream output = Files.newOutputStream(configPath)) {
                properties.store(output, "Inventory AutoTotem settings");
            }
            return true;
        } catch (IOException exception) {
            return false;
        }
    }
}