Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nuker refactor #4787

Merged
merged 6 commits into from
Aug 2, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,7 @@ public class Nuker extends Module {
.build()
);

private final Pool<BlockPos.Mutable> blockPosPool = new Pool<>(BlockPos.Mutable::new);
private final List<BlockPos.Mutable> blocks = new ArrayList<>();
private final List<BlockPos> blocks = new ArrayList<>();

private boolean firstBlock;
private final BlockPos.Mutable lastBlockPos = new BlockPos.Mutable();
Expand Down Expand Up @@ -354,16 +353,20 @@ private void onTickPre(TickEvent.Pre event) {

// Find blocks to break
BlockIterator.register(Math.max((int) Math.ceil(range.get()+1), maxh), Math.max((int) Math.ceil(range.get()), maxv), (blockPos, blockState) -> {
// Check for air, unbreakable blocks and distance
boolean toofarSphere = Utils.squaredDistance(pX, pY, pZ, blockPos.getX() + 0.5, blockPos.getY() + 0.5, blockPos.getZ() + 0.5) > rangeSq;
boolean toofarUniformCube = maxDist(Math.floor(pX), Math.floor(pY), Math.floor(pZ), blockPos.getX(), blockPos.getY(), blockPos.getZ()) >= range.get();
boolean toofarCube = !box.contains(Vec3d.ofCenter(blockPos));

if (!BlockUtils.canBreak(blockPos, blockState)
|| (toofarSphere && shape.get() == Shape.Sphere)
|| (toofarUniformCube && shape.get() == Shape.UniformCube)
|| (toofarCube && shape.get() == Shape.Cube))
return;
// Check for air, unbreakable blocks and distance
Wide-Cat marked this conversation as resolved.
Show resolved Hide resolved
switch (shape.get()) {
case Sphere -> {
if (Utils.squaredDistance(pX, pY, pZ, blockPos.getX() + 0.5, blockPos.getY() + 0.5, blockPos.getZ() + 0.5) > rangeSq) return;
}
case UniformCube -> {
if (chebyshevDist(mc.player.getBlockPos().getX(), mc.player.getBlockPos().getY(), mc.player.getBlockPos().getZ(), blockPos.getX(), blockPos.getY(), blockPos.getZ()) >= range.get()) return;
}
case Cube -> {
if (!box.contains(Vec3d.ofCenter(blockPos))) return;
}
}

if (!BlockUtils.canBreak(blockPos, blockState)) return;
Wide-Cat marked this conversation as resolved.
Show resolved Hide resolved

// Flatten
if (mode.get() == Mode.Flatten && blockPos.getY() < Math.floor(mc.player.getY())) return;
Expand All @@ -376,7 +379,7 @@ private void onTickPre(TickEvent.Pre event) {
if (listMode.get() == ListMode.Blacklist && blacklist.get().contains(blockState.getBlock())) return;

// Add block
blocks.add(blockPosPool.get().set(blockPos));
blocks.add(blockPos.toImmutable());
});

// Break block if found
Expand Down Expand Up @@ -418,7 +421,7 @@ else if (sortMode.get() != SortMode.None)
if (rotate.get()) Rotations.rotate(Rotations.getYaw(block), Rotations.getPitch(block), () -> breakBlock(block));
else breakBlock(block);

if (enableRenderBreaking.get()) RenderUtils.renderTickingBlock(block.toImmutable(), sideColor.get(), lineColor.get(), shapeModeBreak.get(), 0, 8, true, false);
if (enableRenderBreaking.get()) RenderUtils.renderTickingBlock(block, sideColor.get(), lineColor.get(), shapeModeBreak.get(), 0, 8, true, false);
lastBlockPos.set(block);

count++;
Expand All @@ -428,7 +431,6 @@ else if (sortMode.get() != SortMode.None)
firstBlock = false;

// Clear current block positions
for (BlockPos.Mutable blockPos : blocks) blockPosPool.free(blockPos);
blocks.clear();
});
}
Expand Down Expand Up @@ -472,11 +474,11 @@ public enum Shape {
Sphere
}

public static double maxDist(double x1, double y1, double z1, double x2, double y2, double z2) {
public static int chebyshevDist(int x1, int y1, int z1, int x2, int y2, int z2) {
// Gets the largest X, Y or Z difference, manhattan style
Wide-Cat marked this conversation as resolved.
Show resolved Hide resolved
double dX = Math.ceil(Math.abs(x2 - x1));
double dY = Math.ceil(Math.abs(y2 - y1));
double dZ = Math.ceil(Math.abs(z2 - z1));
int dX = Math.abs(x2 - x1);
int dY = Math.abs(y2 - y1);
int dZ = Math.abs(z2 - z1);
return Math.max(Math.max(dX, dY), dZ);
}
}