claymc c

Create a client-side Fabric mod for Minecraft 1.21.11 that automatically refills the player's hotbar with a Totem of Undying from the main inventory whenever a hotbar slot is empty. Implement a toggle keybinding (default key X) to enable or disable this feature, along with an on-screen status message that clearly indicates whether auto-refill is ON or OFF, providing real-time user feedback. Additionally, ensure the mod has a configuration file for customizable keybindings and to allow players to specify the type of item to refill.

Kodari AI
KodariSep 14 at 1:21 pm 1
AutoTotemRefill
Client-side Fabric mod for Minecraft 1.21.11 that automatically refills empty hotbar slots with Totems of Undying from the main inventory. Features a toggle keybinding (default X) with on-screen status messages indicating ON/OFF state, and a configuration file for customizing the keybinding and refill item type. Provides real-time feedback and seamless inventory management.

I’ll create the Fabric 1.21.11 client mod with:

  1. A split-source-set Fabric project and metadata.

  2. JSON configuration for the toggle key and refill item.

  3. Hotbar auto-refill logic with server-safe inventory interaction.

  4. An X keybinding and real-time ON/OFF status feedback.

  5. Required language and item/config resources.

  1. Created a Fabric 1.21.11 client mod project using Yarn mappings and split client source sets.

  2. Added JSON configuration generation at .minecraft/config/autorefill.json:

    • enabled

    • toggleKeyCode — defaults to X

    • refillItem — defaults to minecraft:totem_of_undying

  3. Implemented automatic refilling from inventory slots into empty hotbar slots.

  4. Added the X keybinding to toggle the feature.

  5. Added actionbar status feedback showing Auto-refill: ON or OFF.

  6. Added Fabric metadata, Gradle configuration, and English translations.

claymc c

The compilation failed with this error:

code
Compilation failed with 2 error(s):

ERROR in src/main/java/com/kodari/autorefill/config/ConfigManager.java at line 41: cannot find symbol
                    : Registries.ITEM.getOrEmpty(identifier).orElse(Items.TOTEM_OF_UNDYING);
                                     ^
  symbol: method getOrEmpty(Identifier)
  location: variable ITEM of type DefaultedRegistry<Item>

ERROR in   src/main/java/com/kodari/autorefill/config/ConfigManager.java at line 41: cannot find symbol
                      : Registries.ITEM.getOrEmpty(identifier).orElse(Items.TOTEM_OF_UNDYING);
                                       ^
  symbol: method getOrEmpty(Identifier)
  location: variable ITEM of type DefaultedRegistry<Item>


=== COMPILATION ERROR ANALYSIS ===

MISSING METHODS:
  - getOrEmpty(Identifier)
ACTION: Check method names and signatures

FILES TO INVESTIGATE:
  - src/main/java/com/kodari/autorefill/config/ConfigManager.java
  -   src/main/java/com/kodari/autorefill/config/ConfigManager.java

Please fix this error by creating a new artifact with the corrected code.

Kodari AI
KodariSep 14 at 1:22 pm 1

Fixed ConfigManager.java by replacing the removed Registries.ITEM.getOrEmpty(...) call with the 1.21.11-compatible getOptional(...) lookup, preserving the Totem fallback for invalid or missing items.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
9 316
src/client/java/com/kodari/autorefill/AutoRefillModClient.java
package com.kodari.autorefill;

import com.kodari.autorefill.config.AutoRefillConfig;
import com.kodari.autorefill.config.ConfigManager;
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.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.slot.SlotActionType;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

public class AutoRefillModClient implements ClientModInitializer {
    private static final KeyBinding.Category KEY_CATEGORY =
            KeyBinding.Category.create(Identifier.of(AutoRefillMod.MOD_ID, "keybinds"));

    private static KeyBinding toggleKey;
    private static PlayerEntity lastPlayer;

    @Override
    public void onInitializeClient() {
        AutoRefillConfig config = ConfigManager.getConfig();
        toggleKey = KeyBindingHelper.registerKeyBinding(
                new KeyBinding("key.autorefill.toggle", config.toggleKeyCode, KEY_CATEGORY));

        ClientTickEvents.END_CLIENT_TICK.register(AutoRefillModClient::onClientTick);
    }

    private static void onClientTick(MinecraftClient client) {
        if (client.player == null) {
            lastPlayer = null;
            return;
        }

        if (client.player != lastPlayer) {
            lastPlayer = client.player;
            showStatus(client, ConfigManager.getConfig().enabled);
        }

        while (toggleKey.wasPressed()) {
            AutoRefillConfig config = ConfigManager.getConfig();
            config.enabled = !config.enabled;
            ConfigManager.save();
            showStatus(client, config.enabled);
        }

        AutoRefillConfig config = ConfigManager.getConfig();
        if (!config.enabled || client.currentScreen != null || client.interactionManager == null) {
            return;
        }

        refillOneSlot(client, ConfigManager.getRefillItem());
    }

    private static void refillOneSlot(MinecraftClient client, Item refillItem) {
        PlayerEntity player = client.player;
        ItemStack[] hotbar = new ItemStack[9];
        for (int hotbarSlot = 0; hotbarSlot < hotbar.length; hotbarSlot++) {
            hotbar[hotbarSlot] = player.getInventory().getStack(hotbarSlot);
        }

        for (int hotbarSlot = 0; hotbarSlot < hotbar.length; hotbarSlot++) {
            if (!hotbar[hotbarSlot].isEmpty()) {
                continue;
            }

            for (int inventorySlot = 9; inventorySlot < 36; inventorySlot++) {
                if (!player.getInventory().getStack(inventorySlot).isOf(refillItem)) {
                    continue;
                }

                int hotbarScreenSlot = 36 + hotbarSlot;
                client.interactionManager.clickSlot(
                        player.currentScreenHandler.syncId,
                        inventorySlot,
                        0,
                        SlotActionType.PICKUP,
                        player);
                client.interactionManager.clickSlot(
                        player.currentScreenHandler.syncId,
                        hotbarScreenSlot,
                        0,
                        SlotActionType.PICKUP,
                        player);
                return;
            }
        }
    }

    private static void showStatus(MinecraftClient client, boolean enabled) {
        Text state = Text.translatable(enabled ? "message.autorefill.on" : "message.autorefill.off");
        client.player.sendMessage(Text.translatable("message.autorefill.status", state), true);
    }
}