diff options
author | LifeIsAParadox <LifeIsAParadox@users.noreply.github.com> | 2021-09-14 08:47:32 +0200 |
---|---|---|
committer | LifeIsAParadox <LifeIsAParadox@users.noreply.github.com> | 2021-09-14 08:47:32 +0200 |
commit | 7d2446cdc4bac31cb29709068b2f874da87d4ea9 (patch) | |
tree | 13117dbf6a53e1ca8a474d4fce85c21b09c698f1 /src/main/java/me/xmrvizzy/skyblocker/utils/RenderUtils.java | |
parent | b23331eb654e2e26d17d13616c05ffe3af822290 (diff) | |
download | Skyblocker-7d2446cdc4bac31cb29709068b2f874da87d4ea9.tar.gz Skyblocker-7d2446cdc4bac31cb29709068b2f874da87d4ea9.tar.bz2 Skyblocker-7d2446cdc4bac31cb29709068b2f874da87d4ea9.zip |
Bugfixing and Blaze solver
Diffstat (limited to 'src/main/java/me/xmrvizzy/skyblocker/utils/RenderUtils.java')
-rw-r--r-- | src/main/java/me/xmrvizzy/skyblocker/utils/RenderUtils.java | 235 |
1 files changed, 50 insertions, 185 deletions
diff --git a/src/main/java/me/xmrvizzy/skyblocker/utils/RenderUtils.java b/src/main/java/me/xmrvizzy/skyblocker/utils/RenderUtils.java index 472c41d6..05044ba0 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/utils/RenderUtils.java +++ b/src/main/java/me/xmrvizzy/skyblocker/utils/RenderUtils.java @@ -1,224 +1,89 @@ package me.xmrvizzy.skyblocker.utils; -import com.mojang.blaze3d.platform.GlStateManager; +import com.mojang.blaze3d.systems.RenderSystem; +import me.xmrvizzy.skyblocker.utils.color.QuadColor; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.render.*; -import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher; +import net.minecraft.client.render.BufferBuilder; +import net.minecraft.client.render.Camera; +import net.minecraft.client.render.GameRenderer; +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.entity.Entity; -import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Box; +import net.minecraft.util.math.Direction; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL14; +import net.minecraft.util.math.Vec3f; public class RenderUtils { - public static void drawFilledBox(BlockPos blockPos, float r, float g, float b, float a) { - drawFilledBox(new Box(blockPos), r, g, b, a); - } - - public static void drawFilledBox(Box box, float r, float g, float b, float a) { - gl11Setup(); - - // Fill - Tessellator tessellator = Tessellator.getInstance(); - BufferBuilder buffer = tessellator.getBuffer(); - VertexFormat.DrawMode drawMode = VertexFormat.DrawMode.QUADS; - buffer.begin(drawMode, VertexFormats.POSITION_COLOR); -// buffer.begin(5, VertexFormats.POSITION_COLOR); - WorldRenderer.drawBox(buffer, - box.minX, box.minY, box.minZ, - box.maxX, box.maxY, box.maxZ, r, g, b, a / 2f); - tessellator.draw(); + // -------------------- Outline Boxes -------------------- - // Outline - buffer.begin(drawMode, VertexFormats.POSITION_COLOR); - -// buffer.begin(3, VertexFormats.POSITION_COLOR); - buffer.vertex(box.minX, box.minY, box.minZ).color(r, g, b, a).next(); - buffer.vertex(box.minX, box.minY, box.maxZ).color(r, g, b, a).next(); - buffer.vertex(box.maxX, box.minY, box.maxZ).color(r, g, b, a).next(); - buffer.vertex(box.maxX, box.minY, box.minZ).color(r, g, b, a).next(); - buffer.vertex(box.minX, box.minY, box.minZ).color(r, g, b, a).next(); - buffer.vertex(box.minX, box.maxY, box.minZ).color(r, g, b, a).next(); - buffer.vertex(box.maxX, box.maxY, box.minZ).color(r, g, b, a).next(); - buffer.vertex(box.maxX, box.maxY, box.maxZ).color(r, g, b, a).next(); - buffer.vertex(box.minX, box.maxY, box.maxZ).color(r, g, b, a).next(); - buffer.vertex(box.minX, box.maxY, box.minZ).color(r, g, b, a).next(); - buffer.vertex(box.minX, box.minY, box.maxZ).color(r, g, b, 0f).next(); - buffer.vertex(box.minX, box.maxY, box.maxZ).color(r, g, b, a).next(); - buffer.vertex(box.maxX, box.minY, box.maxZ).color(r, g, b, 0f).next(); - buffer.vertex(box.maxX, box.maxY, box.maxZ).color(r, g, b, a).next(); - buffer.vertex(box.maxX, box.minY, box.minZ).color(r, g, b, 0f).next(); - buffer.vertex(box.maxX, box.maxY, box.minZ).color(r, g, b, a).next(); - tessellator.draw(); - - gl11Cleanup(); - } - - public static void drawOutlineBox(BlockPos blockPos, float r, float g, float b, float a) { - drawOutlineBox(new Box(blockPos), r, g, b, a); - } - - public static void fillGradient(MatrixStack matrix, int x1, int y1, int x2, int y2, int color1, int color2) { - float float_1 = (color1 >> 24 & 255) / 255.0F; - float float_2 = (color1 >> 16 & 255) / 255.0F; - float float_3 = (color1 >> 8 & 255) / 255.0F; - float float_4 = (color1 & 255) / 255.0F; - float float_5 = (color2 >> 24 & 255) / 255.0F; - float float_6 = (color2 >> 16 & 255) / 255.0F; - float float_7 = (color2 >> 8 & 255) / 255.0F; - float float_8 = (color2 & 255) / 255.0F; - Tessellator tessellator_1 = Tessellator.getInstance(); - BufferBuilder bufferBuilder_1 = tessellator_1.getBuffer(); - - VertexFormat.DrawMode drawMode = VertexFormat.DrawMode.QUADS; - bufferBuilder_1.begin(drawMode, VertexFormats.POSITION_COLOR); - -// bufferBuilder_1.begin(7, VertexFormats.POSITION_COLOR); - bufferBuilder_1.vertex(x1, y1, 0).color(float_2, float_3, float_4, float_1).next(); - bufferBuilder_1.vertex(x1, y2, 0).color(float_2, float_3, float_4, float_1).next(); - bufferBuilder_1.vertex(x2, y2, 0).color(float_6, float_7, float_8, float_5).next(); - bufferBuilder_1.vertex(x2, y1, 0).color(float_6, float_7, float_8, float_5).next(); - tessellator_1.draw(); - } + public static void drawBoxOutline(Box box, QuadColor color, float lineWidth, Direction... excludeDirs) { + if (!FrustumUtils.isBoxVisible(box)) { + return; + } + setup(); - public static void drawOutlineBox(Box box, float r, float g, float b, float a) { - gl11Setup(); + MatrixStack matrices = matrixFrom(box.minX, box.minY, box.minZ); Tessellator tessellator = Tessellator.getInstance(); BufferBuilder buffer = tessellator.getBuffer(); // Outline - VertexFormat.DrawMode drawMode = VertexFormat.DrawMode.QUADS; - buffer.begin(drawMode, VertexFormats.POSITION_COLOR); - -// buffer.begin(3, VertexFormats.POSITION_COLOR); - buffer.vertex(box.minX, box.minY, box.minZ).color(r, g, b, a).next(); - buffer.vertex(box.minX, box.minY, box.maxZ).color(r, g, b, a).next(); - buffer.vertex(box.maxX, box.minY, box.maxZ).color(r, g, b, a).next(); - buffer.vertex(box.maxX, box.minY, box.minZ).color(r, g, b, a).next(); - buffer.vertex(box.minX, box.minY, box.minZ).color(r, g, b, a).next(); - buffer.vertex(box.minX, box.maxY, box.minZ).color(r, g, b, a).next(); - buffer.vertex(box.maxX, box.maxY, box.minZ).color(r, g, b, a).next(); - buffer.vertex(box.maxX, box.maxY, box.maxZ).color(r, g, b, a).next(); - buffer.vertex(box.minX, box.maxY, box.maxZ).color(r, g, b, a).next(); - buffer.vertex(box.minX, box.maxY, box.minZ).color(r, g, b, a).next(); - buffer.vertex(box.minX, box.minY, box.maxZ).color(r, g, b, 0f).next(); - buffer.vertex(box.minX, box.maxY, box.maxZ).color(r, g, b, a).next(); - buffer.vertex(box.maxX, box.minY, box.maxZ).color(r, g, b, 0f).next(); - buffer.vertex(box.maxX, box.maxY, box.maxZ).color(r, g, b, a).next(); - buffer.vertex(box.maxX, box.minY, box.minZ).color(r, g, b, 0f).next(); - buffer.vertex(box.maxX, box.maxY, box.minZ).color(r, g, b, a).next(); - tessellator.draw(); - - gl11Cleanup(); - } - - public static void drawLine(double x1, double y1, double z1, double x2, double y2, double z2, float r, float g, float b, float t) { - gl11Setup(); - GL11.glLineWidth(t); + RenderSystem.disableCull(); + RenderSystem.setShader(GameRenderer::getRenderTypeLinesShader); + RenderSystem.lineWidth(lineWidth); - Tessellator tessellator = Tessellator.getInstance(); - BufferBuilder buffer = tessellator.getBuffer(); - - VertexFormat.DrawMode drawMode = VertexFormat.DrawMode.QUADS; - buffer.begin(drawMode, VertexFormats.POSITION_COLOR); - -// buffer.begin(3, VertexFormats.POSITION_COLOR); - buffer.vertex(x1, y1, z1).color(r, g, b, 0.0F).next(); - buffer.vertex(x1, y1, z1).color(r, g, b, 1.0F).next(); - buffer.vertex(x2, y2, z2).color(r, g, b, 1.0F).next(); + buffer.begin(VertexFormat.DrawMode.LINES, VertexFormats.LINES); + Vertexer.vertexBoxLines(matrices, buffer, Boxes.moveToZero(box), color, excludeDirs); tessellator.draw(); - gl11Cleanup(); + RenderSystem.enableCull(); + cleanup(); } - public static void drawRect(float x, float y, float w, float h, int color, float alpha) { - float red = (float) (color >> 16 & 255) / 255.0F; - float green = (float) (color >> 8 & 255) / 255.0F; - float blue = (float) (color & 255) / 255.0F; - final Tessellator tessellator = Tessellator.getInstance(); - final BufferBuilder bufferbuilder = tessellator.getBuffer(); - GlStateManager._enableBlend(); - GlStateManager._disableTexture(); - GlStateManager._blendFuncSeparate(770, 771, 1, 0); - - VertexFormat.DrawMode drawMode = VertexFormat.DrawMode.QUADS; - bufferbuilder.begin(drawMode, VertexFormats.POSITION_COLOR); - -// bufferbuilder.begin(7, VertexFormats.POSITION_COLOR); - bufferbuilder.vertex(x, h, 0.0D).color(red, green, blue, alpha).next(); - bufferbuilder.vertex(w, h, 0.0D).color(red, green, blue, alpha).next(); - bufferbuilder.vertex(w, y, 0.0D).color(red, green, blue, alpha).next(); - bufferbuilder.vertex(x, y, 0.0D).color(red, green, blue, alpha).next(); - tessellator.draw(); - GlStateManager._enableTexture(); - GlStateManager._disableBlend(); - } + // -------------------- Utils -------------------- + + public static MatrixStack matrixFrom(double x, double y, double z) { + MatrixStack matrices = new MatrixStack(); - public static void offsetRender() { - //debg Camera camera = MinecraftClient.getInstance().gameRenderer.getCamera(); - Vec3d camPos = camera.getPos(); - GL11.glRotated(MathHelper.wrapDegrees(camera.getPitch()), 1, 0, 0); - GL11.glRotated(MathHelper.wrapDegrees(camera.getYaw() + 180.0), 0, 1, 0); - GL11.glTranslated(-camPos.x, -camPos.y, -camPos.z); - } + matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(camera.getPitch())); + matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(camera.getYaw() + 180.0F)); - public static void gl11Setup() { - GL11.glPushMatrix(); - GL11.glEnable(GL11.GL_BLEND); - GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO); - GL11.glLineWidth(2.5F); - GL11.glDisable(GL11.GL_TEXTURE_2D); - GL11.glEnable(GL11.GL_LINE_SMOOTH); - offsetRender(); - } + matrices.translate(x - camera.getPos().x, y - camera.getPos().y, z - camera.getPos().z); - public static void gl11Cleanup() { - GL11.glDisable(GL11.GL_LINE_SMOOTH); - GL11.glEnable(GL11.GL_TEXTURE_2D); - GL11.glDisable(GL11.GL_BLEND); - GL11.glPopMatrix(); + return matrices; } + public static Vec3d getInterpolationOffset(Entity e) { + if (MinecraftClient.getInstance().isPaused()) { + return Vec3d.ZERO; + } - public static void DrawPolygon(double x, double y, int radius, int sides, int color) { - GL11.glEnable(GL11.GL_BLEND); - GL11.glDisable(GL11.GL_TEXTURE_2D); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - - final Tessellator tessellator = Tessellator.getInstance(); - final BufferBuilder bufferbuilder = tessellator.getBuffer(); - - VertexFormat.DrawMode drawMode = VertexFormat.DrawMode.TRIANGLE_FAN; - bufferbuilder.begin(drawMode, VertexFormats.POSITION_COLOR); - -// bufferbuilder.begin(GL11.GL_TRIANGLE_FAN, VertexFormats.POSITION); - - float alpha = (float) (color >> 24 & 255) / 255.0F; - float red = (float) (color >> 16 & 255) / 255.0F; - float green = (float) (color >> 8 & 255) / 255.0F; - float blue = (float) (color & 255) / 255.0F; - - bufferbuilder.vertex(x, y, 0).next(); - final double TWICE_PI = Math.PI * 2; + double tickDelta = (double) MinecraftClient.getInstance().getTickDelta(); + return new Vec3d( + e.getX() - MathHelper.lerp(tickDelta, e.lastRenderX, e.getX()), + e.getY() - MathHelper.lerp(tickDelta, e.lastRenderY, e.getY()), + e.getZ() - MathHelper.lerp(tickDelta, e.lastRenderZ, e.getZ())); + } - for (int i = 0; i <= sides; i++) { - double angle = (TWICE_PI * i / sides) + Math.toRadians(180); - bufferbuilder.vertex(x + Math.sin(angle) * radius, y + Math.cos(angle) * radius, 0).next(); - } - tessellator.draw(); + public static void setup() { + RenderSystem.enableBlend(); + RenderSystem.defaultBlendFunc(); + RenderSystem.disableTexture(); + } - GL11.glEnable(GL11.GL_TEXTURE_2D); - GL11.glDisable(GL11.GL_BLEND); + public static void cleanup() { + RenderSystem.disableBlend(); + RenderSystem.enableTexture(); } }
\ No newline at end of file |