Skip to content

Instantly share code, notes, and snippets.

@Densamisten
Created September 6, 2024 15:27
Show Gist options
  • Select an option

  • Save Densamisten/bf8e71d58ee8c22157390b94507eb45c to your computer and use it in GitHub Desktop.

Select an option

Save Densamisten/bf8e71d58ee8c22157390b94507eb45c to your computer and use it in GitHub Desktop.
WorldRenderEvents.AFTER_ENTITIES.register(context -> {
MatrixStack matrices = context.matrixStack();
matrices.push();
// Use the correct render layer for drawing lines (does not require UVs)
VertexConsumer buffer = context.consumers().getBuffer(RenderLayer.getLines());
// Get the player's current position
PlayerEntity player = MinecraftClient.getInstance().player;
Vec3d playerPos = player.getPos();
// Place the box near the player (slightly above for visibility)
double boxX = playerPos.getX();
double boxY = playerPos.getY() + 2;
double boxZ = playerPos.getZ();
float size = 1.0f; // Set a reasonable size for the box
// Draw the box at the new position
WorldRenderer.drawBox(
matrices, buffer,
boxX - size / 2, boxY - size / 2, boxZ - size / 2, // Min coordinates
boxX + size / 2, boxY + size / 2, boxZ + size / 2, // Max coordinates
1.0f, 0.0f, 0.0f, 1.0f // Red color with full opacity
);
matrices.pop();
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment