newgamerisback

Create a mod 1.21.11 fabric that opens the chat and executes the /sellgui command and sell all the stuff in inventory and make it so it works without flaws and even while a player is afk

Kodari AI
KodariTue at 11:13 am 1
AutoSellAll
AutoSellAll is a Fabric mod for Minecraft 1.21.11 that automatically opens the chat and executes the /sellgui command, selling all items in the player's inventory. It works flawlessly even while the player is AFK, ensuring continuous selling without requiring manual interaction. The mod integrates seamlessly with the game's command system, providing a hands-free selling experience for efficient inventory management.

How does /sellgui work on your server: does it have a Sell All button, or do items need to be moved into the GUI? If there’s a button, which slot is it in?

Also, how often should the mod sell while you’re AFK? The server must allow the command and keep the player connected.

newgamerisback

yes it doesnt have any button just type /sellgui nd place the whole inventory stuff in it then close the gui it sells it automatically so u just need to close the gui after insertigthe items

Kodari AI
KodariTue at 12:20 pm 2
  • Add a client-side toggle that runs /sellgui once per minute while you’re connected.

  • Shift-click inventory stacks into the opened container, then close it to trigger the sale.

  • Stop safely if the expected container doesn’t open or the screen changes.

Press V to toggle automatic selling. The mod runs /sellgui, shift-clicks inventory stacks into the container, closes it, and repeats every minute while enabled.

This depends on the server accepting shift-clicks in its sell GUI. It won’t prevent an AFK kick, and items the GUI doesn’t accept may remain unsold. Keep other menus closed while it opens /sellgui.

newgamerisback

make it the way that it should also work when minecraft is minimised like in escape menu

Kodari AI
KodariTue at 12:32 pm 2

I’ll allow selling from the Escape menu and restore that menu after the sale. Minimizing won’t stop the client-side timer.

AFK selling now works while Minecraft is minimized or the Escape menu is open. The Escape menu returns after each sale.

Minecraft must stay running and connected; the mod won’t prevent server AFK kicks. In single-player, selling waits while the game is paused.

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

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.gui.screen.GameMenuScreen;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.screen.GenericContainerScreenHandler;
import net.minecraft.screen.slot.Slot;
import net.minecraft.screen.slot.SlotActionType;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import org.lwjgl.glfw.GLFW;

public class AfkSellClient implements ClientModInitializer {
    private static final int INTERVAL = 20 * 60;
    private static final int OPEN_TIMEOUT = 20 * 5;
    private static final int CLICK_DELAY = 4;

    private KeyBinding toggle;
    private boolean enabled;
    private int cooldown;
    private int waitTicks;
    private int nextSlot;
    private GenericContainerScreenHandler activeHandler;
    private boolean waitingForMenu;
    private boolean restorePauseMenu;

    @Override
    public void onInitializeClient() {
        KeyBinding.Category category = KeyBinding.Category.create(Identifier.of("afksell", "controls"));
        toggle = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.afksell.toggle", GLFW.GLFW_KEY_V, category));
        ClientTickEvents.END_CLIENT_TICK.register(this::tick);
    }

    private void tick(MinecraftClient client) {
        while (toggle.wasPressed()) {
            enabled = !enabled;
            waitingForMenu = false;
            activeHandler = null;
            restorePauseMenu = false;
            cooldown = 0;
            if (client.player != null) {
                client.player.sendMessage(Text.literal("AFK Sell: " + (enabled ? "enabled" : "disabled")), false);
            }
        }

        if (client.player == null || client.interactionManager == null) {
            enabled = false;
            waitingForMenu = false;
            activeHandler = null;
            restorePauseMenu = false;
            return;
        }
        if (!enabled) return;

        if (activeHandler != null) {
            if (!(client.currentScreen instanceof HandledScreen<?> screen)
                    || screen.getScreenHandler() != activeHandler
                    || client.player.currentScreenHandler != activeHandler) {
                activeHandler = null;
                restorePauseMenu = false;
                cooldown = INTERVAL;
                return;
            }
            if (!activeHandler.getCursorStack().isEmpty()) {
                enabled = false;
                activeHandler = null;
                restorePauseMenu = false;
                client.player.sendMessage(Text.literal("AFK Sell stopped: an item is on the cursor."), false);
                return;
            }
            if (waitTicks-- > 0) return;
            while (nextSlot < activeHandler.slots.size()) {
                Slot slot = activeHandler.slots.get(nextSlot++);
                if (slot.inventory == client.player.getInventory() && slot.hasStack()) {
                    client.interactionManager.clickSlot(activeHandler.syncId, slot.id, 0, SlotActionType.QUICK_MOVE, client.player);
                    waitTicks = CLICK_DELAY;
                    return;
                }
            }
            client.player.closeHandledScreen();
            activeHandler = null;
            if (restorePauseMenu && client.currentScreen == null) {
                client.setScreen(new GameMenuScreen(true));
            }
            restorePauseMenu = false;
            cooldown = INTERVAL;
            return;
        }

        if (waitingForMenu) {
            if (client.currentScreen != null && !(client.currentScreen instanceof GameMenuScreen)) {
                waitingForMenu = false;
                if (client.currentScreen instanceof HandledScreen<?> screen
                        && screen.getScreenHandler() instanceof GenericContainerScreenHandler handler
                        && client.player.currentScreenHandler == handler
                        && handler.getCursorStack().isEmpty()) {
                    activeHandler = handler;
                    nextSlot = handler.getRows() * 9;
                    waitTicks = 10;
                } else {
                    enabled = false;
                    restorePauseMenu = false;
                    client.player.sendMessage(Text.literal("AFK Sell stopped: the opened screen is not a compatible container."), false);
                }
            } else if (--waitTicks <= 0) {
                waitingForMenu = false;
                enabled = false;
                restorePauseMenu = false;
                client.player.sendMessage(Text.literal("AFK Sell stopped: /sellgui did not open a container."), false);
            }
            return;
        }

        if (cooldown > 0) {
            cooldown--;
            return;
        }
        if (client.isPaused() || (client.currentScreen != null && !(client.currentScreen instanceof GameMenuScreen))
                || client.player.currentScreenHandler != client.player.playerScreenHandler) return;
        restorePauseMenu = client.currentScreen instanceof GameMenuScreen;
        client.player.networkHandler.sendChatCommand("sellgui");
        waitingForMenu = true;
        waitTicks = OPEN_TIMEOUT;
    }
}