From 589343618429b07e73d115774b304a6c64e55815 Mon Sep 17 00:00:00 2001 From: ThebestkillerTBK <2593828650@qq.com> Date: Thu, 13 Oct 2022 17:41:20 +0800 Subject: [PATCH] Till Aura --- README.md | 1 + .../anticope/rejects/MeteorRejectsAddon.java | 1 + .../anticope/rejects/modules/AutoSoup.java | 5 +- .../rejects/modules/ItemGenerator.java | 8 +- .../anticope/rejects/modules/TillAura.java | 225 ++++++++++++++++++ 5 files changed, 232 insertions(+), 8 deletions(-) create mode 100644 src/main/java/anticope/rejects/modules/TillAura.java diff --git a/README.md b/README.md index 8b42456..43417d7 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,7 @@ - SkeletonESP (Ported from [JexClient](https://github.com/DustinRepo/JexClient-main/blob/main/src/main/java/me/dustin/jex/feature/mod/impl/render/Skeletons.java)) - SoundLocator - Server Finder (Ported from [MeteorAdditions](https://github.com/JFronny/MeteorAdditions)) +- TillAura (Ported from [Wurst](https://github.com/Wurst-Imperium/Wurst7/tree)) - TreeAura (Taken from an [unmerged PR](https://github.com/MeteorDevelopment/meteor-client/pull/2138)) ### Modifications diff --git a/src/main/java/anticope/rejects/MeteorRejectsAddon.java b/src/main/java/anticope/rejects/MeteorRejectsAddon.java index d87671e..60fbb2e 100644 --- a/src/main/java/anticope/rejects/MeteorRejectsAddon.java +++ b/src/main/java/anticope/rejects/MeteorRejectsAddon.java @@ -69,6 +69,7 @@ public class MeteorRejectsAddon extends MeteorAddon { modules.add(new Rendering()); modules.add(new SkeletonESP()); modules.add(new SoundLocator()); + modules.add(new TillAura()); modules.add(new TreeAura()); // Module modifications diff --git a/src/main/java/anticope/rejects/modules/AutoSoup.java b/src/main/java/anticope/rejects/modules/AutoSoup.java index 7fcce7d..cc78b1d 100644 --- a/src/main/java/anticope/rejects/modules/AutoSoup.java +++ b/src/main/java/anticope/rejects/modules/AutoSoup.java @@ -24,7 +24,7 @@ import net.minecraft.util.hit.HitResult; import net.minecraft.util.math.BlockPos; public class AutoSoup extends Module { - private static final String desc = "Automatically eats soup when your health is low.\nNote: This hack ignores hunger and assumes that eating soup directly refills your health. If the server you are playing on is not configured to do that, use AutoEat instead."; + private static final String desc = "Automatically eats soup when your health is low. Note: This hack ignores hunger and assumes that eating soup directly refills your health. If the server you are playing on is not configured to do that, use AutoEat instead."; public AutoSoup() { super(MeteorRejectsAddon.CATEGORY, "auto-soup", desc); @@ -34,8 +34,7 @@ public class AutoSoup extends Module { public final Setting health = sgGeneral.add(new DoubleSetting.Builder() .name("health") - .description("Eats a soup when your health\n" - + "reaches this value or falls below it.") + .description("Eats a soup when your health reaches this value or falls below it.") .defaultValue(6.5) .min(0.5) .sliderMin(0.5) diff --git a/src/main/java/anticope/rejects/modules/ItemGenerator.java b/src/main/java/anticope/rejects/modules/ItemGenerator.java index 592fa77..7334536 100644 --- a/src/main/java/anticope/rejects/modules/ItemGenerator.java +++ b/src/main/java/anticope/rejects/modules/ItemGenerator.java @@ -19,8 +19,7 @@ public class ItemGenerator extends Module { private final SettingGroup sgGeneral = settings.getDefaultGroup(); private final Setting speed = sgGeneral.add(new IntSetting.Builder() .name("speed") - .description("WARNING: High speeds will cause a ton\n" - + "of lag and can easily crash the game!") + .description("WARNING: High speeds will cause a ton of lag and can easily crash the game!") .defaultValue(1) .min(1) .max(36) @@ -30,8 +29,7 @@ public class ItemGenerator extends Module { private final Setting stackSize = sgGeneral.add(new IntSetting.Builder() .name("stack-size") - .description("How many items to place in each stack.\n" - + "Doesn't seem to affect performance.") + .description("How many items to place in each stack. Doesn't seem to affect performance.") .defaultValue(1) .min(1) .max(64) @@ -42,7 +40,7 @@ public class ItemGenerator extends Module { private final Random random = Random.create(); public ItemGenerator() { - super(MeteorRejectsAddon.CATEGORY, "item-generator", "Generates random items and drops them on the ground.\nCreative mode only."); + super(MeteorRejectsAddon.CATEGORY, "item-generator", "Generates random items and drops them on the ground. Creative mode only."); } @Override diff --git a/src/main/java/anticope/rejects/modules/TillAura.java b/src/main/java/anticope/rejects/modules/TillAura.java new file mode 100644 index 0000000..70a3218 --- /dev/null +++ b/src/main/java/anticope/rejects/modules/TillAura.java @@ -0,0 +1,225 @@ +package anticope.rejects.modules; + +import anticope.rejects.MeteorRejectsAddon; +import meteordevelopment.meteorclient.events.world.TickEvent; +import meteordevelopment.meteorclient.mixin.MinecraftClientAccessor; +import meteordevelopment.meteorclient.settings.BoolSetting; +import meteordevelopment.meteorclient.settings.DoubleSetting; +import meteordevelopment.meteorclient.settings.Setting; +import meteordevelopment.meteorclient.settings.SettingGroup; +import meteordevelopment.meteorclient.systems.modules.Module; +import meteordevelopment.meteorclient.utils.player.Rotations; +import meteordevelopment.orbit.EventHandler; +import net.minecraft.block.Block; +import net.minecraft.block.Blocks; +import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.item.HoeItem; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Hand; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.hit.HitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.RaycastContext; +import net.minecraft.world.RaycastContext.FluidHandling; +import net.minecraft.world.RaycastContext.ShapeType; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; +import java.util.function.Predicate; +import java.util.stream.Collectors; + +public class TillAura extends Module { + private final SettingGroup sgGeneral = settings.getDefaultGroup(); + + private final Setting range = sgGeneral.add(new DoubleSetting.Builder() + .name("range") + .description("How far Tillaura will reach to till blocks.") + .defaultValue(5) + .min(0) + .build() + ); + + private final Setting multiTill = sgGeneral.add(new BoolSetting.Builder(). + name("multi-till") + .description("Tills multiple blocks at once. Faster, but can't bypass NoCheat+.") + .defaultValue(false) + .build() + ); + private final Setting checkLOS = sgGeneral.add(new BoolSetting.Builder(). + name("check-line-of-sight") + .description("Prevents Tillaura from reaching through blocks. Good for NoCheat+ servers, but unnecessary in vanilla.") + .defaultValue(true) + .build() + ); + + private final List tillableBlocks = Arrays.asList(Blocks.GRASS_BLOCK, + Blocks.DIRT_PATH, Blocks.DIRT, Blocks.COARSE_DIRT); + + public TillAura() { + super(MeteorRejectsAddon.CATEGORY, "till-aura", "Automatically turns dirt, grass, etc. into farmland."); + } + + @EventHandler + private void onTick(TickEvent.Post event) { + // wait for right click timer + if (((MinecraftClientAccessor) mc).getItemUseCooldown() > 0) + return; + + // check held item + ItemStack stack = mc.player.getInventory().getMainHandStack(); + if (stack.isEmpty() || !(stack.getItem() instanceof HoeItem)) + return; + + // get valid blocks + ArrayList validBlocks = + getValidBlocks(range.get(), this::isCorrectBlock); + + if (multiTill.get()) { + boolean shouldSwing = false; + + // till all valid blocks + for (BlockPos pos : validBlocks) + if (rightClickBlockSimple(pos)) + shouldSwing = true; + + // swing arm + if (shouldSwing) + mc.player.swingHand(Hand.MAIN_HAND); + } else + // till next valid block + for (BlockPos pos : validBlocks) + if (rightClickBlockLegit(pos)) + break; + } + + public static ArrayList getAllInBox(BlockPos from, BlockPos to) { + ArrayList blocks = new ArrayList<>(); + + BlockPos min = new BlockPos(Math.min(from.getX(), to.getX()), + Math.min(from.getY(), to.getY()), Math.min(from.getZ(), to.getZ())); + BlockPos max = new BlockPos(Math.max(from.getX(), to.getX()), + Math.max(from.getY(), to.getY()), Math.max(from.getZ(), to.getZ())); + + for (int x = min.getX(); x <= max.getX(); x++) + for (int y = min.getY(); y <= max.getY(); y++) + for (int z = min.getZ(); z <= max.getZ(); z++) + blocks.add(new BlockPos(x, y, z)); + + return blocks; + } + + public Vec3d getEyesPos() { + ClientPlayerEntity player = mc.player; + + return new Vec3d(player.getX(), + player.getY() + player.getEyeHeight(player.getPose()), + player.getZ()); + } + + private ArrayList getValidBlocks(double range, + Predicate validator) { + Vec3d eyesVec = getEyesPos().subtract(0.5, 0.5, 0.5); + double rangeSq = Math.pow(range + 0.5, 2); + int rangeI = (int) Math.ceil(range); + + BlockPos center = new BlockPos(getEyesPos()); + BlockPos min = center.add(-rangeI, -rangeI, -rangeI); + BlockPos max = center.add(rangeI, rangeI, rangeI); + + return getAllInBox(min, max).stream() + .filter(pos -> eyesVec.squaredDistanceTo(Vec3d.of(pos)) <= rangeSq) + .filter(validator) + .sorted(Comparator.comparingDouble( + pos -> eyesVec.squaredDistanceTo(Vec3d.of(pos)))) + .collect(Collectors.toCollection(ArrayList::new)); + } + + private boolean isCorrectBlock(BlockPos pos) { + if (!tillableBlocks.contains(mc.world.getBlockState(pos).getBlock())) + return false; + + return mc.world.getBlockState(pos.up()).isAir(); + } + + private boolean rightClickBlockLegit(BlockPos pos) { + Vec3d eyesPos = getEyesPos(); + Vec3d posVec = Vec3d.ofCenter(pos); + double distanceSqPosVec = eyesPos.squaredDistanceTo(posVec); + double rangeSq = Math.pow(range.get(), 2); + + for (Direction side : Direction.values()) { + Vec3d hitVec = posVec.add(Vec3d.of(side.getVector()).multiply(0.5)); + double distanceSqHitVec = eyesPos.squaredDistanceTo(hitVec); + + // check if hitVec is within range + if (distanceSqHitVec > rangeSq) + continue; + + // check if side is facing towards player + if (distanceSqHitVec >= distanceSqPosVec) + continue; + + if (checkLOS.get() && !hasLineOfSight(eyesPos, hitVec)) + continue; + + // face block + Rotations.rotate(Rotations.getYaw(hitVec), Rotations.getPitch(hitVec)); + + // right click block + rightClickBlock(pos, side, hitVec); + mc.player.swingHand(Hand.MAIN_HAND); + ((MinecraftClientAccessor) mc).setItemUseCooldown(4); + return true; + } + + return false; + } + + private void rightClickBlock(BlockPos pos, Direction side, Vec3d hitVec) { + mc.interactionManager.interactBlock(mc.player, Hand.MAIN_HAND, + new BlockHitResult(hitVec, side, pos, false)); + mc.interactionManager.interactItem(mc.player, Hand.MAIN_HAND); + } + + private boolean rightClickBlockSimple(BlockPos pos) { + Vec3d eyesPos = getEyesPos(); + Vec3d posVec = Vec3d.ofCenter(pos); + double distanceSqPosVec = eyesPos.squaredDistanceTo(posVec); + double rangeSq = Math.pow(range.get(), 2); + + for (Direction side : Direction.values()) { + Vec3d hitVec = posVec.add(Vec3d.of(side.getVector()).multiply(0.5)); + double distanceSqHitVec = eyesPos.squaredDistanceTo(hitVec); + + // check if hitVec is within range + if (distanceSqHitVec > rangeSq) + continue; + + // check if side is facing towards player + if (distanceSqHitVec >= distanceSqPosVec) + continue; + + if (checkLOS.get() && !hasLineOfSight(eyesPos, hitVec)) + continue; + + rightClickBlock(pos, side, hitVec); + return true; + } + + return false; + } + + private boolean hasLineOfSight(Vec3d from, Vec3d to) { + ShapeType type = RaycastContext.ShapeType.COLLIDER; + FluidHandling fluid = RaycastContext.FluidHandling.NONE; + + RaycastContext context = + new RaycastContext(from, to, type, fluid, mc.player); + + return mc.world.raycast(context).getType() == HitResult.Type.MISS; + } +}