Akshat Raj

Convert this into an actual working mod ( jar )

Kodari AI
KodariNov 9 at 3:45 pm 4
  • Fix the hitbox rendering hook so it submits boxes to the active renderer.

  • Keep the existing particle effect and client-only mod packaging.

Fixed the hitbox rendering hook in the Fabric 1.21.11 mod. It highlights invisible players and enlarges their nearby potion particles.

To get the JAR, click Compile in the top bar, then Compile in the window. When it succeeds, click Download. On phone, use ⋮ → Compile Project.

The build and in-game behavior haven’t been verified in this session.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
8 213
src/main/java/com/invisreveal/InvisibleReveal.java
package com.invisreveal;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.render.DrawStyle;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.debug.gizmo.GizmoDrawing;

public final class InvisibleReveal {
    // ---- tweak these ----
    /** How much bigger the invisibility swirl particles get (1.0 = vanilla). */
    public static final float PARTICLE_SCALE = 3.0f;
    /** Hitbox line color, ARGB. */
    public static final int HITBOX_COLOR = 0xFFFF3B30;
    /** Hitbox line thickness. */
    public static final float HITBOX_WIDTH = 2.5f;
    /** Don't draw hitboxes farther than this many blocks. */
    public static final double MAX_DISTANCE = 64.0;
    // ---------------------

    private InvisibleReveal() {}

    /** True for another, non-spectator player that is invisible to us. */
    private static boolean isHidden(PlayerEntity other, PlayerEntity self) {
        return other != self && !other.isSpectator() && other.isInvisibleTo(self);
    }

    /** Is this point inside (or right next to) an invisible player? Used to pick their particles. */
    public static boolean isNearHiddenPlayer(double x, double y, double z) {
        MinecraftClient mc = MinecraftClient.getInstance();
        ClientWorld world = mc.world;
        ClientPlayerEntity self = mc.player;
        if (world == null || self == null) return false;

        for (AbstractClientPlayerEntity p : world.getPlayers()) {
            if (isHidden(p, self) && p.getBoundingBox().expand(0.75).contains(x, y, z)) {
                return true;
            }
        }
        return false;
    }

    /** Called once per rendered frame. */
    public static void drawHitboxes() {
        MinecraftClient mc = MinecraftClient.getInstance();
        ClientWorld world = mc.world;
        ClientPlayerEntity self = mc.player;
        if (world == null || self == null) return;

        float tickProgress = mc.getRenderTickCounter().getTickProgress(false);
        double maxSq = MAX_DISTANCE * MAX_DISTANCE;

        for (AbstractClientPlayerEntity p : world.getPlayers()) {
            if (!isHidden(p, self) || p.squaredDistanceTo(self) > maxSq) continue;

            // Smooth the box between ticks so it doesn't jitter.
            Vec3d lerped = p.getLerpedPos(tickProgress);
            Box box = p.getBoundingBox().offset(
                    lerped.x - p.getX(),
                    lerped.y - p.getY(),
                    lerped.z - p.getZ());

            try {
                GizmoDrawing.box(box, DrawStyle.stroked(HITBOX_COLOR, HITBOX_WIDTH));
            } catch (RuntimeException ignored) {
                // No gizmo collector active this frame; nothing to draw into.
            }
        }
    }
}