diff --git a/src/main/java/dev/heliosclient/managers/GradientManager.java b/src/main/java/dev/heliosclient/managers/GradientManager.java index 0cd7838..ffa3f29 100644 --- a/src/main/java/dev/heliosclient/managers/GradientManager.java +++ b/src/main/java/dev/heliosclient/managers/GradientManager.java @@ -1,13 +1,12 @@ package dev.heliosclient.managers; import java.awt.Color; -import java.util.HashMap; -import java.util.Map; +import java.util.LinkedHashMap; import java.util.Set; import java.util.function.Supplier; public class GradientManager { - private static final Map gradients = new HashMap<>(); + private static final LinkedHashMap gradients = new LinkedHashMap<>(); public static void registerGradient(String name, Gradient gradientSupplier) { gradients.put(name, gradientSupplier); diff --git a/src/main/java/dev/heliosclient/module/modules/movement/Scaffold.java b/src/main/java/dev/heliosclient/module/modules/movement/Scaffold.java index 20a5515..7217ef0 100644 --- a/src/main/java/dev/heliosclient/module/modules/movement/Scaffold.java +++ b/src/main/java/dev/heliosclient/module/modules/movement/Scaffold.java @@ -80,7 +80,7 @@ public class Scaffold extends Module_ { .description("Radius around the place to place the blocks") .onSettingChange(this) .defaultValue(0d) - .range(0, 5) + .range(0, 7) .roundingPlace(0) .build() ); @@ -245,35 +245,35 @@ public void placeFromCenter(BlockPos center) { //Place the block below the player placeBlockPos(center, itemSlot); - // Calculate the direction the player is moving - Vec3d direction = Vec3d.ZERO; - if (mc.options.forwardKey.isPressed()) { - direction = direction.add(mc.player.getRotationVector()); - } - if (mc.options.backKey.isPressed()) { - direction = direction.subtract(mc.player.getRotationVector()); - } - if (mc.options.leftKey.isPressed()) { - direction = direction.add(new Vec3d(-mc.player.getRotationVector().z, 0, mc.player.getRotationVector().x)); - } - if (mc.options.rightKey.isPressed()) { - direction = direction.add(new Vec3d(mc.player.getRotationVector().z, 0, -mc.player.getRotationVector().x)); - } + // Calculate the direction the player is moving + Vec3d direction = Vec3d.ZERO; + if (mc.options.forwardKey.isPressed()) { + direction = direction.add(mc.player.getRotationVector()); + } + if (mc.options.backKey.isPressed()) { + direction = direction.subtract(mc.player.getRotationVector()); + } + if (mc.options.rightKey.isPressed()) { + direction = direction.add(new Vec3d(-mc.player.getRotationVector().z, 0, mc.player.getRotationVector().x)); + } + if (mc.options.leftKey.isPressed()) { + direction = direction.add(new Vec3d(mc.player.getRotationVector().z, 0, -mc.player.getRotationVector().x)); + } - // Normalize the direction vector to prevent faster movement when moving diagonally - direction = direction.normalize(); + // Normalize the direction vector to prevent faster movement when moving diagonally + direction = direction.normalize(); - for (int i = 1; i <= extendRange.value; i++) { - BlockPos pos = center.add((int) (direction.x * i), 0, (int) (direction.z * i)); + for (int i = 1; i <= extendRange.value; i++) { + BlockPos pos = center.add((int) (direction.x * i), 0, (int) (direction.z * i)); - // Check if the block can be placed at the position - BlockState state = mc.world.getBlockState(pos); - if (!BlockUtils.canPlace(pos, state) || !state.isAir()) continue; + // Check if the block can be placed at the position + BlockState state = mc.world.getBlockState(pos); + if (!BlockUtils.canPlace(pos, state) || !state.isAir()) continue; - if (!placeBlockPos(pos, itemSlot)) { - break; + if (!placeBlockPos(pos, itemSlot)) { + break; + } } - } int rangeInt = (int) placeRadius.value; @@ -332,7 +332,7 @@ private boolean placeBlockPos(BlockPos pos, int itemSlot) { pos, true, 500, - QuadColor.CardinalDirection.DIAGONAL_LEFT + null ); } else { Renderer3d.renderFadingBlock(lineColor.value, fillColor.value, pos.toCenterPos().subtract(0.5f, 0.5f, 0.5f), dimensions, 1000); diff --git a/src/main/java/dev/heliosclient/module/modules/render/BlockSelection.java b/src/main/java/dev/heliosclient/module/modules/render/BlockSelection.java index 1770212..8bfdd23 100644 --- a/src/main/java/dev/heliosclient/module/modules/render/BlockSelection.java +++ b/src/main/java/dev/heliosclient/module/modules/render/BlockSelection.java @@ -15,7 +15,9 @@ import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.HitResult; import net.minecraft.util.math.Box; +import net.minecraft.util.math.Direction; import net.minecraft.util.shape.VoxelShape; +import org.apache.commons.lang3.ArrayUtils; import java.awt.*; @@ -50,6 +52,15 @@ public class BlockSelection extends Module_ { .shouldRender(() -> outline.value) .build() ); + BooleanSetting renderOneSide = sgGeneral.add(new BooleanSetting.Builder() + .name("Flat Render") + .description("Renders only the side you are looking at.") + .value(false) + .defaultValue(false) + .onSettingChange(this) + .build() + ); + BooleanSetting fill = sgGeneral.add(new BooleanSetting.Builder() .name("Fill") .description("Draw side fill of holes") @@ -101,22 +112,28 @@ public void renderBlockHitResult(BlockHitResult result, boolean doEmptyRender) { if (shape.isEmpty()) return; + Direction[] dirs = new Direction[6]; + + if(renderOneSide.value){ + dirs = ArrayUtils.removeElement(Direction.values(),result.getSide()); + } + if (advanced.value) { for (Box b : shape.getBoundingBoxes()) { - renderSelection(b.offset(result.getBlockPos()).expand(0.0045f)); + renderSelection(b.offset(result.getBlockPos()).expand(0.0045f),dirs); } } else { - renderSelection(shape.getBoundingBox().offset(result.getBlockPos()).expand(0.0045f)); + renderSelection(shape.getBoundingBox().offset(result.getBlockPos()).expand(0.0045f),dirs); } } - public void renderSelection(Box box) { + public void renderSelection(Box box,Direction... exclude) { if (outline.value && fill.value) { - Renderer3D.drawBoxBoth(box, QuadColor.single(fillColor.value.getRGB()), QuadColor.single(lineColor.value.getRGB()), (float) outlineWidth.value); + Renderer3D.drawBoxBoth(box, QuadColor.single(fillColor.value.getRGB()), QuadColor.single(lineColor.value.getRGB()), (float) outlineWidth.value,exclude); } else if (outline.value) { - Renderer3D.drawBoxOutline(box, QuadColor.single(lineColor.value.getRGB()), (float) outlineWidth.value); + Renderer3D.drawBoxOutline(box, QuadColor.single(lineColor.value.getRGB()), (float) outlineWidth.value,exclude); } else if (fill.value) { - Renderer3D.drawBoxFill(box, QuadColor.single(fillColor.value.getRGB())); + Renderer3D.drawBoxFill(box, QuadColor.single(fillColor.value.getRGB()),exclude); } } } \ No newline at end of file diff --git a/src/main/java/dev/heliosclient/module/modules/render/CustomCrosshair.java b/src/main/java/dev/heliosclient/module/modules/render/CustomCrosshair.java index 175fae6..4c8f928 100644 --- a/src/main/java/dev/heliosclient/module/modules/render/CustomCrosshair.java +++ b/src/main/java/dev/heliosclient/module/modules/render/CustomCrosshair.java @@ -90,7 +90,7 @@ public class CustomCrosshair extends Module_ { ); BooleanSetting dynamic = sgGeneral.add(new BooleanSetting.Builder() .name("Dynamic") - .description("Draws the crosshair only when you are looking at smth (block / entity") + .description("Draws the crosshair only when you are looking at smth (block / entity)") .defaultValue(false) .onSettingChange(this) .build() @@ -129,7 +129,7 @@ public void renderStandard(DrawContext dr, int x, int y, int width, int height) mask(dr, () -> { Renderer2D.drawHorizontalLine(dr.getMatrices().peek().getPositionMatrix(), x - (float) size.value / 2.0f, (float) size.value, (float) (y - thickness.value / 2.0f), (float) thickness.value, -1); Renderer2D.drawVerticalLine(dr.getMatrices().peek().getPositionMatrix(), x - (float) thickness.value / 2.0f, (float) (y - size.value / 2.0f), (float) size.value, (float) thickness.value, -1); - }, x - getSize() / 2 - 2, y - getSize() / 2 - 2, width + getSize() + 2, height + getSize() + 2); + }, x - getSize() / 2 - 2, y - getSize() / 2 - 2, getSize() + 2, getSize() + 2); } @@ -138,13 +138,13 @@ public void renderRounded(DrawContext dr, int x, int y, int width, int height) { Renderer2D.drawRoundedRectangle(dr.getMatrices().peek().getPositionMatrix(), x - (float) size.value / 2.0f, (float) (y - thickness.value / 2.0f), (float) size.value, (float) thickness.value, (float) radius.value, -1); Renderer2D.drawRoundedRectangle(dr.getMatrices().peek().getPositionMatrix(), x - (float) thickness.value / 2.0f, (float) (y - size.value / 2.0f), (float) thickness.value, (float) size.value, (float) radius.value, -1); - }, x - getSize() / 2, y - getSize() / 2, width + getSize(), height + getSize()); + }, x - getSize() / 2, y - getSize() / 2, getSize(), getSize()); } public void renderSquare(DrawContext dr, int x, int y, int width, int height) { mask(dr, () -> { Renderer2D.drawOutlineRoundedBox(dr.getMatrices().peek().getPositionMatrix(), x - (float) size.value / 2.0f, (float) (y - size.value / 2.0f), (float) size.value, (float) size.value, (float) radius.value, (float) thickness.value, -1); - }, x - getSize() / 2, y - getSize() / 2, width + getSize(), height + getSize()); + }, x - getSize() / 2 - 5, y - getSize() / 2 - 5, getSize() + 5, getSize() + 5); } public void renderInverseTriangleGap(DrawContext dr, int x, int y) { @@ -167,15 +167,15 @@ public void renderInverseTriangleGap(DrawContext dr, int x, int y) { } public void renderDot(DrawContext dr, int x, int y, int width, int height) { - mask(dr, () -> Renderer2D.drawFilledCircle(dr.getMatrices().peek().getPositionMatrix(), x, y, (float) size.value / 2.0f, -1), x - getSize() / 2 - getSize() / 5, y - getSize() / 2 - getSize() / 5, width + getSize() + getSize() / 5, height + getSize() + getSize() / 5); + mask(dr, () -> Renderer2D.drawFilledCircle(dr.getMatrices().peek().getPositionMatrix(), x, y, (float) size.value / 2.0f, -1), x - getSize() * 2, y - getSize() * 2 , getSize() * 4, getSize() * 4); } public void renderCircle(DrawContext dr, int x, int y, int width, int height) { - mask(dr, () -> Renderer2D.drawCircle(dr.getMatrices().peek().getPositionMatrix(), x, y, (float) size.value / 2.0f, (float) thickness.value, -1), x - getSize() - getSize() / 5, y - getSize() - getSize() / 5, width + getSize() + getSize() / 5, height + getSize() + getSize() / 5); + mask(dr, () -> Renderer2D.drawCircle(dr.getMatrices().peek().getPositionMatrix(), x, y, (float) size.value / 2.0f, (float) thickness.value, -1), x - (getSize() * 2) - (int) thickness.value, y - (getSize() * 2) - (int) thickness.value, getSize() * 4 + (int) thickness.value, getSize() * 4 + (int) thickness.value); } private int getSize() { - return (int) size.value; + return (int) Math.ceil(size.value); } public void mask(DrawContext dr, Runnable task, int x, int y, int width, int height) { diff --git a/src/main/java/dev/heliosclient/module/modules/render/Test.java b/src/main/java/dev/heliosclient/module/modules/render/Test.java index 24a39f2..d3e6b20 100644 --- a/src/main/java/dev/heliosclient/module/modules/render/Test.java +++ b/src/main/java/dev/heliosclient/module/modules/render/Test.java @@ -67,6 +67,14 @@ public Test() { @Override public void onEnable() { super.onEnable(); + GradientBlockRenderer.renderGradientBlock( + ColorManager.INSTANCE::getPrimaryGradientStart, + ColorManager.INSTANCE::getPrimaryGradientEnd, + new BlockPos(100,70,100), + true, + 1020300, + null + ); } @Override @@ -103,15 +111,6 @@ public void render(RenderEvent event) { if (GradientRounded.value) Renderer2D.drawRoundedGradientRectangleWithShadow(drawContext.getMatrices(), 22, 20, 40, 40, Color.BLUE, Color.WHITE, Color.BLACK, Color.GRAY, 2, 20, Color.WHITE); - - GradientBlockRenderer.renderGradientBlock( - ColorManager.INSTANCE::getPrimaryGradientStart, - ColorManager.INSTANCE::getPrimaryGradientEnd, - new BlockPos(100,70,100), - true, - 1020300, - QuadColor.CardinalDirection.DIAGONAL_LEFT - ); } @SubscribeEvent diff --git a/src/main/java/dev/heliosclient/util/BlockUtils.java b/src/main/java/dev/heliosclient/util/BlockUtils.java index cfdf4d0..9e68506 100644 --- a/src/main/java/dev/heliosclient/util/BlockUtils.java +++ b/src/main/java/dev/heliosclient/util/BlockUtils.java @@ -234,12 +234,10 @@ public static boolean place(BlockPos pos, boolean rotate, boolean clientSideRota if (!canPlace(pos, mc.world.getBlockState(pos))) return false; - if (!airPlace && !isPlaceable(pos, false)) - return false; - Vec3d hitPos = Vec3d.ofCenter(pos); Direction d = getPlaceSide(pos); + Direction dOld = d; if (d == null) { d = Direction.UP; @@ -249,7 +247,7 @@ public static boolean place(BlockPos pos, boolean rotate, boolean clientSideRota Block neighborBlock = mc.world.getBlockState(pos.offset(d)).getBlock(); - BlockHitResult blockHitResult = new BlockHitResult(hitPos, d.getOpposite(), airPlace ? pos : pos.offset(d), false); + BlockHitResult blockHitResult = new BlockHitResult(hitPos, d.getOpposite(), airPlace || dOld == null ? pos : pos.offset(d), false); ActionResult result = ActionResult.FAIL; if (rotate) { @@ -265,7 +263,7 @@ public static boolean place(BlockPos pos, boolean rotate, boolean clientSideRota } private static ActionResult interactBlock(BlockHitResult blockHitResult,Block block, Hand hand){ - if (isClickable(block)) { + if (!isClickable(block)) { mc.player.networkHandler.sendPacket(new ClientCommandC2SPacket(mc.player, ClientCommandC2SPacket.Mode.PRESS_SHIFT_KEY)); } @@ -276,7 +274,7 @@ private static ActionResult interactBlock(BlockHitResult blockHitResult,Block bl mc.player.swingHand(hand); } - if (isClickable(block)) + if (!isClickable(block)) mc.player.networkHandler.sendPacket(new ClientCommandC2SPacket(mc.player, ClientCommandC2SPacket.Mode.RELEASE_SHIFT_KEY)); return result; diff --git a/src/main/java/dev/heliosclient/util/render/GradientBlockRenderer.java b/src/main/java/dev/heliosclient/util/render/GradientBlockRenderer.java index 42aad02..a17836f 100644 --- a/src/main/java/dev/heliosclient/util/render/GradientBlockRenderer.java +++ b/src/main/java/dev/heliosclient/util/render/GradientBlockRenderer.java @@ -74,16 +74,23 @@ public static void renderGradientBlocks() { endG = ColorUtils.argbToRgb(endG,MODIFY_ALPHA_VALUE); } + QuadColor color = null; + if(gb.dir == null){ + color = QuadColor.gradient(startG,endG); + }else{ + color = QuadColor.gradient(startG,endG, gb.dir); + } + if(OUTLINE && FILL){ - Renderer3D.drawBoxBoth(gradientBlockBoxMap.get(gb), QuadColor.gradient(startG,endG, gb.dir),LINE_WIDTH,gb.exclude()); + Renderer3D.drawBoxBoth(gradientBlockBoxMap.get(gb), color,LINE_WIDTH,gb.exclude()); continue; } if(OUTLINE){ - Renderer3D.drawBoxOutline(gradientBlockBoxMap.get(gb), QuadColor.gradient(startG,endG, gb.dir),LINE_WIDTH,gb.exclude()); + Renderer3D.drawBoxOutline(gradientBlockBoxMap.get(gb), color,LINE_WIDTH,gb.exclude()); } if(FILL){ - Renderer3D.drawBoxFill(gradientBlockBoxMap.get(gb), QuadColor.gradient(startG,endG, gb.dir),gb.exclude()); + Renderer3D.drawBoxFill(gradientBlockBoxMap.get(gb), color,gb.exclude()); } } diff --git a/src/main/java/dev/heliosclient/util/render/Renderer2D.java b/src/main/java/dev/heliosclient/util/render/Renderer2D.java index 3e77fc6..11abf87 100644 --- a/src/main/java/dev/heliosclient/util/render/Renderer2D.java +++ b/src/main/java/dev/heliosclient/util/render/Renderer2D.java @@ -796,7 +796,7 @@ public static void drawTriangle(Matrix4f matrix4f, int x1, int y1, int x2, int y draw(); } public static void drawFilledTriangle(Matrix4f matrix4f, int x1, int y1, int x2, int y2, int x3, int y3, int color) { - BufferBuilder bufferBuilder = setupAndBegin(VertexFormat.DrawMode.TRIANGLES, VertexFormats.POSITION_COLOR); + BufferBuilder bufferBuilder = setupAndBegin(VertexFormat.DrawMode.TRIANGLE_FAN, VertexFormats.POSITION_COLOR); bufferBuilder.vertex(matrix4f, x1, y1, 0).color(color).next(); bufferBuilder.vertex(matrix4f, x2, y2, 0).color(color).next(); diff --git a/src/main/java/dev/heliosclient/util/render/Renderer3D.java b/src/main/java/dev/heliosclient/util/render/Renderer3D.java index ce71cb1..621450f 100644 --- a/src/main/java/dev/heliosclient/util/render/Renderer3D.java +++ b/src/main/java/dev/heliosclient/util/render/Renderer3D.java @@ -118,14 +118,10 @@ public static void drawBoxOutline(Box box, QuadColor color, float lineWidth, Dir RenderSystem.setShader(GameRenderer::getRenderTypeLinesProgram); RenderSystem.lineWidth(lineWidth); - GL11.glEnable(GL11.GL_LINE_SMOOTH); - GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST); buffer.begin(VertexFormat.DrawMode.LINES, VertexFormats.LINES); Vertexer.vertexBoxLines(matrices, buffer, moveToZero(box), color, excludeDirs); tessellator.draw(); - GL11.glDisable(GL11.GL_LINE_SMOOTH); - GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_FASTEST); RenderSystem.enableCull(); @@ -247,10 +243,17 @@ public static void drawLine(Vec3d start, Vec3d end, LineColor color, float width RenderSystem.setShader(GameRenderer::getRenderTypeLinesProgram); RenderSystem.lineWidth(width); + GL11.glEnable(GL11.GL_LINE_SMOOTH); + GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST); + buffer.begin(VertexFormat.DrawMode.LINES, VertexFormats.LINES); Vertexer.vertexLine(matrices, buffer, 0f, 0f, 0f, (float) (end.x - start.x), (float) (end.y - start.y), (float) (end.z - start.z), color); tessellator.draw(); + GL11.glDisable(GL11.GL_LINE_SMOOTH); + GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_FASTEST); + + RenderSystem.enableCull(); RenderSystem.enableDepthTest(); cleanup(); diff --git a/src/main/java/dev/heliosclient/util/render/Vertexer.java b/src/main/java/dev/heliosclient/util/render/Vertexer.java index 57b3b87..2619a6b 100644 --- a/src/main/java/dev/heliosclient/util/render/Vertexer.java +++ b/src/main/java/dev/heliosclient/util/render/Vertexer.java @@ -30,30 +30,29 @@ public static void vertexBoxQuads(MatrixStack matrices, VertexConsumer vertexCon int cullMode = excludeDirs.length == 0 ? CULL_BACK : CULL_NONE; if (!ArrayUtils.contains(excludeDirs, Direction.DOWN)) { - vertexQuad(matrices, vertexConsumer, x1, y1, z1, x2, y1, z1, x2, y1, z2, x1, y1, z2, cullMode, QuadColor.single(quadColor.getColor(0)[0], quadColor.getColor(0)[1], quadColor.getColor(0)[2], quadColor.getColor(0)[3])); + vertexQuad(matrices, vertexConsumer, x1, y1, z1, x2, y1, z1, x2, y1, z2, x1, y1, z2, cullMode, quadColor, box); } if (!ArrayUtils.contains(excludeDirs, Direction.WEST)) { - vertexQuad(matrices, vertexConsumer, x1, y1, z2, x1, y2, z2, x1, y2, z1, x1, y1, z1, cullMode, quadColor); + vertexQuad(matrices, vertexConsumer, x1, y1, z2, x1, y2, z2, x1, y2, z1, x1, y1, z1, cullMode, quadColor, box); } if (!ArrayUtils.contains(excludeDirs, Direction.EAST)) { - vertexQuad(matrices, vertexConsumer, x2, y1, z1, x2, y2, z1, x2, y2, z2, x2, y1, z2, cullMode, quadColor); + vertexQuad(matrices, vertexConsumer, x2, y1, z1, x2, y2, z1, x2, y2, z2, x2, y1, z2, cullMode, quadColor, box); } if (!ArrayUtils.contains(excludeDirs, Direction.NORTH)) { - vertexQuad(matrices, vertexConsumer, x1, y1, z1, x1, y2, z1, x2, y2, z1, x2, y1, z1, cullMode, quadColor); + vertexQuad(matrices, vertexConsumer, x1, y1, z1, x1, y2, z1, x2, y2, z1, x2, y1, z1, cullMode, quadColor, box); } if (!ArrayUtils.contains(excludeDirs, Direction.SOUTH)) { - vertexQuad(matrices, vertexConsumer, x2, y1, z2, x2, y2, z2, x1, y2, z2, x1, y1, z2, cullMode, quadColor); + vertexQuad(matrices, vertexConsumer, x2, y1, z2, x2, y2, z2, x1, y2, z2, x1, y1, z2, cullMode, quadColor, box); } if (!ArrayUtils.contains(excludeDirs, Direction.UP)) { - vertexQuad(matrices, vertexConsumer, x1, y2, z2, x2, y2, z2, x2, y2, z1, x1, y2, z1, cullMode, QuadColor.single(quadColor.getColor(2)[0], quadColor.getColor(2)[1], quadColor.getColor(2)[2], quadColor.getColor(2)[3])); + vertexQuad(matrices, vertexConsumer, x1, y2, z2, x2, y2, z2, x2, y2, z1, x1, y2, z1, cullMode, quadColor, box); } } - public static void vertexQuad(MatrixStack matrices, VertexConsumer vertexConsumer, float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, float x4, float y4, float z4, int cullMode, QuadColor quadColor) { int[] color = quadColor.getAllColors(); @@ -72,6 +71,27 @@ public static void vertexQuad(MatrixStack matrices, VertexConsumer vertexConsume } } + public static void vertexQuad(MatrixStack matrices, VertexConsumer vertexConsumer, float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, float x4, float y4, float z4, int cullMode, QuadColor quadColor, Box box) { + int[] color1 = quadColor.getColorForVertex(x1, y1, z1, box); + int[] color2 = quadColor.getColorForVertex(x2, y2, z2, box); + int[] color3 = quadColor.getColorForVertex(x3, y3, z3, box); + int[] color4 = quadColor.getColorForVertex(x4, y4, z4, box); + + if (cullMode != CULL_FRONT) { + vertexConsumer.vertex(matrices.peek().getPositionMatrix(), x1, y1, z1).color(color1[0], color1[1], color1[2], color1[3]).next(); + vertexConsumer.vertex(matrices.peek().getPositionMatrix(), x2, y2, z2).color(color2[0], color2[1], color2[2], color2[3]).next(); + vertexConsumer.vertex(matrices.peek().getPositionMatrix(), x3, y3, z3).color(color3[0], color3[1], color3[2], color3[3]).next(); + vertexConsumer.vertex(matrices.peek().getPositionMatrix(), x4, y4, z4).color(color4[0], color4[1], color4[2], color4[3]).next(); + } + + if (cullMode != CULL_BACK) { + vertexConsumer.vertex(matrices.peek().getPositionMatrix(), x4, y4, z4).color(color4[0], color4[1], color4[2], color4[3]).next(); + vertexConsumer.vertex(matrices.peek().getPositionMatrix(), x3, y3, z3).color(color3[0], color3[1], color3[2], color3[3]).next(); + vertexConsumer.vertex(matrices.peek().getPositionMatrix(), x2, y2, z2).color(color2[0], color2[1], color2[2], color2[3]).next(); + vertexConsumer.vertex(matrices.peek().getPositionMatrix(), x1, y1, z1).color(color1[0], color1[1], color1[2], color1[3]).next(); + } + } + public static void vertexBoxLines(MatrixStack matrices, VertexConsumer vertexConsumer, Box box, QuadColor quadColor, Direction... excludeDirs) { float x1 = (float) box.minX; float y1 = (float) box.minY; diff --git a/src/main/java/dev/heliosclient/util/render/color/QuadColor.java b/src/main/java/dev/heliosclient/util/render/color/QuadColor.java index 5177503..46af125 100644 --- a/src/main/java/dev/heliosclient/util/render/color/QuadColor.java +++ b/src/main/java/dev/heliosclient/util/render/color/QuadColor.java @@ -8,6 +8,8 @@ */ package dev.heliosclient.util.render.color; +import net.minecraft.util.math.Box; + import java.util.function.Function; public class QuadColor extends RenderColor { @@ -43,9 +45,15 @@ public static QuadColor gradient(int color1, int color2, CardinalDirection direc (color2 & 0xff0000) >> 16, (color2 & 0xff00) >> 8, color2 & 0xff, color2 >> 24 & 0xff, direction); } + public static QuadColor gradient(int color1, int color2) { + return QuadColor.gradient( + (color1 & 0xff0000) >> 16, (color1 & 0xff00) >> 8, color1 & 0xff, color1 >> 24 & 0xff, + (color2 & 0xff0000) >> 16, (color2 & 0xff00) >> 8, color2 & 0xff, color2 >> 24 & 0xff); + } public static QuadColor gradient(int red1, int green1, int blue1, int alpha1, int red2, int green2, int blue2, int alpha2, CardinalDirection direction) { return new QuadColor(curVertex -> { + if (direction.isStartVertex(curVertex)) { return new int[]{red1, green1, blue1, alpha1}; } @@ -53,6 +61,17 @@ public static QuadColor gradient(int red1, int green1, int blue1, int alpha1, in return new int[]{red2, green2, blue2, alpha2}; }); } + public static QuadColor gradient(int red1, int green1, int blue1, int alpha1, int red2, int green2, int blue2, int alpha2) { + return new QuadColor(curVertex -> { + float t = (float) curVertex / 3; // Interpolate between 0 and 1 based on vertex index + int red = (int) (red1 * (1 - t) + red2 * t); + int green = (int) (green1 * (1 - t) + green2 * t); + int blue = (int) (blue1 * (1 - t) + blue2 * t); + int alpha = (int) (alpha1 * (1 - t) + alpha2 * t); + return new int[]{red, green, blue, alpha}; + }); + } + public static QuadColor custom(float red1, float green1, float blue1, float alpha1, float red2, float green2, float blue2, float alpha2, float red3, float green3, float blue3, float alpha3, float red4, float green4, float blue4, float alpha4) { return QuadColor.custom( @@ -71,16 +90,31 @@ public static QuadColor custom(int color1, int color2, int color3, int color4) { } public static QuadColor custom(int red1, int green1, int blue1, int alpha1, int red2, int green2, int blue2, int alpha2, int red3, int green3, int blue3, int alpha3, int red4, int green4, int blue4, int alpha4) { - return new QuadColor(curVertex -> { - return switch (curVertex) { - case 0 -> new int[]{red1, green1, blue1, alpha1}; - case 1 -> new int[]{red2, green2, blue2, alpha2}; - case 2 -> new int[]{red3, green3, blue3, alpha3}; - default -> new int[]{red4, green4, blue4, alpha4}; - }; + return new QuadColor(curVertex -> switch (curVertex) { + case 0 -> new int[]{red1, green1, blue1, alpha1}; + case 1 -> new int[]{red2, green2, blue2, alpha2}; + case 2 -> new int[]{red3, green3, blue3, alpha3}; + default -> new int[]{red4, green4, blue4, alpha4}; }); } + public int[] getColorForVertex(float x, float y, float z, Box box) { + float tX = (x - (float) box.minX) / ((float) box.maxX - (float) box.minX); + float tY = (y - (float) box.minY) / ((float) box.maxY - (float) box.minY); + float tZ = (z - (float) box.minZ) / ((float) box.maxZ - (float) box.minZ); + + int[] color1 = getColor(0); + int[] color2 = getColor(3); + + int red = (int) (color1[0] * (1 - tX) + color2[0] * tX); + int green = (int) (color1[1] * (1 - tY) + color2[1] * tY); + int blue = (int) (color1[2] * (1 - tZ) + color2[2] * tZ); + int alpha = (int) (color1[3] * (1 - tX) + color2[3] * tX); + + return new int[]{red, green, blue, alpha}; + } + + public int[] getColor(int curVertex) { int[] outColor = getColorFunc.apply(curVertex);