This is my first Forge mod for 1.15.2.
I'm trying to render 3d lines into the world.
Previously I used the RenderWorldLastEvent, but after I disabled Clouds in the Video settings I noticed, that the event wasn't being called anymore.
This led me to believe, that I may have used the wrong event for this kind of stuff.
This is the code I use to draw an outline around an area:
//The method that should be called by the event
public void render() {
if(pos1 != null && pos2 != null) {
//The next few lines calculate, where to render the area
int[] xList = new int[4];
int[] yList = new int[4];
int[] zList = new int[4];
xList[0] = pos1.getX();
xList[1] = pos1.getX()+1;
yList[0] = pos1.getY();
yList[1] = pos1.getY()+1;
zList[0] = pos1.getZ();
zList[1] = pos1.getZ()+1;
xList[2] = pos2.getX();
xList[3] = pos2.getX()+1;
yList[2] = pos2.getY();
yList[3] = pos2.getY()+1;
zList[2] = pos2.getZ();
zList[3] = pos2.getZ()+1;
int minX = Integer.MAX_VALUE;
int minY = Integer.MAX_VALUE;
int minZ = Integer.MAX_VALUE;
int maxX = Integer.MIN_VALUE;
int maxY = Integer.MIN_VALUE;
int maxZ = Integer.MIN_VALUE;
for(int x : xList) {
if(x < minX) minX = x;
if(x > maxX) maxX = x;
}
for(int y : yList) {
if(y < minY) minY = y;
if(y > maxY) maxY = y;
}
for(int z : zList) {
if(z < minZ) minZ = z;
if(z > maxZ) maxZ = z;
}
//Render the first area
AxisAlignedBB aabb = new AxisAlignedBB(minX, minY, minZ, maxX, maxY, maxZ);
renderArea(aabb, 1.0f, 1.0f, 1.0f);
//If position 3 is set, render the second area in another color
if(pos3 != null) {
AxisAlignedBB aabb2 = new AxisAlignedBB(pos3.getX(), pos3.getY(), pos3.getZ(), pos3.getX() + (maxX - minX), pos3.getY() + (maxY - minY), pos3.getZ() + (maxZ - minZ));
renderArea(aabb2, 1.0f, 0.33f, 0.33f);
}
}
}
//Contains the code to do the actual rendering
public void renderArea(AxisAlignedBB aabb, float r, float g, float b) {
Minecraft mc = Minecraft.getInstance();
Vec3d pos = mc.getRenderManager().info.getProjectedView();
float yaw = mc.getRenderManager().info.getYaw();
float pitch = mc.getRenderManager().info.getPitch();
GL11.glPushMatrix();
//Rotate after the camera
GL11.glRotated(yaw-180, 0, 1, 0);
GL11.glRotated(pitch, -Math.sin((yaw + 90) / 360 * Math.PI * 2), 0, Math.cos((yaw + 90) / 360 * Math.PI * 2));
//Translation
GL11.glTranslated(-pos.x, -pos.y, -pos.z);
//Expand the area for better visibility
aabb = aabb.expand(0.01, 0.01, 0.01);
aabb = aabb.offset(-0.005, -0.005, -0.005);
//Color
RenderSystem.color4f(r, g, b, 1.0f);
GL11.glLineWidth(4);
//Vertices
GL11.glBegin(GL11.GL_LINES);
GL11.glVertex3d(aabb.minX, aabb.minY, aabb.minZ);
GL11.glVertex3d(aabb.maxX, aabb.minY, aabb.minZ);
GL11.glVertex3d(aabb.minX, aabb.maxY, aabb.minZ);
GL11.glVertex3d(aabb.maxX, aabb.maxY, aabb.minZ);
GL11.glVertex3d(aabb.minX, aabb.minY, aabb.minZ);
GL11.glVertex3d(aabb.minX, aabb.maxY, aabb.minZ);
GL11.glVertex3d(aabb.maxX, aabb.minY, aabb.minZ);
GL11.glVertex3d(aabb.maxX, aabb.maxY, aabb.minZ);
GL11.glVertex3d(aabb.minX, aabb.minY, aabb.maxZ);
GL11.glVertex3d(aabb.maxX, aabb.minY, aabb.maxZ);
GL11.glVertex3d(aabb.minX, aabb.maxY, aabb.maxZ);
GL11.glVertex3d(aabb.maxX, aabb.maxY, aabb.maxZ);
GL11.glVertex3d(aabb.minX, aabb.minY, aabb.maxZ);
GL11.glVertex3d(aabb.minX, aabb.maxY, aabb.maxZ);
GL11.glVertex3d(aabb.maxX, aabb.minY, aabb.maxZ);
GL11.glVertex3d(aabb.maxX, aabb.maxY, aabb.maxZ);
GL11.glVertex3d(aabb.minX, aabb.minY, aabb.minZ);
GL11.glVertex3d(aabb.minX, aabb.minY, aabb.maxZ);
GL11.glVertex3d(aabb.minX, aabb.maxY, aabb.minZ);
GL11.glVertex3d(aabb.minX, aabb.maxY, aabb.maxZ);
GL11.glVertex3d(aabb.maxX, aabb.minY, aabb.minZ);
GL11.glVertex3d(aabb.maxX, aabb.minY, aabb.maxZ);
GL11.glVertex3d(aabb.maxX, aabb.maxY, aabb.minZ);
GL11.glVertex3d(aabb.maxX, aabb.maxY, aabb.maxZ);
GL11.glEnd();
GL11.glPopMatrix();
}