Package me.hackware.api.util
Class RenderUtils
java.lang.Object
me.hackware.api.util.RenderUtils
Direct-draw API for 3D overlays: box outlines/fills, lines, quads and
camera-facing strips (tracers), plus world-to-screen projection. Draw calls
are valid between Render3DEvent begin/end; the client drives the lifecycle.
Shader-mod routing and AA selection go through
RenderBridge.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final org.joml.Matrix4fThe combined bobHurt + bobView transform for the current frame.static floatLast FOV captured from GameRenderer.renderLevel (degrees).static final floatNear-plane distance for manual strip clipping (matches vanilla).static final org.joml.Matrix4fView-projection matrix for the current frame (proj * bob * view). -
Method Summary
Modifier and TypeMethodDescriptionstatic intargb(int r, int g, int b, int a) static voidCalled once per frame fromGameRendererMixinbeforeRender3DEventis posted.static voidbeginRender(net.minecraft.client.renderer.MultiBufferSource.BufferSource bufferSource, com.mojang.blaze3d.vertex.PoseStack poseStack, net.minecraft.client.Camera camera, net.minecraft.client.renderer.culling.Frustum frameFrustum) Begins the per-frame direct-draw context.static voidClears the direct-draw pipeline/type caches (called from RenderState.clearAllCaches).static voiddrawBoxFill(net.minecraft.world.phys.AABB box, int color) static voiddrawBoxOutline(net.minecraft.world.phys.AABB box, int color, float lineWidth) static voiddrawBoxOutlineDepth(net.minecraft.world.phys.AABB box, int color, float lineWidth) static voiddrawLine(net.minecraft.world.phys.Vec3 from, net.minecraft.world.phys.Vec3 to, int color, float lineWidth) static voidemitClippedStrip(float sx, float sy, float sz, float ex, float ey, float ez, org.joml.Vector3f fwd, int color, float pxWidth, float pxToWorld) Emits a camera-facing anti-aliased quad strip with constant screen-pixel width, after clipping the segment against the near plane.static voidemitFillQuad(double x0, double y0, double z0, double x1, double y1, double z1, double x2, double y2, double z2, double x3, double y3, double z3, int color) Emits a single filled quad into the no-depth-test filled batch.static voidemitFillQuad(double x0, double y0, double z0, double x1, double y1, double z1, double x2, double y2, double z2, double x3, double y3, double z3, int c0, int c1, int c2, int c3) Emits a filled quad with a per-vertex color (for gradients) into the no-depth-test filled batch.static voidemitFillQuadRelative(float x0, float y0, float z0, float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, int color) Emits a filled quad using camera-relative float coordinates.static voidemitLine(double sx, double sy, double sz, double ex, double ey, double ez, int color, float lineWidth) Emits a single line segment into the no-depth-test line batch.static voidemitLineDepth(double sx, double sy, double sz, double ex, double ey, double ez, int color, float lineWidth) Emits a single line segment into the depth-tested line batch.static voidemitLineRelative(float sx, float sy, float sz, float ex, float ey, float ez, int color, float lineWidth) Emits a line segment using camera-relative float coordinates.static voidFlushes any pending draw batches and clears the render context.static voidImmediately flushes the pending no-depth lines + filled batches without tearing down the render context.static net.minecraft.client.renderer.MultiBufferSource.BufferSourceReturns the active buffer source for the current frame, ornulloutside a render pass.static doublegetCamX()static doublegetCamY()static doublegetCamZ()static booleanReturnstruewhen draw calls should be skipped this frame.static booleanisInFrustum(net.minecraft.world.phys.AABB box) Returnstrueif the given world-space AABB is inside (or intersects) the current view frustum.static intwithAlpha(int argb, int alpha) static org.joml.Vector3fworldToScreen(double x, double y, double z, net.minecraft.client.Camera camera) Project a world position to GUI-scaled screen coordinates.
-
Field Details
-
STRIP_NEAR_PLANE
public static final float STRIP_NEAR_PLANENear-plane distance for manual strip clipping (matches vanilla).- See Also:
-
lastFov
public static float lastFovLast FOV captured from GameRenderer.renderLevel (degrees). -
viewProjMatrix
public static final org.joml.Matrix4f viewProjMatrixView-projection matrix for the current frame (proj * bob * view). Set by GameRendererMixin. -
bobMatrix
public static final org.joml.Matrix4f bobMatrixThe combined bobHurt + bobView transform for the current frame. Applied to the projection matrix by vanilla so that the world "bobs" when walking. Custom renderers that bypass the GPU projection (e.g.worldToScreen(double, double, double, net.minecraft.client.Camera)) must account for this matrix to stay aligned with the bobbed world.Identity when view bobbing is disabled or suppressed.
-
-
Method Details
-
beginFrame
public static void beginFrame()Called once per frame fromGameRendererMixinbeforeRender3DEventis posted. Resets the draw budget and detects post-loading conditions, and registers Iris pipelines on first use. -
isGizmosSuppressed
public static boolean isGizmosSuppressed()Returnstruewhen draw calls should be skipped this frame. -
beginRender
public static void beginRender(net.minecraft.client.renderer.MultiBufferSource.BufferSource bufferSource, com.mojang.blaze3d.vertex.PoseStack poseStack, net.minecraft.client.Camera camera, net.minecraft.client.renderer.culling.Frustum frameFrustum) Begins the per-frame direct-draw context. Must be called before postingRender3DEventand paired withendRender(). -
isInFrustum
public static boolean isInFrustum(net.minecraft.world.phys.AABB box) Returnstrueif the given world-space AABB is inside (or intersects) the current view frustum. Always returnstruewhen no frustum is set. -
endRender
public static void endRender()Flushes any pending draw batches and clears the render context. -
flushPendingBatches
public static void flushPendingBatches()Immediately flushes the pending no-depth lines + filled batches without tearing down the render context. Used by post-process pipelines that need draws to materialise against a specific FBO that's only bound for a short window. -
drawBoxOutline
public static void drawBoxOutline(net.minecraft.world.phys.AABB box, int color, float lineWidth) -
drawBoxOutlineDepth
public static void drawBoxOutlineDepth(net.minecraft.world.phys.AABB box, int color, float lineWidth) -
drawBoxFill
public static void drawBoxFill(net.minecraft.world.phys.AABB box, int color) -
drawLine
public static void drawLine(net.minecraft.world.phys.Vec3 from, net.minecraft.world.phys.Vec3 to, int color, float lineWidth) -
getCamX
public static double getCamX() -
getCamY
public static double getCamY() -
getCamZ
public static double getCamZ() -
getBufferSource
public static net.minecraft.client.renderer.MultiBufferSource.BufferSource getBufferSource()Returns the active buffer source for the current frame, ornulloutside a render pass. -
emitFillQuad
public static void emitFillQuad(double x0, double y0, double z0, double x1, double y1, double z1, double x2, double y2, double z2, double x3, double y3, double z3, int color) Emits a single filled quad into the no-depth-test filled batch. -
emitFillQuad
public static void emitFillQuad(double x0, double y0, double z0, double x1, double y1, double z1, double x2, double y2, double z2, double x3, double y3, double z3, int c0, int c1, int c2, int c3) Emits a filled quad with a per-vertex color (for gradients) into the no-depth-test filled batch. -
emitFillQuadRelative
public static void emitFillQuadRelative(float x0, float y0, float z0, float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, int color) Emits a filled quad using camera-relative float coordinates. Use this when positions were already computed as(world - cam)in doubles and then cast to float, avoiding double precision loss. -
emitLine
public static void emitLine(double sx, double sy, double sz, double ex, double ey, double ez, int color, float lineWidth) Emits a single line segment into the no-depth-test line batch. -
emitLineDepth
public static void emitLineDepth(double sx, double sy, double sz, double ex, double ey, double ez, int color, float lineWidth) Emits a single line segment into the depth-tested line batch. -
emitLineRelative
public static void emitLineRelative(float sx, float sy, float sz, float ex, float ey, float ez, int color, float lineWidth) Emits a line segment using camera-relative float coordinates. Use this when positions were already computed as(world - cam)in doubles and then cast to float, avoiding double precision loss. -
emitClippedStrip
public static void emitClippedStrip(float sx, float sy, float sz, float ex, float ey, float ez, org.joml.Vector3f fwd, int color, float pxWidth, float pxToWorld) Emits a camera-facing anti-aliased quad strip with constant screen-pixel width, after clipping the segment against the near plane.Unlike the MC line shader (which computes width from the normal's screen projection and degenerates when the line is view-aligned), this builds explicit billboard geometry whose width is derived from depth, guaranteeing constant rasterised width at any angle. The quad is widened by
STRIP_AA_PADpixels per side and the strip_aa shader fades edge coverage over the outer pixel.- Parameters:
fwd- unit camera-forward direction (camera-relative)pxWidth- desired width in screen pixelspxToWorld- pre-computed2·tan(fov/2) / screenHeight
-
argb
public static int argb(int r, int g, int b, int a) -
withAlpha
public static int withAlpha(int argb, int alpha) -
worldToScreen
public static org.joml.Vector3f worldToScreen(double x, double y, double z, net.minecraft.client.Camera camera) Project a world position to GUI-scaled screen coordinates.- Returns:
- a
Vector3fwith (screenX, screenY, cameraSpaceZ) ornullif the point is behind the camera.
-
clearDrawCaches
public static void clearDrawCaches()Clears the direct-draw pipeline/type caches (called from RenderState.clearAllCaches).
-