From 5a7f7b4c2504e9cb97e59fec1ca3e7f1501230d5 Mon Sep 17 00:00:00 2001 From: ThebestkillerTBK <2593828650@qq.com> Date: Thu, 13 Oct 2022 16:46:41 +0800 Subject: [PATCH] Auto Soup --- README.md | 1 + .../anticope/rejects/MeteorRejectsAddon.java | 1 + .../anticope/rejects/modules/AutoSoup.java | 167 ++++++++++++++++++ .../rejects/modules/ItemGenerator.java | 4 +- 4 files changed, 171 insertions(+), 2 deletions(-) create mode 100644 src/main/java/anticope/rejects/modules/AutoSoup.java diff --git a/README.md b/README.md index 665dd0b..8b42456 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ - AutoCraft (More generalized version of [AutoBedCraft](https://github.com/Anticope/orion/blob/main/src/main/java/me/ghosttypes/orion/modules/main/AutoBedCraft.java) from orion) - AutoExtinguish - 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)) - 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 cdd43e4..d87671e 100644 --- a/src/main/java/anticope/rejects/MeteorRejectsAddon.java +++ b/src/main/java/anticope/rejects/MeteorRejectsAddon.java @@ -39,6 +39,7 @@ public class MeteorRejectsAddon extends MeteorAddon { modules.add(new AutoCraft()); modules.add(new AutoExtinguish()); modules.add(new AutoPot()); + modules.add(new AutoSoup()); modules.add(new AutoTNT()); modules.add(new AutoWither()); modules.add(new BoatGlitch()); diff --git a/src/main/java/anticope/rejects/modules/AutoSoup.java b/src/main/java/anticope/rejects/modules/AutoSoup.java new file mode 100644 index 0000000..7fcce7d --- /dev/null +++ b/src/main/java/anticope/rejects/modules/AutoSoup.java @@ -0,0 +1,167 @@ +package anticope.rejects.modules; + +import anticope.rejects.MeteorRejectsAddon; +import meteordevelopment.meteorclient.events.world.TickEvent; +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.InvUtils; +import meteordevelopment.orbit.EventHandler; +import net.minecraft.block.Block; +import net.minecraft.block.BlockWithEntity; +import net.minecraft.block.CraftingTableBlock; +import net.minecraft.entity.Entity; +import net.minecraft.entity.passive.TameableEntity; +import net.minecraft.entity.passive.VillagerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +import net.minecraft.item.StewItem; +import net.minecraft.util.Hand; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.hit.EntityHitResult; +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."; + + public AutoSoup() { + super(MeteorRejectsAddon.CATEGORY, "auto-soup", desc); + } + + private final SettingGroup sgGeneral = settings.getDefaultGroup(); + + 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.") + .defaultValue(6.5) + .min(0.5) + .sliderMin(0.5) + .sliderMax(9.5) + .build() + ); + + private int oldSlot = -1; + + @Override + public void onDeactivate() { + stopIfEating(); + } + + @EventHandler + private void onTick(TickEvent.Post event) { + // sort empty bowls + for (int i = 0; i < 36; i++) { + // filter out non-bowl items and empty bowl slot + ItemStack stack = mc.player.getInventory().getStack(i); + if (stack == null || stack.getItem() != Items.BOWL || i == 9) + continue; + + // check if empty bowl slot contains a non-bowl item + ItemStack emptyBowlStack = mc.player.getInventory().getStack(9); + boolean swap = !emptyBowlStack.isEmpty() + && emptyBowlStack.getItem() != Items.BOWL; + + // place bowl in empty bowl slot + InvUtils.click().slot(i < 9 ? 36 + i : i); + InvUtils.click().slot(9); + + // place non-bowl item from empty bowl slot in current slot + if (swap) + InvUtils.click().slot(i < 9 ? 36 + i : i); + } + + // search soup in hotbar + int soupInHotbar = findSoup(0, 9); + + // check if any soup was found + if (soupInHotbar != -1) { + // check if player should eat soup + if (!shouldEatSoup()) { + stopIfEating(); + return; + } + + // save old slot + if (oldSlot == -1) + oldSlot = mc.player.getInventory().selectedSlot; + + // set slot + mc.player.getInventory().selectedSlot = soupInHotbar; + + // eat soup + mc.options.useKey.setPressed(true); + mc.interactionManager.interactItem(mc.player, Hand.MAIN_HAND); + + return; + } + + stopIfEating(); + + // search soup in inventory + int soupInInventory = findSoup(9, 36); + + // move soup in inventory to hotbar + if (soupInInventory != -1) + InvUtils.quickMove().slot(soupInInventory); + } + + private int findSoup(int startSlot, int endSlot) { + for (int i = startSlot; i < endSlot; i++) { + ItemStack stack = mc.player.getInventory().getStack(i); + + if (stack != null && stack.getItem() instanceof StewItem) + return i; + } + + return -1; + } + + private boolean shouldEatSoup() { + // check health + if (mc.player.getHealth() > health.get() * 2F) + return false; + + // check for clickable objects + return !isClickable(mc.crosshairTarget); + } + + private boolean isClickable(HitResult hitResult) { + if (hitResult == null) + return false; + + if (hitResult instanceof EntityHitResult) { + Entity entity = ((EntityHitResult) mc.crosshairTarget).getEntity(); + return entity instanceof VillagerEntity + || entity instanceof TameableEntity; + } + + if (hitResult instanceof BlockHitResult) { + BlockPos pos = ((BlockHitResult) mc.crosshairTarget).getBlockPos(); + if (pos == null) + return false; + + Block block = mc.world.getBlockState(pos).getBlock(); + return block instanceof BlockWithEntity + || block instanceof CraftingTableBlock; + } + + return false; + } + + private void stopIfEating() { + // check if eating + if (oldSlot == -1) + return; + + // stop eating + mc.options.useKey.setPressed(false); + + // reset slot + mc.player.getInventory().selectedSlot = oldSlot; + oldSlot = -1; + } + +} diff --git a/src/main/java/anticope/rejects/modules/ItemGenerator.java b/src/main/java/anticope/rejects/modules/ItemGenerator.java index 1b47a83..592fa77 100644 --- a/src/main/java/anticope/rejects/modules/ItemGenerator.java +++ b/src/main/java/anticope/rejects/modules/ItemGenerator.java @@ -19,7 +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("\u00a74\u00a7lWARNING:\u00a7r High speeds will cause a ton\n" + .description("WARNING: High speeds will cause a ton\n" + "of lag and can easily crash the game!") .defaultValue(1) .min(1) @@ -42,7 +42,7 @@ public class ItemGenerator extends Module { private final Random random = Random.create(); public ItemGenerator() { - super(MeteorRejectsAddon.CATEGORY, "item-generator", "Spawns a lot of unwanted items"); + super(MeteorRejectsAddon.CATEGORY, "item-generator", "Generates random items and drops them on the ground.\nCreative mode only."); } @Override