VulkanMod compatibility + use LINES instead of DEBUG_LINES

This commit is contained in:
Brady
2023-07-17 16:34:01 -05:00
parent b647c0fca0
commit bf9cb76604
3 changed files with 76 additions and 78 deletions

View File

@@ -43,7 +43,6 @@ import java.awt.*;
import java.util.Collections;
import static baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX;
import static org.lwjgl.opengl.GL11.*;
public class GuiClick extends Screen implements Helper {

View File

@@ -20,17 +20,19 @@ package baritone.utils;
import baritone.api.BaritoneAPI;
import baritone.api.Settings;
import baritone.utils.accessor.IEntityRenderManager;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.math.Matrix3f;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.texture.TextureManager;
import com.mojang.blaze3d.vertex.*;
import com.mojang.math.Matrix4f;
import net.minecraft.util.Mth;
import net.minecraft.world.phys.AABB;
import java.awt.*;
import static org.lwjgl.opengl.GL11.*;
public interface IRenderer {
Tesselator tessellator = Tesselator.getInstance();
@@ -51,17 +53,23 @@ public interface IRenderer {
static void startLines(Color color, float alpha, float lineWidth, boolean ignoreDepth) {
RenderSystem.enableBlend();
RenderSystem.blendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);
RenderSystem.blendFuncSeparate(
GlStateManager.SourceFactor.SRC_ALPHA,
GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA,
GlStateManager.SourceFactor.ONE,
GlStateManager.DestFactor.ZERO
);
glColor(color, alpha);
RenderSystem.lineWidth(lineWidth);
RenderSystem.disableTexture();
RenderSystem.depthMask(false);
RenderSystem.disableCull();
if (ignoreDepth) {
RenderSystem.disableDepthTest();
}
//TODO: check
buffer.begin(VertexFormat.Mode.DEBUG_LINES, DefaultVertexFormat.POSITION_COLOR);
RenderSystem.setShader(GameRenderer::getRendertypeLinesShader);
buffer.begin(VertexFormat.Mode.LINES, DefaultVertexFormat.POSITION_COLOR_NORMAL);
}
static void startLines(Color color, float lineWidth, boolean ignoreDepth) {
@@ -74,51 +82,56 @@ public interface IRenderer {
RenderSystem.enableDepthTest();
}
RenderSystem.enableCull();
RenderSystem.depthMask(true);
RenderSystem.enableTexture();
RenderSystem.disableBlend();
}
static void emitLine(PoseStack stack, double x1, double y1, double z1, double x2, double y2, double z2) {
final Matrix4f matrix4f = stack.last().pose();
final Matrix3f normal = stack.last().normal();
final double dx = x2 - x1;
final double dy = y2 - y1;
final double dz = z2 - z1;
final double invMag = Mth.fastInvSqrt(dx * dx + dy * dy + dz * dz);
final float nx = (float) (dx * invMag);
final float ny = (float) (dy * invMag);
final float nz = (float) (dz * invMag);
buffer.vertex(matrix4f, (float) x1, (float) y1, (float) z1)
.color(color[0], color[1], color[2], color[3])
.normal(normal, nx, ny, nz)
.endVertex();
buffer.vertex(matrix4f, (float) x2, (float) y2, (float) z2)
.color(color[0], color[1], color[2], color[3])
.normal(normal, nx, ny, nz)
.endVertex();
}
static void emitAABB(PoseStack stack, AABB aabb) {
AABB toDraw = aabb.move(-renderManager.renderPosX(), -renderManager.renderPosY(), -renderManager.renderPosZ());
Matrix4f matrix4f = stack.last().pose();
// bottom
buffer.vertex(matrix4f, (float) toDraw.minX, (float) toDraw.minY, (float) toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) toDraw.maxX, (float) toDraw.minY, (float) toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) toDraw.maxX, (float) toDraw.minY, (float) toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) toDraw.maxX, (float) toDraw.minY, (float) toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) toDraw.maxX, (float) toDraw.minY, (float) toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) toDraw.minX, (float) toDraw.minY, (float) toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) toDraw.minX, (float) toDraw.minY, (float) toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) toDraw.minX, (float) toDraw.minY, (float) toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
emitLine(stack, toDraw.minX, toDraw.minY, toDraw.minZ, toDraw.maxX, toDraw.minY, toDraw.minZ);
emitLine(stack, toDraw.maxX, toDraw.minY, toDraw.minZ, toDraw.maxX, toDraw.minY, toDraw.maxZ);
emitLine(stack, toDraw.maxX, toDraw.minY, toDraw.maxZ, toDraw.minX, toDraw.minY, toDraw.maxZ);
emitLine(stack, toDraw.minX, toDraw.minY, toDraw.maxZ, toDraw.minX, toDraw.minY, toDraw.minZ);
// top
buffer.vertex(matrix4f, (float) toDraw.minX, (float) toDraw.maxY, (float) toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) toDraw.maxX, (float) toDraw.maxY, (float) toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) toDraw.maxX, (float) toDraw.maxY, (float) toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) toDraw.maxX, (float) toDraw.maxY, (float) toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) toDraw.maxX, (float) toDraw.maxY, (float) toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) toDraw.minX, (float) toDraw.maxY, (float) toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) toDraw.minX, (float) toDraw.maxY, (float) toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) toDraw.minX, (float) toDraw.maxY, (float) toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
emitLine(stack, toDraw.minX, toDraw.maxY, toDraw.minZ, toDraw.maxX, toDraw.maxY, toDraw.minZ);
emitLine(stack, toDraw.maxX, toDraw.maxY, toDraw.minZ, toDraw.maxX, toDraw.maxY, toDraw.maxZ);
emitLine(stack, toDraw.maxX, toDraw.maxY, toDraw.maxZ, toDraw.minX, toDraw.maxY, toDraw.maxZ);
emitLine(stack, toDraw.minX, toDraw.maxY, toDraw.maxZ, toDraw.minX, toDraw.maxY, toDraw.minZ);
// corners
buffer.vertex(matrix4f, (float) toDraw.minX, (float) toDraw.minY, (float) toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) toDraw.minX, (float) toDraw.maxY, (float) toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) toDraw.maxX, (float) toDraw.minY, (float) toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) toDraw.maxX, (float) toDraw.maxY, (float) toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) toDraw.maxX, (float) toDraw.minY, (float) toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) toDraw.maxX, (float) toDraw.maxY, (float) toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) toDraw.minX, (float) toDraw.minY, (float) toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) toDraw.minX, (float) toDraw.maxY, (float) toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
emitLine(stack, toDraw.minX, toDraw.minY, toDraw.minZ, toDraw.minX, toDraw.maxY, toDraw.minZ);
emitLine(stack, toDraw.maxX, toDraw.minY, toDraw.minZ, toDraw.maxX, toDraw.maxY, toDraw.minZ);
emitLine(stack, toDraw.maxX, toDraw.minY, toDraw.maxZ, toDraw.maxX, toDraw.maxY, toDraw.maxZ);
emitLine(stack, toDraw.minX, toDraw.minY, toDraw.maxZ, toDraw.minX, toDraw.maxY, toDraw.maxZ);
}
static void emitAABB(PoseStack stack, AABB aabb, double expand) {
emitAABB(stack, aabb.inflate(expand, expand, expand));
}
static void drawAABB(PoseStack stack, AABB aabb) {
buffer.begin(VertexFormat.Mode.DEBUG_LINES, DefaultVertexFormat.POSITION_COLOR);
emitAABB(stack, aabb);
tessellator.end();
}
}

View File

@@ -28,6 +28,7 @@ import baritone.behavior.PathingBehavior;
import baritone.pathing.path.PathExecutor;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Matrix3f;
import com.mojang.math.Matrix4f;
import net.minecraft.client.renderer.blockentity.BeaconRenderer;
import net.minecraft.core.BlockPos;
@@ -46,8 +47,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import static org.lwjgl.opengl.GL11.*;
/**
* @author Brady
* @since 8/9/2018
@@ -168,31 +167,35 @@ public final class PathRenderer implements IRenderer {
IRenderer.glColor(color, alpha);
}
emitLine(stack, start.x, start.y, start.z, end.x, end.y, end.z);
emitPathLine(stack, start.x, start.y, start.z, end.x, end.y, end.z);
}
IRenderer.endLines(settings.renderPathIgnoreDepth.value);
}
private static void emitLine(PoseStack stack, double x1, double y1, double z1, double x2, double y2, double z2) {
Matrix4f matrix4f = stack.last().pose();
private static void emitPathLine(PoseStack stack, double x1, double y1, double z1, double x2, double y2, double z2) {
double vpX = posX();
double vpY = posY();
double vpZ = posZ();
boolean renderPathAsFrickinThingy = !settings.renderPathAsLine.value;
buffer.vertex(matrix4f, (float) (x1 + 0.5D - vpX), (float) (y1 + 0.5D - vpY), (float) (z1 + 0.5D - vpZ)).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) (x2 + 0.5D - vpX), (float) (y2 + 0.5D - vpY), (float) (z2 + 0.5D - vpZ)).color(color[0], color[1], color[2], color[3]).endVertex();
IRenderer.emitLine(stack,
x1 + 0.5D - vpX, y1 + 0.5D - vpY, z1 + 0.5D - vpZ,
x2 + 0.5D - vpX, y2 + 0.5D - vpY, z2 + 0.5D - vpZ
);
if (renderPathAsFrickinThingy) {
buffer.vertex(matrix4f, (float) (x2 + 0.5D - vpX), (float) (y2 + 0.5D - vpY), (float) (z2 + 0.5D - vpZ)).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) (x2 + 0.5D - vpX), (float) (y2 + 0.53D - vpY), (float) (z2 + 0.5D - vpZ)).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) (x2 + 0.5D - vpX), (float) (y2 + 0.53D - vpY), (float) (z2 + 0.5D - vpZ)).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) (x1 + 0.5D - vpX), (float) (y1 + 0.53D - vpY), (float) (z1 + 0.5D - vpZ)).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) (x1 + 0.5D - vpX), (float) (y1 + 0.53D - vpY), (float) (z1 + 0.5D - vpZ)).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) (x1 + 0.5D - vpX), (float) (y1 + 0.5D - vpY), (float) (z1 + 0.5D - vpZ)).color(color[0], color[1], color[2], color[3]).endVertex();
IRenderer.emitLine(stack,
x2 + 0.5D - vpX, y2 + 0.5D - vpY, z2 + 0.5D - vpZ,
x2 + 0.5D - vpX, y2 + 0.53D - vpY, z2 + 0.5D - vpZ
);
IRenderer.emitLine(stack,
x2 + 0.5D - vpX, y2 + 0.53D - vpY, z2 + 0.5D - vpZ,
x1 + 0.5D - vpX, y1 + 0.53D - vpY, z1 + 0.5D - vpZ
);
IRenderer.emitLine(stack,
x1 + 0.5D - vpX, y1 + 0.53D - vpY, z1 + 0.5D - vpZ,
x1 + 0.5D - vpX, y1 + 0.5D - vpY, z1 + 0.5D - vpZ
);
}
}
@@ -256,8 +259,6 @@ public final class PathRenderer implements IRenderer {
maxY = ctx.world().getMaxBuildHeight();
if (settings.renderGoalXZBeacon.value) {
glPushAttrib(GL_LIGHTING_BIT);
//TODO: check
textureManager.bindForSetup(TEXTURE_BEACON_BEAM);
if (settings.renderGoalIgnoreDepth.value) {
@@ -289,8 +290,6 @@ public final class PathRenderer implements IRenderer {
if (settings.renderGoalIgnoreDepth.value) {
RenderSystem.enableDepthTest();
}
glPopAttrib();
return;
}
@@ -341,15 +340,10 @@ public final class PathRenderer implements IRenderer {
renderHorizontalQuad(stack, minX, maxX, minZ, maxZ, y1);
renderHorizontalQuad(stack, minX, maxX, minZ, maxZ, y2);
Matrix4f matrix4f = stack.last().pose();
buffer.vertex(matrix4f, (float) minX, (float) minY, (float) minZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) minX, (float) maxY, (float) minZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) maxX, (float) minY, (float) minZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) maxX, (float) maxY, (float) minZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) maxX, (float) minY, (float) maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) maxX, (float) maxY, (float) maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) minX, (float) minY, (float) maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) minX, (float) maxY, (float) maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
IRenderer.emitLine(stack, minX, minY, minZ, minX, maxY, minZ);
IRenderer.emitLine(stack, maxX, minY, minZ, maxX, maxY, minZ);
IRenderer.emitLine(stack, maxX, minY, maxZ, maxX, maxY, maxZ);
IRenderer.emitLine(stack, minX, minY, maxZ, minX, maxY, maxZ);
if (setupRender) {
IRenderer.endLines(settings.renderGoalIgnoreDepth.value);
@@ -358,18 +352,10 @@ public final class PathRenderer implements IRenderer {
private static void renderHorizontalQuad(PoseStack stack, double minX, double maxX, double minZ, double maxZ, double y) {
if (y != 0) {
Matrix4f matrix4f = stack.last().pose();
buffer.vertex(matrix4f, (float) minX, (float) y, (float) minZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) maxX, (float) y, (float) minZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) maxX, (float) y, (float) minZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) maxX, (float) y, (float) maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) maxX, (float) y, (float) maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) minX, (float) y, (float) maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) minX, (float) y, (float) maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.vertex(matrix4f, (float) minX, (float) y, (float) minZ).color(color[0], color[1], color[2], color[3]).endVertex();
IRenderer.emitLine(stack, minX, y, minZ, maxX, y, minZ);
IRenderer.emitLine(stack, maxX, y, minZ, maxX, y, maxZ);
IRenderer.emitLine(stack, maxX, y, maxZ, minX, y, maxZ);
IRenderer.emitLine(stack, minX, y, maxZ, minX, y, minZ);
}
}
}