Leo Pilipovic
📎 1 file 1,309 chars
📄
pasted-code-1792933212744.txt
txt 20 lines
▶
# Update: Automatic Totem Mouse Targeting

Modify the NearestTotemFinder mod for Minecraft Java Fabric 26.3.

### Main Feature
When I open my inventory, automatically move the mouse cursor to the nearest Totem of Undying in my inventory.

### Requirements
- Search the entire player inventory, including the hotbar and main inventory.
- If one or more Totems of Undying are present, identify the nearest totem slot according to the cursor's current position.
- Automatically move the mouse cursor to the center of the selected totem's inventory slot.
- Do not just highlight the totem. The actual mouse cursor must move onto it.
- If multiple totems exist, select the one closest to the cursor's position when the inventory opens.
- If no totem exists, leave the mouse cursor unchanged.
- Add an ON/OFF toggle in the settings menu.
- Do not move, pick up, equip or use items automatically. Only move the mouse cursor.
- Keep the feature responsive and compatible with the inventory GUI.
- Build the finished mod and provide a working `NearestTotemFinder.jar` and a `NearestTotemFinder.zip` containing the complete source code and project files.

If the Minecraft or Fabric API prevents reliable cursor positioning, explain the limitation honestly and implement the closest working solution.
Kodari AI
KodariOct 25 at 1:09 pm 3
TotemCursorAim
Automatically moves the mouse cursor to the nearest Totem of Undying in the player's inventory when the inventory GUI opens. Searches the entire inventory including hotbar and main slots, calculates the closest totem relative to the cursor's current position, and positions the cursor at the center of that slot. Includes an ON/OFF toggle in the settings menu. Does not move, pick up, equip, or use items—only repositions the cursor. Responsive and compatible with the inventory GUI, with a fallback implementation if direct cursor positioning is restricted by Minecraft or Fabric API limitations.
  1. Verify 26.3 inventory-slot coordinates, cursor-positioning support, and mixin targets.

  2. Add the toggleable YACL settings integration and wire it to the cursor targeting feature.

  3. Create the complete Fabric project and source archive configuration.

Created the Fabric 26.3 project with automatic nearest-totem cursor targeting, a persistent ON/OFF setting in the ModMenu configuration screen, and a build task for the complete source archive.

The feature searches the main inventory and hotbar, chooses the totem closest to the cursor when the player inventory opens, and only moves the cursor—it does not interact with items. Minecraft 26.3 has no standalone cursor-position setter, so the mod uses its SDL cursor-warp method, which also releases mouse grab; the inventory screen is normally already ungrabbed.

To build and download the jar: click Compile in the top bar (on phone, ⋮ → Compile Project), click Compile in the window, then click Download for NearestTotemFinder.jar. The build is configured to create NearestTotemFinder.zip with the project source and files at build/distributions/NearestTotemFinder.zip.

Leo Pilipovic

The compilation failed with this error:

code
Compilation failed with 7 error(s):

ERROR in src/client/java/com/kodari/nearesttotemfinder/mixin/AbstractContainerScreenMixin.java at line 18: class TotemOffhandKeybind is public, should be declared in a file named TotemOffhandKeybind.java
public class TotemOffhandKeybind implements ClientModInitializer {
       ^

ERROR in src/client/java/com/kodari/nearesttotemfinder/mixin/AbstractContainerScreenMixin.java at line 6: package net.fabricmc.fabric.api.client.keybinding.v1 does not exist
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
                                                   ^

ERROR in src/client/java/com/kodari/nearesttotemfinder/mixin/AbstractContainerScreenMixin.java at line 11: cannot find symbol
import net.minecraft.world.inventory.ClickType;
                                    ^
  symbol: class ClickType
  location: package net.minecraft.world.inventory

ERROR in src/client/java/com/kodari/nearesttotemfinder/mixin/AbstractContainerScreenMixin.java at line 16: package org.lwjgl.glfw does not exist
import org.lwjgl.glfw.GLFW;
                     ^

ERROR in src/client/java/com/kodari/nearesttotemfinder/mixin/AbstractContainerScreenMixin.java at line 27: cannot find symbol
                GLFW.GLFW_KEY_R,
                ^
  symbol: variable GLFW
  location: class TotemOffhandKeybind

ERROR in src/client/java/com/kodari/nearesttotemfinder/mixin/AbstractContainerScreenMixin.java at line 24: cannot find symbol
        key = KeyBindingHelper.registerKeyBinding(
              ^
  symbol: variable KeyBindingHelper
  location: class TotemOffhandKeybind

ERROR in src/client/java/com/kodari/nearesttotemfinder/mixin/AbstractContainerScreenMixin.java at line 67: cannot find symbol
                    ClickType.SWAP,
                    ^
  symbol: variable ClickType
  location: class TotemOffhandKeybind


=== COMPILATION ERROR ANALYSIS ===

MISSING CLASSES:
  - ClickType
ACTION: Create these classes or check imports

FILES TO INVESTIGATE:
  - src/client/java/com/kodari/nearesttotemfinder/mixin/AbstractContainerScreenMixin.java

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

Kodari AI
KodariNov 15 at 8:15 am 2

Fixed the erroneous offhand-keybind code and replaced it with the inventory-screen cursor-targeting mixin. It searches the main inventory and hotbar, selects the totem nearest the opening cursor position, and warps the cursor without interacting with items. I also moved the mixin configuration into the resources folder so it’s included in the mod.

Compile in Kodari: click Compile in the top bar (on phone, ⋮ → Compile Project), then click Compile in the window. Download the resulting NearestTotemFinder.jar; the build also creates NearestTotemFinder.zip.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
manifest.kod
settings.gradle
Code
10 289
src/client/java/com/kodari/nearesttotemfinder/mixin/AbstractContainerScreenMixin.java

package com.kodari.nearesttotemfinder.mixin;

import com.kodari.nearesttotemfinder.client.NearestTotemFinderConfig;
import com.mojang.blaze3d.platform.Window;
import net.minecraft.client.Minecraft;
import net.minecraft.client.MouseHandler;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.gui.screens.inventory.InventoryScreen;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.Items;
import org.lwjgl.sdl.SDLMouse;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(AbstractContainerScreen.class)
public abstract class AbstractContainerScreenMixin {
    @Shadow
    @Final
    protected AbstractContainerMenu menu;

    @Shadow
    protected int leftPos;

    @Shadow
    protected int topPos;

    @Inject(method = "init", at = @At("TAIL"))
    private void nearesttotemfinder$moveCursorToNearestTotem(CallbackInfo callbackInfo) {
        if (!NearestTotemFinderConfig.isEnabled() || !(((Object) this) instanceof InventoryScreen)) {
            return;
        }

        Minecraft minecraft = Minecraft.getInstance();
        Window window = minecraft.getWindow();
        double mouseX = MouseHandler.getScaledXPos(window, minecraft.mouseHandler.xpos());
        double mouseY = MouseHandler.getScaledYPos(window, minecraft.mouseHandler.ypos());
        Slot nearestSlot = null;
        double nearestDistanceSquared = Double.POSITIVE_INFINITY;
        double nearestCenterX = 0.0;
        double nearestCenterY = 0.0;

        for (int index = InventoryMenu.INV_SLOT_START; index < InventoryMenu.USE_ROW_SLOT_END; index++) {
            Slot slot = this.menu.slots.get(index);
            if (slot.getItem().getItem() != Items.TOTEM_OF_UNDYING) {
                continue;
            }

            double centerX = this.leftPos + slot.x + 8.0;
            double centerY = this.topPos + slot.y + 8.0;
            double distanceX = centerX - mouseX;
            double distanceY = centerY - mouseY;
            double distanceSquared = distanceX * distanceX + distanceY * distanceY;

            if (distanceSquared < nearestDistanceSquared) {
                nearestSlot = slot;
                nearestDistanceSquared = distanceSquared;
                nearestCenterX = centerX;
                nearestCenterY = centerY;
            }
        }

        if (nearestSlot == null) {
            return;
        }

        double windowX = nearestCenterX * window.getScreenWidth() / window.getGuiScaledWidth();
        double windowY = nearestCenterY * window.getScreenHeight() / window.getGuiScaledHeight();
        SDLMouse.SDL_WarpMouseInWindow(window.handle(), (float) windowX, (float) windowY);
    }
}