vremzzxd

Act as a senior Minecraft Java mod developer for Minecraft version 1.21.11 (Fabric). I want to create a simple educational mod to learn how to:

  • Bind a GUI to the right shift (Sneak) key.
  • Open a custom screen when that key is pressed.
  • Implement basic entity interaction logic in a clean, modular way.

Provide:

  1. A brief explanation of the required dependencies and setup (Fabric API, etc.).
  2. The keybinding registration code (for right shift / Sneak).
  3. The GUI/Screen class structure with a simple layout (e.g., a button or toggle).
  4. A sample tick handler or event listener that checks for nearby entities and logs their names/positions (for learning purposes, no combat automation).
  5. Example of how to register the mod in fabric.mod.json.

Write the code in Java, with comments explaining each part. Keep it simple, safe, and suitable for a beginner modder. Do not include any code that automates aiming, attacks, or gives unfair gameplay advantages.

Kodari AI
KodariSep 3 at 6:45 pm 1
KeybindEntityInspector
An educational Fabric mod for Minecraft 1.21.11 that teaches keybinding, custom GUI screens, and entity interaction. Registers a right-shift keybind that opens a simple screen with a toggle button. Includes a tick handler that logs nearby entity names and positions for learning purposes. Clean modular structure with commented Java code, safe for beginners, no combat automation.
  1. Set up the Fabric 1.21.11 project metadata and Gradle configuration.

  2. Add common initialization plus modular nearby-entity inspection logic.

  3. Add client keybinding, screen, and client tick handling.

  4. Add resources for the mod manifest and language text.

Created a complete Fabric 1.21.11 educational mod project.

  • Dependencies and setup

    • Minecraft 1.21.11

    • Yarn mappings 1.21.11+build.5

    • Fabric Loader 0.19.2

    • Fabric API 0.141.4+1.21.11

    • Fabric Loom 1.14

    • Java 21

    • No third-party libraries are required.

  • Right Shift keybinding

    • Registered in NearbyInspectorClient.

    • Uses GLFW.GLFW_KEY_RIGHT_SHIFT.

    • Pressing the key opens NearbyInspectorScreen.

    • The key remains configurable through Minecraft’s Controls menu.

  • GUI

    • NearbyInspectorScreen provides:

      • A title and description.

      • A details toggle button.

      • A close button.

      • Non-pausing screen behavior.

  • Entity inspection

    • NearbyEntityScanner contains the reusable scanning logic.

    • NearbyEntityInspector runs from the client tick handler.

    • Every second, it searches within 8 blocks and logs entity names and positions.

    • It only observes entities and performs no targeting, combat, or automation.

  • Registration and resources

    • Added fabric.mod.json.

    • Added English translations for the keybinding, category, screen, and buttons.

    • Client code uses the required src/client/java source set.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
10 298
src/client/java/com/example/nearbyinspector/NearbyInspectorClient.java
package com.example.nearbyinspector;

import com.example.nearbyinspector.client.NearbyEntityInspector;
import com.example.nearbyinspector.client.NearbyInspectorScreen;
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.client.util.InputUtil;
import net.minecraft.util.Identifier;
import org.lwjgl.glfw.GLFW;

public final class NearbyInspectorClient implements ClientModInitializer {
    private static final KeyBinding OPEN_SCREEN_KEY = new KeyBinding(
            "key.nearbyinspector.open_screen",
            GLFW.GLFW_KEY_RIGHT_SHIFT,
            KeyBinding.Category.create(Identifier.of(NearbyInspectorMod.MOD_ID, "keys"))
    );

    @Override
    public void onInitializeClient() {
        // Fabric's helper registers this client-only key with Minecraft's options screen.
        KeyBindingHelper.registerKeyBinding(OPEN_SCREEN_KEY);

        // One client tick is enough for both input handling and the learning scanner.
        ClientTickEvents.END_CLIENT_TICK.register(this::onClientTick);
    }

    private void onClientTick(MinecraftClient client) {
        while (OPEN_SCREEN_KEY.wasPressed()) {
            if (client.currentScreen == null) {
                client.setScreen(new NearbyInspectorScreen());
            }
        }

        NearbyEntityInspector.tick(client);
    }
}