Skip to content

Commit

Permalink
Smoother gradients. Typo fix and some bugs fixed. Also added Render T…
Browse files Browse the repository at this point in the history
…op in block selection.
  • Loading branch information
tanishisherewithhh committed Aug 1, 2024
1 parent 55f1674 commit 56b8a21
Show file tree
Hide file tree
Showing 11 changed files with 156 additions and 79 deletions.
5 changes: 2 additions & 3 deletions src/main/java/dev/heliosclient/managers/GradientManager.java
Original file line number Diff line number Diff line change
@@ -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<String, Gradient> gradients = new HashMap<>();
private static final LinkedHashMap<String, Gradient> gradients = new LinkedHashMap<>();

public static void registerGradient(String name, Gradient gradientSupplier) {
gradients.put(name, gradientSupplier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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);

}

Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
17 changes: 8 additions & 9 deletions src/main/java/dev/heliosclient/module/modules/render/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/dev/heliosclient/util/BlockUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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));
}

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/heliosclient/util/render/Renderer2D.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/dev/heliosclient/util/render/Renderer3D.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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();
Expand Down
Loading

0 comments on commit 56b8a21

Please sign in to comment.