Search in sources :

Example 1 with FindItemResult

use of mathax.client.utils.player.FindItemResult in project Client by MatHax.

the class TNTAura method onTick.

@EventHandler
private void onTick(TickEvent.Pre event) {
    FindItemResult obsidian = InvUtils.findInHotbar(Items.OBSIDIAN);
    if (!obsidian.isHotbar() && !toggled) {
        obsidianPos.clear();
        error("No obsidian found, disabling...");
        toggle();
        toggled = true;
    }
    FindItemResult flint = InvUtils.findInHotbar(Items.FLINT_AND_STEEL);
    if (!flint.isHotbar() && !toggled) {
        obsidianPos.clear();
        error("No flint and steel found, disabling...");
        toggle();
        toggled = true;
    }
    FindItemResult tnt = InvUtils.findInHotbar(Items.TNT);
    if (!tnt.isHotbar() && !toggled) {
        obsidianPos.clear();
        error("No TNT found, disabling...");
        toggle();
        toggled = true;
    }
    FindItemResult pickaxe = InvUtils.find(itemStack -> itemStack.getItem() == Items.DIAMOND_PICKAXE || itemStack.getItem() == Items.NETHERITE_PICKAXE);
    if (!pickaxe.isHotbar() && !toggled) {
        obsidianPos.clear();
        error("No pickaxe found, disabling...");
        toggle();
        toggled = true;
    }
    if (TargetUtils.isBadTarget(target, range.get()))
        target = TargetUtils.getPlayerTarget(range.get(), SortPriority.Lowest_Distance);
    if (target == null)
        return;
    if (burrowPause.get() && isBurrowed(target) && !toggled) {
        obsidianPos.clear();
        error("Target is burrowed, disabling...");
        toggle();
        toggled = true;
    }
    if (antiSelf.get() && antiSelf(target) && !toggled) {
        obsidianPos.clear();
        error("Target is in your hole!");
        toggle();
        toggled = true;
    }
    if (holePause.get() && !isSurrounded(target) && !toggled) {
        obsidianPos.clear();
        error("Target isn't surrounded, disabling...");
        toggle();
        toggled = true;
    }
    if (TargetUtils.isBadTarget(target, range.get()) && !toggled) {
        error("Enemy is too far, disabling...");
        toggle();
        toggled = true;
    }
    if (PlayerUtils.shouldPause(pauseOnMine.get(), pauseOnEat.get(), pauseOnDrink.get()))
        return;
    if (allowTNT(target)) {
        placeTNT(target);
        igniteTNT(target.getBlockPos().up(2), flint);
    }
    if (!mineBlockstate(target.getBlockPos().up(2)) && autoBreak.get())
        mine(target.getBlockPos().up(2), pickaxe);
    placeObsidian(target);
    if (ticks >= delay.get() && obsidianPos.size() > 0) {
        BlockPos blockPos = obsidianPos.get(obsidianPos.size() - 1);
        if (BlockUtils.place(blockPos, obsidian, rotate.get(), 50, true))
            obsidianPos.remove(blockPos);
        ticks = 0;
    } else
        ticks++;
}
Also used : FindItemResult(mathax.client.utils.player.FindItemResult) BlockPos(net.minecraft.util.math.BlockPos) EventHandler(mathax.client.eventbus.EventHandler)

Example 2 with FindItemResult

use of mathax.client.utils.player.FindItemResult in project Client by MatHax.

the class BookBot method onTick.

@EventHandler
private void onTick(TickEvent.Post event) {
    FindItemResult writableBook = InvUtils.find(Items.WRITABLE_BOOK);
    // Check if there is a book to write
    if (!writableBook.found()) {
        toggle();
        return;
    }
    // Move the book into hand
    if (!writableBook.isMainHand()) {
        InvUtils.move().from(writableBook.slot()).toHotbar(mc.player.getInventory().selectedSlot);
        return;
    }
    // If somehow it failed, just dont do anything until it tries again
    FindItemResult finalBook = InvUtils.findInHotbar(Items.WRITABLE_BOOK);
    if (!finalBook.isMainHand())
        return;
    // Check delay
    if (delayTimer > 0) {
        delayTimer--;
        return;
    }
    // Reset delay
    delayTimer = delay.get();
    if (mode.get() == Mode.Random) {
        int origin = onlyAscii.get() ? 0x21 : 0x0800;
        int bound = onlyAscii.get() ? 0x7E : 0x10FFFF;
        writeBook(// Generate a random load of ints to use as random characters
        random.ints(origin, bound).filter(i -> !Character.isWhitespace(i) && i != '\r' && i != '\n').iterator());
    } else if (mode.get() == Mode.File) {
        // Ignore if somehow the file got deleted
        if ((file == null || !file.exists()) && mode.get() == Mode.File) {
            info("No file selected, please select a file in the GUI.");
            toggle();
            return;
        }
        // Handle the file being empty
        if (file.length() == 0) {
            MutableText message = new LiteralText("");
            message.append(new LiteralText("The bookbot file is empty! ").formatted(Formatting.RED));
            message.append(new LiteralText("Click here to edit it.").setStyle(Style.EMPTY.withFormatting(Formatting.UNDERLINE, Formatting.RED).withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, file.getAbsolutePath()))));
            info(message);
            toggle();
            return;
        }
        // Read each line of the file and construct a string with the needed line breaks
        try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
            StringBuilder file = new StringBuilder();
            String line;
            while ((line = reader.readLine()) != null) {
                file.append(line).append('\n');
            }
            reader.close();
            // Write the file string to a book
            writeBook(file.toString().chars().iterator());
        } catch (IOException ignored) {
            error("Failed to read the file.");
        }
    }
}
Also used : MutableText(net.minecraft.text.MutableText) ClickEvent(net.minecraft.text.ClickEvent) FindItemResult(mathax.client.utils.player.FindItemResult) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) NbtString(net.minecraft.nbt.NbtString) IOException(java.io.IOException) LiteralText(net.minecraft.text.LiteralText) EventHandler(mathax.client.eventbus.EventHandler)

Example 3 with FindItemResult

use of mathax.client.utils.player.FindItemResult in project Client by MatHax.

the class SelfWeb method placeWeb.

private void placeWeb() {
    FindItemResult web = InvUtils.findInHotbar(Items.COBWEB);
    BlockUtils.place(mc.player.getBlockPos(), web, rotate.get(), 0, swing.get(), false);
    if (doubles.get())
        BlockUtils.place(mc.player.getBlockPos().add(0, 1, 0), web, rotate.get(), 0, swing.get(), false);
    if (turnOff.get())
        toggle();
}
Also used : FindItemResult(mathax.client.utils.player.FindItemResult)

Example 4 with FindItemResult

use of mathax.client.utils.player.FindItemResult in project Client by MatHax.

the class SurroundBreak method onTick.

@EventHandler(priority = EventPriority.MEDIUM + 60)
private void onTick(TickEvent.Pre event) {
    CrystalAura crystalAura = Modules.get().get(CrystalAura.class);
    if (crystalAura.isActive())
        target = crystalAura.getPlayerTarget();
    if (target == null || !crystalAura.isActive())
        return;
    FindItemResult crystal = InvUtils.findInHotbar(Items.END_CRYSTAL);
    if (!crystal.found())
        return;
    if (!PlayerUtils.isSurrounded(target))
        return;
    placePositions.clear();
    findPlacePos(target);
    if (delay >= delaySetting.get() && placePositions.size() > 0) {
        BlockPos blockPos = placePositions.get(placePositions.size() - 1);
        if (PlayerUtils.distanceTo(blockPos) > placeRange.get())
            return;
        if (BlockUtils.place(blockPos, crystal, rotate.get(), 50, swing.get(), checkEntity.get(), swapBack.get()))
            placePositions.remove(blockPos);
        delay = 0;
    } else
        delay++;
    if (renderTimer > 0)
        renderTimer--;
    renderTimer = renderTime.get();
}
Also used : FindItemResult(mathax.client.utils.player.FindItemResult) BlockPos(net.minecraft.util.math.BlockPos) EventHandler(mathax.client.eventbus.EventHandler)

Example 5 with FindItemResult

use of mathax.client.utils.player.FindItemResult in project Client by MatHax.

the class TNTAura method placeTNT.

private void placeTNT(PlayerEntity target) {
    FindItemResult tnt = InvUtils.findInHotbar(Items.TNT);
    BlockPos targetPos = target.getBlockPos();
    BlockUtils.place(targetPos.add(0, 2, 0), tnt, rotate.get(), 50, true, true);
}
Also used : FindItemResult(mathax.client.utils.player.FindItemResult) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

FindItemResult (mathax.client.utils.player.FindItemResult)30 EventHandler (mathax.client.eventbus.EventHandler)21 BlockPos (net.minecraft.util.math.BlockPos)13 InvUtils (mathax.client.utils.player.InvUtils)5 ItemStack (net.minecraft.item.ItemStack)5 ArrayList (java.util.ArrayList)4 TickEvent (mathax.client.events.world.TickEvent)4 Categories (mathax.client.systems.modules.Categories)4 Module (mathax.client.systems.modules.Module)4 mathax.client.settings (mathax.client.settings)3 PlayerUtils (mathax.client.utils.player.PlayerUtils)3 BlockUtils (mathax.client.utils.world.BlockUtils)3 Block (net.minecraft.block.Block)3 Blocks (net.minecraft.block.Blocks)3 BlockItem (net.minecraft.item.BlockItem)3 Items (net.minecraft.item.Items)3 Direction (net.minecraft.util.math.Direction)3 Comparator (java.util.Comparator)2 List (java.util.List)2 MatHax (mathax.client.MatHax)2