mirror of https://github.com/cabaletta/baritone
149 lines
6.4 KiB
Java
149 lines
6.4 KiB
Java
/*
|
|
* This file is part of Baritone.
|
|
*
|
|
* Baritone is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* Baritone is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
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.world.phys.AABB;
|
|
|
|
import java.awt.*;
|
|
|
|
public interface IRenderer {
|
|
|
|
Tesselator tessellator = Tesselator.getInstance();
|
|
BufferBuilder buffer = tessellator.getBuilder();
|
|
IEntityRenderManager renderManager = (IEntityRenderManager) Minecraft.getInstance().getEntityRenderDispatcher();
|
|
TextureManager textureManager = Minecraft.getInstance().getTextureManager();
|
|
Settings settings = BaritoneAPI.getSettings();
|
|
|
|
float[] color = new float[] {1.0F, 1.0F, 1.0F, 255.0F};
|
|
|
|
static void glColor(Color color, float alpha) {
|
|
float[] colorComponents = color.getColorComponents(null);
|
|
IRenderer.color[0] = colorComponents[0];
|
|
IRenderer.color[1] = colorComponents[1];
|
|
IRenderer.color[2] = colorComponents[2];
|
|
IRenderer.color[3] = alpha;
|
|
}
|
|
|
|
static void startLines(Color color, float alpha, float lineWidth, boolean ignoreDepth) {
|
|
RenderSystem.enableBlend();
|
|
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();
|
|
}
|
|
RenderSystem.setShader(GameRenderer::getRendertypeLinesShader);
|
|
buffer.begin(VertexFormat.Mode.LINES, DefaultVertexFormat.POSITION_COLOR_NORMAL);
|
|
}
|
|
|
|
static void startLines(Color color, float lineWidth, boolean ignoreDepth) {
|
|
startLines(color, .4f, lineWidth, ignoreDepth);
|
|
}
|
|
|
|
static void endLines(boolean ignoredDepth) {
|
|
tessellator.end();
|
|
if (ignoredDepth) {
|
|
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 double dx = x2 - x1;
|
|
final double dy = y2 - y1;
|
|
final double dz = z2 - z1;
|
|
|
|
final double invMag = 1.0 / Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
final float nx = (float) (dx * invMag);
|
|
final float ny = (float) (dy * invMag);
|
|
final float nz = (float) (dz * invMag);
|
|
|
|
emitLine(stack, x1, y1, z1, x2, y2, z2, nx, ny, nz);
|
|
}
|
|
|
|
static void emitLine(PoseStack stack,
|
|
double x1, double y1, double z1,
|
|
double x2, double y2, double z2,
|
|
double nx, double ny, double nz) {
|
|
emitLine(stack,
|
|
(float) x1, (float) y1, (float) z1,
|
|
(float) x2, (float) y2, (float) z2,
|
|
(float) nx, (float) ny, (float) nz
|
|
);
|
|
}
|
|
|
|
static void emitLine(PoseStack stack,
|
|
float x1, float y1, float z1,
|
|
float x2, float y2, float z2,
|
|
float nx, float ny, float nz) {
|
|
final Matrix4f matrix4f = stack.last().pose();
|
|
final Matrix3f normal = stack.last().normal();
|
|
|
|
buffer.vertex(matrix4f, x1, y1, z1).color(color[0], color[1], color[2], color[3]).normal(normal, nx, ny, nz).endVertex();
|
|
buffer.vertex(matrix4f, x2, y2, 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());
|
|
|
|
// bottom
|
|
emitLine(stack, toDraw.minX, toDraw.minY, toDraw.minZ, toDraw.maxX, toDraw.minY, toDraw.minZ, 1.0, 0.0, 0.0);
|
|
emitLine(stack, toDraw.maxX, toDraw.minY, toDraw.minZ, toDraw.maxX, toDraw.minY, toDraw.maxZ, 0.0, 0.0, 1.0);
|
|
emitLine(stack, toDraw.maxX, toDraw.minY, toDraw.maxZ, toDraw.minX, toDraw.minY, toDraw.maxZ, -1.0, 0.0, 0.0);
|
|
emitLine(stack, toDraw.minX, toDraw.minY, toDraw.maxZ, toDraw.minX, toDraw.minY, toDraw.minZ, 0.0, 0.0, -1.0);
|
|
// top
|
|
emitLine(stack, toDraw.minX, toDraw.maxY, toDraw.minZ, toDraw.maxX, toDraw.maxY, toDraw.minZ, 1.0, 0.0, 0.0);
|
|
emitLine(stack, toDraw.maxX, toDraw.maxY, toDraw.minZ, toDraw.maxX, toDraw.maxY, toDraw.maxZ, 0.0, 0.0, 1.0);
|
|
emitLine(stack, toDraw.maxX, toDraw.maxY, toDraw.maxZ, toDraw.minX, toDraw.maxY, toDraw.maxZ, -1.0, 0.0, 0.0);
|
|
emitLine(stack, toDraw.minX, toDraw.maxY, toDraw.maxZ, toDraw.minX, toDraw.maxY, toDraw.minZ, 0.0, 0.0, -1.0);
|
|
// corners
|
|
emitLine(stack, toDraw.minX, toDraw.minY, toDraw.minZ, toDraw.minX, toDraw.maxY, toDraw.minZ, 0.0, 1.0, 0.0);
|
|
emitLine(stack, toDraw.maxX, toDraw.minY, toDraw.minZ, toDraw.maxX, toDraw.maxY, toDraw.minZ, 0.0, 1.0, 0.0);
|
|
emitLine(stack, toDraw.maxX, toDraw.minY, toDraw.maxZ, toDraw.maxX, toDraw.maxY, toDraw.maxZ, 0.0, 1.0, 0.0);
|
|
emitLine(stack, toDraw.minX, toDraw.minY, toDraw.maxZ, toDraw.minX, toDraw.maxY, toDraw.maxZ, 0.0, 1.0, 0.0);
|
|
}
|
|
|
|
static void emitAABB(PoseStack stack, AABB aabb, double expand) {
|
|
emitAABB(stack, aabb.inflate(expand, expand, expand));
|
|
}
|
|
}
|