I've been trying to render a selection box using an AxisAlignedBB by using the method in WorldRenderer as an example. The first problem I have is that lines that are behind blocks are being rendered in front of the blocks like in the image. The second problem is that the selection block seems to disappear when I break a block or sprint. Third problem is that as far as I can tell, the box should have red lines but they are still black. These are the methods that I'm using:
// In Event Handler
@SubscribeEvent
public static void onRenderWorldEvent(RenderWorldLastEvent e) {
final AxisAlignedBB test = new AxisAlignedBB(0,0,0,1,1,1);
Renderer.drawBoundingBoxAtBlockPos(e.getMatrixStack(), test, 1.0F, 0.0F, 0.0F, 1.0F, new BlockPos(0,64,0));
}
// In Renderer Class
public static void drawBoundingBoxAtBlockPos(MatrixStack matrixStackIn, AxisAlignedBB aabbIn, float red, float green, float blue, float alpha, BlockPos pos) {
Vector3d cam = Minecraft.getInstance().gameRenderer.getActiveRenderInfo().getProjectedView();
double camX = cam.x, camY = cam.y, camZ = cam.z;
matrixStackIn.push();
RenderSystem.lineWidth(2.0F);
matrixStackIn.translate(pos.getX() - camX, pos.getY() - camY, pos.getZ() - camZ);
drawBoundingBox(matrixStackIn, aabbIn.minX, aabbIn.minY, aabbIn.minZ, aabbIn.maxX, aabbIn.maxY, aabbIn.maxZ, red, green, blue, alpha, red, green, blue);
matrixStackIn.pop();
}
private static void drawBoundingBox(MatrixStack matrixStackIn, double minX, double minY, double minZ, double maxX, double maxY, double maxZ, float red, float green, float blue, float alpha, float red2, float green2, float blue2) {
Matrix4f matrix4f = matrixStackIn.getLast().getMatrix();
float f = (float)minX;
float f1 = (float)minY;
float f2 = (float)minZ;
float f3 = (float)maxX;
float f4 = (float)maxY;
float f5 = (float)maxZ;
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferIn = tessellator.getBuffer();
bufferIn.begin(1, DefaultVertexFormats.POSITION_COLOR);
bufferIn.pos(matrix4f, f, f1, f2).color(red, green2, blue2, alpha).endVertex();
bufferIn.pos(matrix4f, f3, f1, f2).color(red, green2, blue2, alpha).endVertex();
bufferIn.pos(matrix4f, f, f1, f2).color(red2, green, blue2, alpha).endVertex();
bufferIn.pos(matrix4f, f, f4, f2).color(red2, green, blue2, alpha).endVertex();
bufferIn.pos(matrix4f, f, f1, f2).color(red2, green2, blue, alpha).endVertex();
bufferIn.pos(matrix4f, f, f1, f5).color(red2, green2, blue, alpha).endVertex();
bufferIn.pos(matrix4f, f3, f1, f2).color(red, green, blue, alpha).endVertex();
bufferIn.pos(matrix4f, f3, f4, f2).color(red, green, blue, alpha).endVertex();
bufferIn.pos(matrix4f, f3, f4, f2).color(red, green, blue, alpha).endVertex();
bufferIn.pos(matrix4f, f, f4, f2).color(red, green, blue, alpha).endVertex();
bufferIn.pos(matrix4f, f, f4, f2).color(red, green, blue, alpha).endVertex();
bufferIn.pos(matrix4f, f, f4, f5).color(red, green, blue, alpha).endVertex();
bufferIn.pos(matrix4f, f, f4, f5).color(red, green, blue, alpha).endVertex();
bufferIn.pos(matrix4f, f, f1, f5).color(red, green, blue, alpha).endVertex();
bufferIn.pos(matrix4f, f, f1, f5).color(red, green, blue, alpha).endVertex();
bufferIn.pos(matrix4f, f3, f1, f5).color(red, green, blue, alpha).endVertex();
bufferIn.pos(matrix4f, f3, f1, f5).color(red, green, blue, alpha).endVertex();
bufferIn.pos(matrix4f, f3, f1, f2).color(red, green, blue, alpha).endVertex();
bufferIn.pos(matrix4f, f, f4, f5).color(red, green, blue, alpha).endVertex();
bufferIn.pos(matrix4f, f3, f4, f5).color(red, green, blue, alpha).endVertex();
bufferIn.pos(matrix4f, f3, f1, f5).color(red, green, blue, alpha).endVertex();
bufferIn.pos(matrix4f, f3, f4, f5).color(red, green, blue, alpha).endVertex();
bufferIn.pos(matrix4f, f3, f4, f2).color(red, green, blue, alpha).endVertex();
bufferIn.pos(matrix4f, f3, f4, f5).color(red, green, blue, alpha).endVertex();
Tessellator.getInstance().draw();
}
Any help would be very appreciated.