import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
-import net.minecraft.client.gl.VertexBuffer;
-import net.minecraft.client.render.BufferBuilder;
-import net.minecraft.client.render.BufferRenderer;
import net.minecraft.client.render.GameRenderer;
-import net.minecraft.client.render.Shader;
-import net.minecraft.client.render.Tessellator;
-import net.minecraft.client.render.VertexFormat;
-import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
-import net.minecraft.util.math.Matrix4f;
-import org.lwjgl.opengl.GL11;
import java.awt.*;
public static final double PHI_SEGMENT = TAU / 90D;
private static final double PI = TAU / 2D;
public static final double THETA_SEGMENT = PHI_SEGMENT / 2D;
- private static final float DEFAULT_LINE_WIDTH = 0.0025f;
- private final VertexBuffer solidBox = new VertexBuffer();
- private final VertexBuffer outlinedBox = new VertexBuffer();
-
- {
- final Box box = new Box(BlockPos.ORIGIN);
- RenderHelper.drawSolidBox(box, solidBox);
- RenderHelper.drawOutlinedBox(box, outlinedBox);
- }
+ private static final Box ORIGIN_BOX = new Box(BlockPos.ORIGIN);
public abstract void render(MatrixStack matrixStack, T boundingBox);
void renderCuboid(MatrixStack matrixStack, OffsetBox bb, Color color, boolean fillOnly, int fillAlpha) {
- OffsetBox nudge = bb.nudge();
-
- GL11.glEnable(GL11.GL_CULL_FACE);
- RenderHelper.polygonModeFill();
matrixStack.push();
- RenderSystem.depthMask(false);
- renderCuboid0(matrixStack, nudge, color, fillOnly, fillAlpha);
- RenderSystem.depthMask(true);
+ renderCuboid0(matrixStack, bb.nudge(), color, fillOnly, fillAlpha, false);
matrixStack.pop();
- RenderSystem.setShaderColor(1, 1, 1, 1);
}
- private void renderCuboid0(MatrixStack stack, OffsetBox nudge, Color color, boolean fillOnly, int fillAlpha) {
- if (!RenderCulling.isVisibleCulling(nudge.toBox())) return;
+ private void renderCuboid0(MatrixStack stack, OffsetBox nudge, Color color, boolean fillOnly, int fillAlpha, boolean mask) {
+ if (ConfigManager.fastRender.get() >= 1 && !RenderCulling.isVisibleCulling(nudge.toBox())) return;
if (ConfigManager.invertBoxColorPlayerInside.get() &&
playerInsideBoundingBox(nudge)) {
color = new Color(255 - color.getRed(), 255 - color.getGreen(), 255 - color.getBlue());
int regionX = (((int) Camera.getX()) >> 9) << 9;
int regionZ = (((int) Camera.getZ()) >> 9) << 9;
RenderHelper.applyRegionalRenderOffset(stack);
- RenderSystem.setShader(GameRenderer::getPositionShader);
final double minX = nudge.getMin().getX();
final double minY = nudge.getMin().getY();
final double minZ = nudge.getMin().getZ();
(float) (maxY - minY),
(float) (maxZ - minZ));
- Matrix4f viewMatrix = stack.peek().getModel();
- Matrix4f projMatrix = RenderSystem.getProjectionMatrix();
- Shader shader = RenderSystem.getShader();
if (fillOnly || ConfigManager.fill.get()) {
- RenderSystem.setShaderColor(color.getRed() / 255F, color.getGreen() / 255F, color.getBlue() / 255F, fillAlpha / 255F);
- solidBox.setShader(viewMatrix, projMatrix, shader);
+ RenderBatch.drawSolidBox(stack.peek(), ORIGIN_BOX, color, fillAlpha, mask, minX == maxX, minY == maxY, minZ == maxZ);
}
if (!fillOnly) {
- RenderSystem.setShaderColor(color.getRed() / 255F, color.getGreen() / 255F, color.getBlue() / 255F, 1F);
-// outlinedBox.setShader(viewMatrix, projMatrix, shader);
- final double minXL = minX - getLineWidth();
- final double minYL = minY - getLineWidth();
- final double minZL = minZ - getLineWidth();
- final double maxXL = maxX + getLineWidth();
- final double maxYL = maxY + getLineWidth();
- final double maxZL = maxZ + getLineWidth();
stack.push();
- stack.peek().getModel().load(lastStack.getModel());
- stack.peek().getNormal().load(lastStack.getNormal());
- renderLine(stack, new OffsetPoint(minXL, minYL, minZL), new OffsetPoint(maxXL, minYL, minZL), color);
- renderLine(stack, new OffsetPoint(maxXL, minYL, minZL), new OffsetPoint(maxXL, minYL, maxZL), color);
- renderLine(stack, new OffsetPoint(maxXL, minYL, maxZL), new OffsetPoint(minXL, minYL, maxZL), color);
- renderLine(stack, new OffsetPoint(minXL, minYL, maxZL), new OffsetPoint(minXL, minYL, minZL), color);
- renderLine(stack, new OffsetPoint(minXL, minYL, minZL), new OffsetPoint(minXL, maxYL, minZL), color);
- renderLine(stack, new OffsetPoint(maxXL, minYL, minZL), new OffsetPoint(maxXL, maxYL, minZL), color);
- renderLine(stack, new OffsetPoint(maxXL, minYL, maxZL), new OffsetPoint(maxXL, maxYL, maxZL), color);
- renderLine(stack, new OffsetPoint(minXL, minYL, maxZL), new OffsetPoint(minXL, maxYL, maxZL), color);
- renderLine(stack, new OffsetPoint(minXL, maxYL, minZL), new OffsetPoint(maxXL, maxYL, minZL), color);
- renderLine(stack, new OffsetPoint(maxXL, maxYL, minZL), new OffsetPoint(maxXL, maxYL, maxZL), color);
- renderLine(stack, new OffsetPoint(maxXL, maxYL, maxZL), new OffsetPoint(minXL, maxYL, maxZL), color);
- renderLine(stack, new OffsetPoint(minXL, maxYL, maxZL), new OffsetPoint(minXL, maxYL, minZL), color);
+ stack.peek().getPositionMatrix().load(lastStack.getPositionMatrix());
+ stack.peek().getNormalMatrix().load(lastStack.getNormalMatrix());
+ renderLine(stack, new OffsetPoint(minX, minY, minZ), new OffsetPoint(maxX, minY, minZ), color, true);
+ renderLine(stack, new OffsetPoint(maxX, minY, minZ), new OffsetPoint(maxX, minY, maxZ), color, true);
+ renderLine(stack, new OffsetPoint(maxX, minY, maxZ), new OffsetPoint(minX, minY, maxZ), color, true);
+ renderLine(stack, new OffsetPoint(minX, minY, maxZ), new OffsetPoint(minX, minY, minZ), color, true);
+ renderLine(stack, new OffsetPoint(minX, minY, minZ), new OffsetPoint(minX, maxY, minZ), color, true);
+ renderLine(stack, new OffsetPoint(maxX, minY, minZ), new OffsetPoint(maxX, maxY, minZ), color, true);
+ renderLine(stack, new OffsetPoint(maxX, minY, maxZ), new OffsetPoint(maxX, maxY, maxZ), color, true);
+ renderLine(stack, new OffsetPoint(minX, minY, maxZ), new OffsetPoint(minX, maxY, maxZ), color, true);
+ renderLine(stack, new OffsetPoint(minX, maxY, minZ), new OffsetPoint(maxX, maxY, minZ), color, true);
+ renderLine(stack, new OffsetPoint(maxX, maxY, minZ), new OffsetPoint(maxX, maxY, maxZ), color, true);
+ renderLine(stack, new OffsetPoint(maxX, maxY, maxZ), new OffsetPoint(minX, maxY, maxZ), color, true);
+ renderLine(stack, new OffsetPoint(minX, maxY, maxZ), new OffsetPoint(minX, maxY, minZ), color, true);
stack.pop();
}
nudge.getMin().getZ() < 0 && nudge.getMax().getZ() > 0;
}
- private double getLineWidth() {
- return DEFAULT_LINE_WIDTH * ConfigManager.lineWidthModifier.get();
- }
- void renderLine(MatrixStack matrixStack, OffsetPoint startPoint, OffsetPoint endPoint, Color color) {
- if ((startPoint.getY() == endPoint.getY() && startPoint.getZ() == endPoint.getZ()) ||
- (startPoint.getX() == endPoint.getX() && startPoint.getZ() == endPoint.getZ()) ||
- (startPoint.getX() == endPoint.getX() && startPoint.getY() == endPoint.getY())) {
- RenderSystem.depthMask(true);
- renderCuboid0(matrixStack, new OffsetBox(startPoint.offset(-getLineWidth(), -getLineWidth(), -getLineWidth()), endPoint.offset(getLineWidth(), getLineWidth(), getLineWidth())), color, true, 255);
- RenderSystem.depthMask(false);
- return;
- }
+ void renderLine(MatrixStack matrixStack, OffsetPoint startPoint, OffsetPoint endPoint, Color color, boolean cullIfEmpty) {
+// if ((startPoint.getY() == endPoint.getY() && startPoint.getZ() == endPoint.getZ()) ||
+// (startPoint.getX() == endPoint.getX() && startPoint.getZ() == endPoint.getZ()) ||
+// (startPoint.getX() == endPoint.getX() && startPoint.getY() == endPoint.getY())) {
+// renderCuboid0(matrixStack, new OffsetBox(startPoint.offset(-getLineWidth(), -getLineWidth(), -getLineWidth()), endPoint.offset(getLineWidth(), getLineWidth(), getLineWidth())), color, true, 255, true);
+// return;
+// }
- if (!RenderCulling.isVisibleCulling(new OffsetBox(startPoint, endPoint).toBox())) return; // TODO better culling
+ if (cullIfEmpty && startPoint.equals(endPoint)) return;
+ if (ConfigManager.fastRender.get() >= 1 && !RenderCulling.isVisibleCulling(new OffsetBox(startPoint, endPoint).toBox())) return; // TODO better culling
matrixStack.push();
RenderHelper.applyRegionalRenderOffset(matrixStack);
- RenderSystem.setShader(GameRenderer::getPositionShader);
- RenderSystem.setShaderColor(color.getRed() / 255F, color.getGreen() / 255F, color.getBlue() / 255F, 1F);
- int regionX = (((int) Camera.getX()) >> 9) * 512;
- int regionZ = (((int) Camera.getZ()) >> 9) * 512;
- BufferBuilder bufferBuilder = Tessellator.getInstance().getBuffer();
- bufferBuilder.begin(VertexFormat.DrawMode.DEBUG_LINES,
- VertexFormats.POSITION);
- bufferBuilder
- .vertex(matrixStack.peek().getModel(),
- (float) startPoint.getX() - regionX,
- (float) startPoint.getY(),
- (float) startPoint.getZ() - regionZ)
- .next();
- bufferBuilder
- .vertex(matrixStack.peek().getModel(),
- (float) endPoint.getX() - regionX,
- (float) endPoint.getY(),
- (float) endPoint.getZ() - regionZ)
- .next();
- bufferBuilder.end();
- BufferRenderer.draw(bufferBuilder);
+ RenderBatch.drawLine(matrixStack.peek(), startPoint.getPoint(), endPoint.getPoint(), color, 255);
matrixStack.pop();
}
}
private void renderLineSphere(MatrixStack matrixStack, Point center, double radius, Color color) {
- if (!RenderCulling.isVisibleCulling(new Box(new BlockPos(center.getX(), center.getY(), center.getZ())).expand(radius))) return;
- RenderHelper.lineWidth2();
+ if (ConfigManager.fastRender.get() >= 1 && !RenderCulling.isVisibleCulling(new Box(new BlockPos(center.getX(), center.getY(), center.getZ())).expand(radius))) return;
double offset = ((radius - (int) radius) == 0) ? center.getY() - (int) center.getY() : 0;
int dyStep = radius < 64 ? 1 : MathHelper.floor(radius / 32);
RenderHelper.applyRegionalRenderOffset(matrixStack);
RenderSystem.setShader(GameRenderer::getPositionShader);
- RenderSystem.setShaderColor(color.getRed() / 255F, color.getGreen() / 255F, color.getBlue() / 255F, 0.55f);
- int regionX = (((int) Camera.getX()) >> 9) * 512;
- int regionZ = (((int) Camera.getZ()) >> 9) * 512;
-
- BufferBuilder bufferBuilder = Tessellator.getInstance().getBuffer();
- bufferBuilder.begin(VertexFormat.DrawMode.DEBUG_LINE_STRIP,
- VertexFormats.POSITION);
Point firstPoint = null;
+ Point lastPoint = null;
for (double phi = 0.0D; phi < TAU; phi += PHI_SEGMENT) {
final Point point = center.offset(Math.cos(phi) * radius, dy, Math.sin(phi) * radius);
if (firstPoint == null) firstPoint = point;
- bufferBuilder.vertex(matrixStack.peek().getModel(),
- (float) point.getX() - regionX,
- (float) point.getY(),
- (float) point.getZ() - regionZ)
- .next();
+ if (lastPoint == null) {
+ lastPoint = point;
+ continue;
+ }
+ RenderBatch.drawLine(matrixStack.peek(), lastPoint, point, color, 255);
+ lastPoint = point;
}
+ RenderBatch.drawLine(matrixStack.peek(), lastPoint, firstPoint, color, 255);
- bufferBuilder.vertex(matrixStack.peek().getModel(),
- (float) firstPoint.getX() - regionX,
- (float) firstPoint.getY(),
- (float) firstPoint.getZ() - regionZ)
- .next();
-
- bufferBuilder.end();
- BufferRenderer.draw(bufferBuilder);
matrixStack.pop();
}
private void renderDotSphere(MatrixStack matrixStack, Point center, double radius, Color color) {
- if (!RenderCulling.isVisibleCulling(new Box(new BlockPos(center.getX(), center.getY(), center.getZ())).expand(radius))) return;
+ if (ConfigManager.fastRender.get() >= 1 && !RenderCulling.isVisibleCulling(new Box(new BlockPos(center.getX(), center.getY(), center.getZ())).expand(radius))) return;
matrixStack.push();
- RenderHelper.applyRegionalRenderOffset(matrixStack);
- RenderSystem.setShader(GameRenderer::getPositionShader);
- RenderSystem.setShaderColor(color.getRed() / 255F, color.getGreen() / 255F, color.getBlue() / 255F, 0.55f);
- int regionX = (((int) Camera.getX()) >> 9) * 512;
- int regionZ = (((int) Camera.getZ()) >> 9) * 512;
-
- BufferBuilder bufferBuilder = Tessellator.getInstance().getBuffer();
- bufferBuilder.begin(VertexFormat.DrawMode.QUADS,
- VertexFormats.POSITION);
for (double phi = 0.0D; phi < TAU; phi += PHI_SEGMENT) {
double dy = radius * Math.cos(phi);
for (double theta = 0.0D; theta < PI; theta += THETA_SEGMENT) {
double dx = radiusBySinPhi * Math.cos(theta);
double dz = radiusBySinPhi * Math.sin(theta);
-
final Point point = center.offset(dx, dy, dz);
- bufferBuilder
- .vertex(matrixStack.peek().getModel(),
- (float) point.getX() - regionX,
- (float) point.getY(),
- (float) point.getZ() - regionZ)
- .next();
+ renderCuboid0(matrixStack, new OffsetBox(point.offset(-0.0025f, -0.0025f, -0.0025f), point.offset(0.0025f, 0.0025f, 0.0025f)), color, true, 255, true);
}
}
- bufferBuilder.end();
- BufferRenderer.draw(bufferBuilder);
matrixStack.pop();
}
}