Humera Khan

Create a real, buildable Minecraft Java mod called Red Target Crosshair.

Technical requirements

  • Minecraft Java Edition 1.21.4 ONLY
  • Mod loader: Fabric
  • Java 21
  • Use compatible Fabric Loader, Fabric API, Yarn mappings, and Gradle versions.
  • Keep the source ZIP as small as reasonably possible, ideally under 20 KB.

Main feature

  1. Detect when the player's crosshair is directly targeting another player entity.
  2. When targeting another player, change the crosshair to red.
  3. When targeting anything else, restore the normal Minecraft crosshair.
  4. The color change must happen smoothly and update in real time.
  5. Do not change the crosshair when aiming at yourself, blocks, mobs, or empty space.

Implementation requirements

  • Use Java and Fabric APIs compatible with Minecraft 1.21.4.
  • Use a client-side HUD rendering approach or an appropriate crosshair rendering hook.
  • Avoid unnecessary dependencies and performance overhead.
  • Do not include auto-attacks, aim assistance, weapon switching, or other combat automation.
  • Keep the implementation lightweight and compatible with multiplayer.

Deliverables

  1. Create the actual project files, not just example code.
  2. Include "build.gradle", "settings.gradle", "gradle.properties", "fabric.mod.json", and all required Java source files.
  3. compile the project and provide the resulting ".jar".
  4. Verify the build before claiming that the mod works.
  5. Give clear instructions for installing the mod and testing it.
  6. If a build fails, diagnose and fix the error rather than claiming success.

Important: Do not merely explain how to create the mod. Generate the actual project files and provide a working download if file-generation tools are available.

Kodari AI
KodariOct 28 at 10:05 am 2
RedTargetCrosshair
Client-side Fabric mod for Minecraft 1.21.4 that changes the crosshair to red when aiming at another player. Uses HUD rendering hook to detect player entities in crosshair and smoothly interpolate the crosshair color in real time. Restores standard crosshair when targeting non-player entities or empty space. Lightweight, multiplayer-compatible, no combat automation.
  1. Look up the exact 1.21.4 crosshair, hit-test, and drawing signatures in the mounted source.

  2. Create a minimal Fabric/Gradle client mod with a smooth red transition and a mixin that leaves vanilla rendering untouched outside the transition.

  3. Provide the project for Kodari’s build flow; I can’t run the build tool here or produce a verified jar.

Created a lightweight Fabric 1.21.4 client mod project. It smoothly fades the crosshair red when targeting another player and restores vanilla rendering when the target changes. It leaves the crosshair unchanged for blocks, mobs, yourself, and empty space.

Build status: I couldn’t run Gradle here, so the build is not verified and there’s no jar to download yet. In Kodari, click Compile in the top bar (or ⋮ → Compile Project on mobile), then click Compile in the window. Download the jar from the successful build.

Install and test: Use Minecraft 1.21.4 with Fabric Loader and Fabric API, put the downloaded jar in the instance’s mods folder, and launch the game. In first-person, aim at another player to test the red fade; aim away to see it fade back to vanilla.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
6 158
src/main/java/com/kodari/redtargetcrosshair/mixin/InGameHudMixin.java
package com.kodari.redtargetcrosshair.mixin;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.hud.InGameHud;
import net.minecraft.client.render.RenderTickCounter;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.hit.EntityHitResult;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(InGameHud.class)
public abstract class InGameHudMixin {
    private static final double TRANSITION_NANOS = 85_000_000.0;
    private static long lastUpdateNanos;
    private static float redAmount;

    @Inject(
            method = "renderCrosshair(Lnet/minecraft/client/gui/DrawContext;Lnet/minecraft/client/render/RenderTickCounter;)V",
            at = @At("HEAD"),
            cancellable = true
    )
    private void redtargetcrosshair$renderTargetCrosshair(DrawContext context, RenderTickCounter tickCounter, CallbackInfo ci) {
        MinecraftClient client = MinecraftClient.getInstance();
        EntityHitResult entityHit = client.crosshairTarget instanceof EntityHitResult hit ? hit : null;
        boolean targetsOtherPlayer = client.player != null
                && entityHit != null
                && entityHit.getEntity() instanceof PlayerEntity
                && entityHit.getEntity() != client.player;

        long now = System.nanoTime();
        long elapsed = lastUpdateNanos == 0L ? 0L : Math.max(0L, now - lastUpdateNanos);
        lastUpdateNanos = now;
        float targetAmount = targetsOtherPlayer ? 1.0F : 0.0F;
        double smoothing = 1.0 - Math.exp(-elapsed / TRANSITION_NANOS);
        redAmount += (targetAmount - redAmount) * (float) smoothing;

        if ((!targetsOtherPlayer && redAmount < 0.002F)
                || client.player == null
                || !client.options.getPerspective().isFirstPerson()
                || client.player.isSpectator()) {
            return;
        }

        int greenBlue = Math.round(255.0F + (40.0F - 255.0F) * redAmount);
        int color = 0xFF000000 | (255 << 16) | (greenBlue << 8) | greenBlue;
        int centerX = client.getWindow().getScaledWidth() / 2;
        int centerY = client.getWindow().getScaledHeight() / 2;

        drawSegment(context, centerX - 5, centerY, centerX - 2, centerY + 2, color);
        drawSegment(context, centerX + 2, centerY, centerX + 5, centerY + 2, color);
        drawSegment(context, centerX, centerY - 5, centerX + 2, centerY - 2, color);
        drawSegment(context, centerX, centerY + 2, centerX + 2, centerY + 5, color);
        ci.cancel();
    }

    private static void drawSegment(DrawContext context, int x1, int y1, int x2, int y2, int color) {
        context.fill(x1 + 1, y1 + 1, x2 + 1, y2 + 1, 0x80000000);
        context.fill(x1, y1, x2, y2, color);
    }
}