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

Optimize validHole check #3055

Merged
merged 4 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -5,8 +5,14 @@

package meteordevelopment.meteorclient.mixininterface;

import net.minecraft.util.math.BlockPos;

public interface IBox {
void expand(double v);

void set(double x1, double y1, double z1, double x2, double y2, double z2);

default void set(BlockPos pos) {
set(pos.getX(), pos.getY(), pos.getZ(), pos.getX() + 1, pos.getY() + 1, pos.getZ() + 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import meteordevelopment.meteorclient.events.render.Render3DEvent;
import meteordevelopment.meteorclient.events.world.TickEvent;
import meteordevelopment.meteorclient.mixin.AbstractBlockAccessor;
import meteordevelopment.meteorclient.mixininterface.IBox;
import meteordevelopment.meteorclient.renderer.ShapeMode;
import meteordevelopment.meteorclient.settings.*;
import meteordevelopment.meteorclient.systems.friends.Friends;
Expand All @@ -26,9 +27,11 @@
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.entity.TntEntity;
import net.minecraft.entity.decoration.EndCrystalEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItem;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;

Expand Down Expand Up @@ -221,6 +224,10 @@ public class HoleFiller extends Module {

private final List<PlayerEntity> targets = new ArrayList<>();
private final List<Hole> holes = new ArrayList<>();

private final BlockPos.Mutable testPos = new BlockPos.Mutable();
private final Box box = new Box(0, 0, 0, 0, 0, 0);
private Vec3d testVec;
private int timer;

public HoleFiller() {
Expand Down Expand Up @@ -312,23 +319,32 @@ private void onRender(Render3DEvent event) {
}

private boolean validHole(BlockPos pos) {
if (mc.player.getBlockPos().equals(pos)) return false;
if (distance(mc.player, pos, false) > placeRange.get()) return false;
if (mc.world.getBlockState(pos).getBlock() == Blocks.COBWEB) return false;

if (smart.get() && !forceFill.get().isPressed()) {
boolean validHole = false;
for (PlayerEntity target : targets) {
if (target.getY() > pos.getY()
&& !target.getBlockPos().equals(pos)
&& (distance(target, pos, true) < feetRange.get())
) validHole = true;
testPos.set(pos);

if (mc.player.getBlockPos().equals(testPos)) return false;
if (distance(mc.player, testPos, false) > placeRange.get()) return false;
if (mc.world.getBlockState(testPos).getBlock() == Blocks.COBWEB) return false;

if (((AbstractBlockAccessor) mc.world.getBlockState(testPos).getBlock()).isCollidable()) return false;
testPos.add(0, 1, 0);
if (((AbstractBlockAccessor) mc.world.getBlockState(testPos).getBlock()).isCollidable()) return false;
testPos.add(0, -1, 0);

((IBox) box).set(pos);
if (!mc.world.getOtherEntities(null, box, entity -> entity instanceof PlayerEntity
|| entity instanceof TntEntity || entity instanceof EndCrystalEntity).isEmpty()) return false;

if (!smart.get() || forceFill.get().isPressed()) return true;

boolean validHole = false;
for (PlayerEntity target : targets) {
if (target.getY() > testPos.getY() && (distance(target, testPos, true) < feetRange.get())) {
validHole = true;
break;
}
if (!validHole) return false;
}

if (((AbstractBlockAccessor) mc.world.getBlockState(pos).getBlock()).isCollidable()) return false;
return !((AbstractBlockAccessor) mc.world.getBlockState(pos.up()).getBlock()).isCollidable();
return validHole;
}

private void setTargets() {
Expand All @@ -343,12 +359,9 @@ private void setTargets() {
) continue;

if (onlyMoving.get()) {
Vec3d velocity = new Vec3d(
player.getX() - player.prevX,
player.getY() - player.prevY,
player.getZ() - player.prevZ
);
if (velocity.length() == 0) continue;
if (player.getX() - player.prevX != 0) continue;
if (player.getY() - player.prevY != 0) continue;
if (player.getZ() - player.prevZ != 0) continue;
}

if (ignoreSafe.get()) {
Expand All @@ -363,7 +376,8 @@ private boolean isSurrounded(PlayerEntity target) {
for (Direction dir : Direction.values()) {
if (dir == Direction.UP || dir == Direction.DOWN) continue;

Block block = mc.world.getBlockState(target.getBlockPos().offset(dir)).getBlock();
testPos.set(target.getBlockPos().offset(dir));
Block block = mc.world.getBlockState(testPos).getBlock();
if (block != Blocks.OBSIDIAN && block != Blocks.BEDROCK && block != Blocks.RESPAWN_ANCHOR
&& block != Blocks.CRYING_OBSIDIAN && block != Blocks.NETHERITE_BLOCK) {
return false;
Expand All @@ -374,22 +388,20 @@ private boolean isSurrounded(PlayerEntity target) {
}

private double distance(PlayerEntity player, BlockPos pos, boolean feet) {
Vec3d center = new Vec3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
if (feet) center.add(0, 0.5, 0);
testVec = player.getPos();
if (!feet) testVec.add(0, player.getEyeHeight(mc.player.getPose()), 0);

Vec3d playerPos = player.getPos();
if (!feet) playerPos.add(0, player.getEyeHeight(mc.player.getPose()), 0);
else if (predict.get()) {
playerPos.add(
testVec.add(
player.getX() - player.prevX,
player.getY() - player.prevY,
player.getZ() - player.prevZ
);
}

double i = playerPos.x - center.x;
double j = playerPos.y - center.y;
double k = playerPos.z - center.z;
double i = testVec.x - (pos.getX() + 0.5);
double j = testVec.y - (pos.getX() + ((feet) ? 1 : 0.5));
double k = testVec.z - (pos.getZ() + 0.5);

return (Math.sqrt(i * i + j * j + k * k));
}
Expand Down