Skip to content

Commit

Permalink
Scaffold Radius, also fixed buggy BlockUtils placement when bpt > 1
Browse files Browse the repository at this point in the history
  • Loading branch information
hexadecimal233 authored and arlomcwalter committed Feb 3, 2023
1 parent db2383a commit 1c8c8ff
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ public class Scaffold extends Module {
.build()
);

private final Setting<Boolean> cancelVelocity = sgGeneral.add(new BoolSetting.Builder()
.name("cancel-velocity")
.description("Whether or not to cancel velocity when towering.")
.defaultValue(false)
.visible(fastTower::get)
.build()
);

private final Setting<Boolean> onlyOnClick = sgGeneral.add(new BoolSetting.Builder()
.name("only-on-click")
.description("Only places blocks when holding right click.")
Expand Down Expand Up @@ -98,6 +106,25 @@ public class Scaffold extends Module {
.build()
);

private final Setting<Double> range = sgGeneral.add(new DoubleSetting.Builder()
.name("range")
.description("Scaffold radius.")
.defaultValue(3)
.min(0)
.max(6)
.visible(() -> !airPlace.get())
.build()
);

private final Setting<Integer> blocksPerTick = sgGeneral.add(new IntSetting.Builder()
.name("blocks-per-tick")
.description("How many blocks to place in one tick.")
.defaultValue(3)
.min(1)
.visible(() -> !airPlace.get())
.build()
);

// Render

private final Setting<Boolean> render = sgRender.add(new BoolSetting.Builder()
Expand Down Expand Up @@ -196,12 +223,6 @@ private void onTick(TickEvent.Pre event) {
bp.set(prevBp.offset(facing));
}

FindItemResult item = InvUtils.findInHotbar(itemStack -> validItem(itemStack, bp));
if (!item.found()) return;


if (item.getHand() == null && !autoSwitch.get()) return;

// Move down if shifting
if (mc.options.sneakKey.isPressed() && !mc.options.jumpKey.isPressed()) {
if (lastSneakingY - mc.player.getY() < 0.1) {
Expand All @@ -214,20 +235,36 @@ private void onTick(TickEvent.Pre event) {
if (!lastWasSneaking) lastSneakingY = mc.player.getY();

if (mc.options.jumpKey.isPressed() && !mc.options.sneakKey.isPressed() && fastTower.get()) {
mc.player.setVelocity(0, 0.42f, 0);
Vec3d vel = mc.player.getVelocity();
mc.player.setVelocity(cancelVelocity.get() ? 0 : vel.x, 0.42, cancelVelocity.get() ? 0 : vel.z);
}

if (BlockUtils.place(bp, item, rotate.get(), 50, renderSwing.get(), true)) {
// Render block if was placed
if (render.get())
RenderUtils.renderTickingBlock(bp.toImmutable(), sideColor.get(), lineColor.get(), shapeMode.get(), 0, 8, true, false);
if (!airPlace.get()) {
List<BlockPos> blocks = new ArrayList<>();
for (double x = mc.player.getX() - range.get(); x <= mc.player.getX() + range.get(); x = x + 0.5) {
for (double z = mc.player.getZ() - range.get(); z <= mc.player.getZ() + range.get(); z = z + 0.5) {
blocks.add(new BlockPos(x, mc.player.getY() - 0.5, z));
}
}

if (!blocks.isEmpty()) {
blocks.sort(Comparator.comparingDouble(PlayerUtils::squaredDistanceTo));
int counter = 0;
for (BlockPos block : blocks) {
if (place(block)) counter++;

// Move player down so they are on top of the placed block ready to jump again
if (mc.options.jumpKey.isPressed() && !mc.options.sneakKey.isPressed() && !mc.player.isOnGround() && !mc.world.getBlockState(bp).isAir() && fastTower.get()) {
mc.player.setVelocity(0, -0.28f, 0);
if (counter >= blocksPerTick.get()) {
break;
}
}
}
}

// Move player down so they are on top of the placed block ready to jump again
if (place(bp) && fastTower.get() && mc.options.jumpKey.isPressed() && !mc.options.sneakKey.isPressed() && !mc.player.isOnGround() && !mc.world.getBlockState(bp).isAir()) {
mc.player.setVelocity(0, -0.28f, 0);
}

if (!mc.world.getBlockState(bp).isAir()) {
prevBp.set(bp);
}
Expand All @@ -249,6 +286,21 @@ private boolean validItem(ItemStack itemStack, BlockPos pos) {
return !(block instanceof FallingBlock) || !FallingBlock.canFallThrough(mc.world.getBlockState(pos));
}

private boolean place(BlockPos bp) {
FindItemResult item = InvUtils.findInHotbar(itemStack -> validItem(itemStack, bp));
if (!item.found()) return false;

if (item.getHand() == null && !autoSwitch.get()) return false;

if (BlockUtils.place(bp, item, rotate.get(), 50, renderSwing.get(), true)) {
// Render block if was placed
if (render.get())
RenderUtils.renderTickingBlock(bp.toImmutable(), sideColor.get(), lineColor.get(), shapeMode.get(), 0, 8, true, false);
return true;
}
return false;
}

public enum ListMode {
Whitelist,
Blacklist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import meteordevelopment.meteorclient.MeteorClient;
import meteordevelopment.meteorclient.events.world.TickEvent;
import meteordevelopment.meteorclient.mixininterface.IVec3d;
import meteordevelopment.meteorclient.utils.PreInit;
import meteordevelopment.meteorclient.utils.player.FindItemResult;
import meteordevelopment.meteorclient.utils.player.InvUtils;
Expand Down Expand Up @@ -37,8 +36,6 @@
import static meteordevelopment.meteorclient.MeteorClient.mc;

public class BlockUtils {
private static final Vec3d hitPos = new Vec3d(0, 0, 0);

public static boolean breaking;
private static boolean breakingThisTick;

Expand Down Expand Up @@ -82,7 +79,7 @@ public static boolean place(BlockPos blockPos, Hand hand, int slot, boolean rota
if (slot < 0 || slot > 8) return false;
if (!canPlace(blockPos, checkEntities)) return false;

((IVec3d) hitPos).set(blockPos.getX() + 0.5, blockPos.getY() + 0.5, blockPos.getZ() + 0.5);
Vec3d hitPos = Vec3d.ofCenter(blockPos);

BlockPos neighbour;
Direction side = getPlaceSide(blockPos);
Expand All @@ -97,18 +94,20 @@ public static boolean place(BlockPos blockPos, Hand hand, int slot, boolean rota

Direction s = side;

BlockHitResult bhr = new BlockHitResult(hitPos, s, neighbour, false);

if (rotate) {
Rotations.rotate(Rotations.getYaw(hitPos), Rotations.getPitch(hitPos), rotationPriority, () -> {
InvUtils.swap(slot, swapBack);

place(new BlockHitResult(hitPos, s, neighbour, false), hand, swingHand);
interact(bhr, hand, swingHand);

if (swapBack) InvUtils.swapBack();
});
} else {
InvUtils.swap(slot, swapBack);

place(new BlockHitResult(hitPos, s, neighbour, false), hand, swingHand);
interact(bhr, hand, swingHand);

if (swapBack) InvUtils.swapBack();
}
Expand All @@ -117,7 +116,7 @@ public static boolean place(BlockPos blockPos, Hand hand, int slot, boolean rota
return true;
}

private static void place(BlockHitResult blockHitResult, Hand hand, boolean swing) {
public static void interact(BlockHitResult blockHitResult, Hand hand, boolean swing) {
boolean wasSneaking = mc.player.input.sneaking;
mc.player.input.sneaking = false;

Expand Down

0 comments on commit 1c8c8ff

Please sign in to comment.