From b8fc3c75b6514f6b26244e4117d1c3a94f9bb467 Mon Sep 17 00:00:00 2001 From: crazymoose77756 Date: Mon, 2 Sep 2024 12:05:55 -0400 Subject: [PATCH] AutoTorch --- README.md | 1 + .../anticope/rejects/MeteorRejectsAddon.java | 1 + .../anticope/rejects/modules/AutoFarm.java | 4 +- .../anticope/rejects/modules/AutoTorch.java | 75 +++++++++++++++++++ .../anticope/rejects/modules/MossBot.java | 2 +- .../anticope/rejects/utils/WorldUtils.java | 4 +- 6 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 src/main/java/anticope/rejects/modules/AutoTorch.java diff --git a/README.md b/README.md index eafb1c4a..5109fc50 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ - AutoLogin - AutoPot (Taken from an [unmerged PR](https://github.com/MeteorDevelopment/meteor-client/pull/274)) - AutoSoup (Ported from [Wurst](https://github.com/Wurst-Imperium/Wurst7/tree)) +- AutoTorch - AutoTNT - AutoWither (Taken from an [unmerged PR](https://github.com/MeteorDevelopment/meteor-client/pull/1070)) - BlockIn diff --git a/src/main/java/anticope/rejects/MeteorRejectsAddon.java b/src/main/java/anticope/rejects/MeteorRejectsAddon.java index 6098d03f..f5629906 100644 --- a/src/main/java/anticope/rejects/MeteorRejectsAddon.java +++ b/src/main/java/anticope/rejects/MeteorRejectsAddon.java @@ -43,6 +43,7 @@ public void onInitialize() { modules.add(new AutoLogin()); modules.add(new AutoPot()); modules.add(new AutoSoup()); + modules.add(new AutoTorch()); modules.add(new AutoTNT()); modules.add(new AutoWither()); modules.add(new BoatGlitch()); diff --git a/src/main/java/anticope/rejects/modules/AutoFarm.java b/src/main/java/anticope/rejects/modules/AutoFarm.java index 2109f2db..e4b36c66 100644 --- a/src/main/java/anticope/rejects/modules/AutoFarm.java +++ b/src/main/java/anticope/rejects/modules/AutoFarm.java @@ -192,7 +192,7 @@ private boolean till(BlockPos pos, Block block) { block == Blocks.ROOTED_DIRT; if (moist && tillable && mc.world.getBlockState(pos.up()).isAir()) { FindItemResult hoe = InvUtils.findInHotbar(itemStack -> itemStack.getItem() instanceof HoeItem); - return WorldUtils.interact(pos, hoe, rotate.get()); + return WorldUtils.interact(pos, hoe, rotate.get(), true); } return false; } @@ -245,7 +245,7 @@ private boolean bonemeal(BlockPos pos, BlockState state, Block block) { if (isMature(state, block)) return false; FindItemResult bonemeal = InvUtils.findInHotbar(Items.BONE_MEAL); - return WorldUtils.interact(pos, bonemeal, rotate.get()); + return WorldUtils.interact(pos, bonemeal, rotate.get(), true); } private boolean isWaterNearby(WorldView world, BlockPos pos) { diff --git a/src/main/java/anticope/rejects/modules/AutoTorch.java b/src/main/java/anticope/rejects/modules/AutoTorch.java new file mode 100644 index 00000000..edd3c476 --- /dev/null +++ b/src/main/java/anticope/rejects/modules/AutoTorch.java @@ -0,0 +1,75 @@ +package anticope.rejects.modules; + +import anticope.rejects.MeteorRejectsAddon; +import anticope.rejects.utils.WorldUtils; +import meteordevelopment.meteorclient.events.world.TickEvent; +import meteordevelopment.meteorclient.settings.*; +import meteordevelopment.meteorclient.systems.modules.Module; +import meteordevelopment.meteorclient.utils.player.ChatUtils; +import meteordevelopment.meteorclient.utils.player.FindItemResult; +import meteordevelopment.meteorclient.utils.player.InvUtils; +import meteordevelopment.orbit.EventHandler; +import net.minecraft.item.Item; +import net.minecraft.item.Items; +import net.minecraft.text.Text; +import net.minecraft.world.LightType; + +import java.util.List; + +//TODO: add setting for replaceable blocks +public class AutoTorch extends Module { + + private final SettingGroup sgGeneral = settings.getDefaultGroup(); + + private final Setting> torches = sgGeneral.add(new ItemListSetting.Builder() + .name("torch-type") + .description("The type of torches to use.") + .defaultValue(Items.TORCH) + .filter(this::torchFilter) + .build() + ); + + private final Setting lightLevel = sgGeneral.add(new IntSetting.Builder() + .name("light-level") + .description("At what light level and below to place torches.") + .defaultValue(7) + .min(0) + .sliderMax(15) + .build() + ); + + public AutoTorch() {super(MeteorRejectsAddon.CATEGORY, "auto-torch", "Automatically places torches where you stand.");} + + @EventHandler + private void onTick(TickEvent.Pre event) { + if (torches.get().isEmpty() || mc.player == null || mc.world == null) return; + + boolean torchFound = false; + + for (int i = 0; i < torches.get().size(); i++) { + FindItemResult findItemResult = InvUtils.findInHotbar(torches.get().get(i)); + + if (findItemResult.found()) { + torchFound = true; + + if (mc.world.getLightLevel(LightType.BLOCK, mc.player.getBlockPos()) <= lightLevel.get()) { + WorldUtils.interact(mc.player.getBlockPos(), findItemResult, false, false); + return; + } + } + } + + if (!torchFound) { + ChatUtils.sendMsg(Text.of("No torches found in hotbar.")); + toggle(); + } + } + + + private boolean torchFilter(Item item) { + return item == Items.TORCH || + item == Items.REDSTONE_TORCH || + item == Items.SOUL_TORCH; + } + +} diff --git a/src/main/java/anticope/rejects/modules/MossBot.java b/src/main/java/anticope/rejects/modules/MossBot.java index 83bfa1de..b8317459 100644 --- a/src/main/java/anticope/rejects/modules/MossBot.java +++ b/src/main/java/anticope/rejects/modules/MossBot.java @@ -67,7 +67,7 @@ private void onTick(TickEvent.Pre event) { mc.interactionManager.updateBlockBreakingProgress(bestBlock.up(), Direction.UP); } - WorldUtils.interact(bestBlock, findItemResult, rotate.get()); + WorldUtils.interact(bestBlock, findItemResult, rotate.get(), true); mossMap.put(bestBlock, 100); } } diff --git a/src/main/java/anticope/rejects/utils/WorldUtils.java b/src/main/java/anticope/rejects/utils/WorldUtils.java index 7d01c8f5..946a1484 100644 --- a/src/main/java/anticope/rejects/utils/WorldUtils.java +++ b/src/main/java/anticope/rejects/utils/WorldUtils.java @@ -38,14 +38,14 @@ public static double distanceBetween(BlockPos pos1, BlockPos pos2) { return MathHelper.sqrt((float) (d * d + e * e + f * f)); } - public static boolean interact(BlockPos pos, FindItemResult findItemResult, boolean rotate) { + public static boolean interact(BlockPos pos, FindItemResult findItemResult, boolean rotate, boolean swingHand) { if (!findItemResult.found()) return false; Runnable action = () -> { boolean wasSneaking = mc.player.input.sneaking; mc.player.input.sneaking = false; InvUtils.swap(findItemResult.slot(), true); mc.interactionManager.interactBlock(mc.player, Hand.MAIN_HAND, new BlockHitResult(Vec3d.ofCenter(pos), Direction.UP, pos, false)); - mc.player.swingHand(Hand.MAIN_HAND); + if (swingHand) {mc.player.swingHand(Hand.MAIN_HAND);} InvUtils.swapBack(); mc.player.input.sneaking = wasSneaking; };