Search in sources :

Example 6 with FindItemResult

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

the class Auto32K method onTick.

@EventHandler
private void onTick(TickEvent.Post event) {
    if (phase <= 7) {
        if (mode.get() == Mode.Hopper) {
            FindItemResult findShulker = InvUtils.findInHotbar(this::isShulkerBox);
            FindItemResult findHopper = InvUtils.findInHotbar(Items.HOPPER);
            if (isValidSlot(findShulker) || isValidSlot(findHopper))
                return;
            List<BlockPos> sortedBlocks = findValidBlocksHopper();
            sortedBlocks.sort(Comparator.comparingDouble(value -> mc.player.squaredDistanceTo(value.getX(), value.getY(), value.getZ())));
            Iterator<BlockPos> sortedIterator = sortedBlocks.iterator();
            BlockPos bestBlock = null;
            if (sortedIterator.hasNext())
                bestBlock = sortedIterator.next();
            if (bestBlock != null) {
                while (!BlockUtils.place(bestBlock, findHopper, true, 100, false)) {
                    if (sortedIterator.hasNext())
                        bestBlock = sortedIterator.next().up();
                    else
                        break;
                }
                mc.player.setSneaking(true);
                if (!BlockUtils.place(bestBlock.up(), findShulker, true, 100, false)) {
                    error("Failed to place.");
                    toggle();
                    return;
                }
                mc.player.setSneaking(false);
                mc.interactionManager.interactBlock(mc.player, mc.world, Hand.MAIN_HAND, new BlockHitResult(mc.player.getPos(), mc.player.getHorizontalFacing(), bestBlock.up(), false));
                phase = 8;
            }
        } else if (mode.get() == Mode.Dispenser) {
            FindItemResult shulkerSlot = InvUtils.find(this::isShulkerBox);
            FindItemResult hopperSlot = InvUtils.find(Items.HOPPER);
            FindItemResult dispenserSlot = InvUtils.find(Items.DISPENSER);
            FindItemResult redstoneSlot = InvUtils.find(Items.REDSTONE_BLOCK);
            if ((isValidSlot(shulkerSlot) && mode.get() == Mode.Hopper) || isValidSlot(hopperSlot) || isValidSlot(dispenserSlot) || isValidSlot(redstoneSlot))
                return;
            if (phase == 0) {
                bestBlock = findValidBlocksDispenser();
                if (bestBlock == null)
                    return;
                if (!BlockUtils.place(bestBlock.add(x, 0, z), hopperSlot, true, 100, false)) {
                    error("Failed to place.");
                    toggle();
                    return;
                }
                phase += 1;
            } else if (phase == 1) {
                mc.player.getInventory().selectedSlot = dispenserSlot.slot();
                if (x == -1)
                    mc.player.networkHandler.sendPacket(new PlayerMoveC2SPacket.LookAndOnGround(-90f, mc.player.getPitch(), mc.player.isOnGround()));
                else if (x == 1)
                    mc.player.networkHandler.sendPacket(new PlayerMoveC2SPacket.LookAndOnGround(90f, mc.player.getPitch(), mc.player.isOnGround()));
                else if (z == -1)
                    mc.player.networkHandler.sendPacket(new PlayerMoveC2SPacket.LookAndOnGround(1f, mc.player.getPitch(), mc.player.isOnGround()));
                else if (z == 1)
                    mc.player.networkHandler.sendPacket(new PlayerMoveC2SPacket.LookAndOnGround(179f, mc.player.getPitch(), mc.player.isOnGround()));
                phase += 1;
            } else if (phase == 2) {
                mc.interactionManager.interactBlock(mc.player, mc.world, Hand.MAIN_HAND, new BlockHitResult(mc.player.getPos(), Direction.UP, bestBlock, false));
                phase += 1;
            } else if (phase == 3) {
                mc.interactionManager.interactBlock(mc.player, mc.world, Hand.MAIN_HAND, new BlockHitResult(mc.player.getPos(), mc.player.getHorizontalFacing().getOpposite(), bestBlock.up(), false));
                phase += 1;
            } else if (phase == 4 && mc.currentScreen instanceof Generic3x3ContainerScreen) {
                mc.player.getMovementSpeed();
                InvUtils.move().from(shulkerSlot.slot()).toId(4);
                phase += 1;
            } else if (phase == 5 && mc.currentScreen instanceof Generic3x3ContainerScreen) {
                mc.player.closeHandledScreen();
                phase += 1;
            } else if (phase == 6) {
                mc.player.getInventory().selectedSlot = redstoneSlot.slot();
                mc.player.setSneaking(true);
                mc.interactionManager.interactBlock(mc.player, mc.world, Hand.MAIN_HAND, new BlockHitResult(mc.player.getPos(), mc.player.getHorizontalFacing().getOpposite(), bestBlock.up(2), false));
                mc.player.setSneaking(false);
                phase += 1;
            } else if (phase == 7) {
                mc.interactionManager.interactBlock(mc.player, mc.world, Hand.MAIN_HAND, new BlockHitResult(mc.player.getPos(), mc.player.getHorizontalFacing().getOpposite(), bestBlock.add(x, 0, z), false));
                phase += 1;
            }
        }
    } else if (phase == 8) {
        if (mc.currentScreen instanceof HopperScreen) {
            if (fillHopper.get() && !throwawayItems.get().isEmpty()) {
                int slot = -1;
                int count = 0;
                Iterator<Block> blocks = throwawayItems.get().iterator();
                for (Item item = blocks.next().asItem(); blocks.hasNext(); item = blocks.next().asItem()) {
                    for (int i = 5; i <= 40; i++) {
                        ItemStack stack = mc.player.getInventory().getStack(i);
                        if (stack.getItem() == item && stack.getCount() >= 4) {
                            slot = i;
                            count = stack.getCount();
                            break;
                        }
                    }
                    if (count >= 4)
                        break;
                }
                for (int i = 1; i < 5; i++) {
                    if (mc.player.currentScreenHandler.getSlot(i).getStack().getItem() instanceof AirBlockItem)
                        InvUtils.move().from(slot - 4).toId(i);
                }
            }
            boolean manage = true;
            int slot = -1;
            int dropSlot = -1;
            for (int i = 32; i < 41; i++) {
                if (EnchantmentHelper.getLevel(Enchantments.SHARPNESS, mc.player.currentScreenHandler.getSlot(i).getStack()) > 5) {
                    manage = false;
                    slot = i;
                    break;
                } else if (mc.player.currentScreenHandler.getSlot(i).getStack().getItem() instanceof SwordItem && EnchantmentHelper.getLevel(Enchantments.SHARPNESS, mc.player.currentScreenHandler.getSlot(i).getStack()) <= 5) {
                    dropSlot = i;
                }
            }
            if (dropSlot != -1)
                InvUtils.drop().slot(dropSlot);
            if (autoMove.get() && manage) {
                int slot2 = mc.player.getInventory().getEmptySlot();
                if (slot2 < 9 && slot2 != -1 && EnchantmentHelper.getLevel(Enchantments.SHARPNESS, mc.player.currentScreenHandler.getSlot(0).getStack()) > 5)
                    InvUtils.move().fromId(0).to(slot2 - 4);
                else if (EnchantmentHelper.getLevel(Enchantments.SHARPNESS, mc.player.currentScreenHandler.getSlot(0).getStack()) <= 5 && mc.player.currentScreenHandler.getSlot(0).getStack().getItem() != Items.AIR)
                    InvUtils.drop().slotId(0);
            }
            if (slot != -1)
                mc.player.getInventory().selectedSlot = slot - 32;
        } else
            toggle();
    }
}
Also used : BlockUtils(mathax.client.utils.world.BlockUtils) EventHandler(mathax.client.eventbus.EventHandler) ArrayList(java.util.ArrayList) Direction(net.minecraft.util.math.Direction) TickEvent(mathax.client.events.world.TickEvent) Block(net.minecraft.block.Block) Generic3x3ContainerScreen(net.minecraft.client.gui.screen.ingame.Generic3x3ContainerScreen) Enchantments(net.minecraft.enchantment.Enchantments) Hand(net.minecraft.util.Hand) Module(mathax.client.systems.modules.Module) mathax.client.settings(mathax.client.settings) Iterator(java.util.Iterator) Box(net.minecraft.util.math.Box) BlockHitResult(net.minecraft.util.hit.BlockHitResult) HopperScreen(net.minecraft.client.gui.screen.ingame.HopperScreen) net.minecraft.item(net.minecraft.item) BlockPos(net.minecraft.util.math.BlockPos) Blocks(net.minecraft.block.Blocks) EnchantmentHelper(net.minecraft.enchantment.EnchantmentHelper) InvUtils(mathax.client.utils.player.InvUtils) List(java.util.List) FindItemResult(mathax.client.utils.player.FindItemResult) ShulkerBoxBlock(net.minecraft.block.ShulkerBoxBlock) Categories(mathax.client.systems.modules.Categories) PlayerMoveC2SPacket(net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket) Comparator(java.util.Comparator) Generic3x3ContainerScreen(net.minecraft.client.gui.screen.ingame.Generic3x3ContainerScreen) PlayerMoveC2SPacket(net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket) FindItemResult(mathax.client.utils.player.FindItemResult) Iterator(java.util.Iterator) HopperScreen(net.minecraft.client.gui.screen.ingame.HopperScreen) BlockPos(net.minecraft.util.math.BlockPos) BlockHitResult(net.minecraft.util.hit.BlockHitResult) EventHandler(mathax.client.eventbus.EventHandler)

Example 7 with FindItemResult

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

the class AutoAnvil method onTick.

@EventHandler
private void onTick(TickEvent.Pre event) {
    if (toggleOnBreak.get() && target != null && target.getInventory().getArmorStack(3).isEmpty()) {
        error("Target head slot is empty, disabling...");
        toggle();
        return;
    }
    if (TargetUtils.isBadTarget(target, range.get()))
        target = TargetUtils.getPlayerTarget(range.get(), priority.get());
    if (TargetUtils.isBadTarget(target, range.get()))
        return;
    if (placeButton.get()) {
        FindItemResult floorBlock = InvUtils.findInHotbar(itemStack -> Block.getBlockFromItem(itemStack.getItem()) instanceof AbstractPressurePlateBlock || Block.getBlockFromItem(itemStack.getItem()) instanceof AbstractButtonBlock);
        BlockUtils.place(target.getBlockPos(), floorBlock, rotate.get(), 0, false);
    }
    if (timer >= delay.get()) {
        timer = 0;
        FindItemResult anvil = InvUtils.findInHotbar(itemStack -> Block.getBlockFromItem(itemStack.getItem()) instanceof AnvilBlock);
        if (!anvil.found())
            return;
        for (int i = height.get(); i > 1; i--) {
            BlockPos blockPos = target.getBlockPos().up().add(0, i, 0);
            for (int j = 0; j < i; j++) {
                if (!mc.world.getBlockState(target.getBlockPos().up(j + 1)).getMaterial().isReplaceable())
                    break;
            }
            if (BlockUtils.place(blockPos, anvil, rotate.get(), 0) && !multiPlace.get())
                break;
        }
    } else
        timer++;
}
Also used : AbstractPressurePlateBlock(net.minecraft.block.AbstractPressurePlateBlock) AbstractButtonBlock(net.minecraft.block.AbstractButtonBlock) AnvilBlock(net.minecraft.block.AnvilBlock) FindItemResult(mathax.client.utils.player.FindItemResult) BlockPos(net.minecraft.util.math.BlockPos) EventHandler(mathax.client.eventbus.EventHandler)

Example 8 with FindItemResult

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

the class AutoCity method onTick.

@EventHandler
private void onTick(TickEvent.Pre event) {
    if (TargetUtils.isBadTarget(target, targetRange.get())) {
        PlayerEntity search = TargetUtils.getPlayerTarget(targetRange.get(), SortPriority.Lowest_Distance);
        if (search != target)
            sentMessage = false;
        target = search;
    }
    if (TargetUtils.isBadTarget(target, targetRange.get())) {
        target = null;
        mineTarget = null;
        if (selfToggle.get())
            toggle();
        return;
    }
    mineTarget = EntityUtils.getCityBlock(target);
    if (mineTarget == null) {
        if (selfToggle.get()) {
            error("No target block found, disabling...");
            toggle();
        }
        target = null;
        return;
    }
    if (selfToggle.get() && PlayerUtils.distanceTo(mineTarget) > mc.interactionManager.getReachDistance()) {
        error("Target block out of reach, disabling...");
        toggle();
        return;
    }
    if (!sentMessage) {
        info("Attempting to city (highlight)%s(default).", target.getEntityName());
        sentMessage = true;
    }
    FindItemResult pickaxe = InvUtils.find(itemStack -> itemStack.getItem() == Items.DIAMOND_PICKAXE || itemStack.getItem() == Items.NETHERITE_PICKAXE);
    if (!pickaxe.isHotbar()) {
        if (selfToggle.get()) {
            error("No pickaxe found, disabling...");
            toggle();
        }
        return;
    }
    if (support.get())
        BlockUtils.place(mineTarget.down(1), InvUtils.findInHotbar(Items.OBSIDIAN), rotate.get(), 0, true);
    InvUtils.swap(pickaxe.slot(), false);
    if (rotate.get())
        Rotations.rotate(Rotations.getYaw(mineTarget), Rotations.getPitch(mineTarget), () -> mine(mineTarget));
    else
        mine(mineTarget);
    if (selfToggle.get())
        toggle();
}
Also used : FindItemResult(mathax.client.utils.player.FindItemResult) PlayerEntity(net.minecraft.entity.player.PlayerEntity) EventHandler(mathax.client.eventbus.EventHandler)

Example 9 with FindItemResult

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

the class AutoWither method onPostTick.

@EventHandler
private void onPostTick(TickEvent.Post event) {
    if (wither == null) {
        // Delay
        if (witherTicksWaited < witherDelay.get() - 1) {
            witherTicksWaited++;
            return;
        }
        if (withers.isEmpty())
            return;
        // Sorting
        switch(priority.get()) {
            case Closest:
                withers.sort(Comparator.comparingDouble(w -> PlayerUtils.distanceTo(w.foot)));
            case Furthest:
                withers.sort((w1, w2) -> {
                    int sort = Double.compare(PlayerUtils.distanceTo(w1.foot), PlayerUtils.distanceTo(w2.foot));
                    if (sort == 0)
                        return 0;
                    return sort > 0 ? -1 : 1;
                });
            case Random:
                Collections.shuffle(withers);
        }
        wither = withers.get(0);
    }
    // Soul sand/soil and skull slot
    FindItemResult findSoulSand = InvUtils.findInHotbar(Items.SOUL_SAND);
    if (!findSoulSand.found())
        findSoulSand = InvUtils.findInHotbar(Items.SOUL_SOIL);
    FindItemResult findWitherSkull = InvUtils.findInHotbar(Items.WITHER_SKELETON_SKULL);
    // Check for enough resources
    if (!findSoulSand.found() || !findWitherSkull.found()) {
        error("Not enough resources in hotbar");
        toggle();
        return;
    }
    // Build
    if (blockDelay.get() == 0) {
        // All in 1 tick
        // Body
        BlockUtils.place(wither.foot, findSoulSand, rotate.get(), -50);
        BlockUtils.place(wither.foot.up(), findSoulSand, rotate.get(), -50);
        BlockUtils.place(wither.foot.up().offset(wither.axis, -1), findSoulSand, rotate.get(), -50);
        BlockUtils.place(wither.foot.up().offset(wither.axis, 1), findSoulSand, rotate.get(), -50);
        // Head
        BlockUtils.place(wither.foot.up().up(), findWitherSkull, rotate.get(), -50);
        BlockUtils.place(wither.foot.up().up().offset(wither.axis, -1), findWitherSkull, rotate.get(), -50);
        BlockUtils.place(wither.foot.up().up().offset(wither.axis, 1), findWitherSkull, rotate.get(), -50);
        // Auto turnoff
        if (turnOff.get()) {
            wither = null;
            toggle();
        }
    } else {
        // Delay
        if (blockTicksWaited < blockDelay.get() - 1) {
            blockTicksWaited++;
            return;
        }
        switch(wither.stage) {
            case 0:
                if (BlockUtils.place(wither.foot, findSoulSand, rotate.get(), -50))
                    wither.stage++;
                break;
            case 1:
                if (BlockUtils.place(wither.foot.up(), findSoulSand, rotate.get(), -50))
                    wither.stage++;
                break;
            case 2:
                if (BlockUtils.place(wither.foot.up().offset(wither.axis, -1), findSoulSand, rotate.get(), -50))
                    wither.stage++;
                break;
            case 3:
                if (BlockUtils.place(wither.foot.up().offset(wither.axis, 1), findSoulSand, rotate.get(), -50))
                    wither.stage++;
                break;
            case 4:
                if (BlockUtils.place(wither.foot.up().up(), findWitherSkull, rotate.get(), -50))
                    wither.stage++;
                break;
            case 5:
                if (BlockUtils.place(wither.foot.up().up().offset(wither.axis, -1), findWitherSkull, rotate.get(), -50))
                    wither.stage++;
                break;
            case 6:
                if (BlockUtils.place(wither.foot.up().up().offset(wither.axis, 1), findWitherSkull, rotate.get(), -50))
                    wither.stage++;
                break;
            case 7:
                // Auto turnoff
                if (turnOff.get()) {
                    wither = null;
                    toggle();
                }
                break;
        }
    }
    witherTicksWaited = 0;
}
Also used : MatHax(mathax.client.MatHax) ShapeContext(net.minecraft.block.ShapeContext) BlockIterator(mathax.client.utils.world.BlockIterator) PlayerUtils(mathax.client.utils.player.PlayerUtils) SettingColor(mathax.client.utils.render.color.SettingColor) BlockPos(net.minecraft.util.math.BlockPos) Items(net.minecraft.item.Items) BlockUtils(mathax.client.utils.world.BlockUtils) ShapeMode(mathax.client.renderer.ShapeMode) Blocks(net.minecraft.block.Blocks) EventHandler(mathax.client.eventbus.EventHandler) ArrayList(java.util.ArrayList) Direction(net.minecraft.util.math.Direction) InvUtils(mathax.client.utils.player.InvUtils) TickEvent(mathax.client.events.world.TickEvent) FindItemResult(mathax.client.utils.player.FindItemResult) Categories(mathax.client.systems.modules.Categories) Render3DEvent(mathax.client.events.render.Render3DEvent) Module(mathax.client.systems.modules.Module) Comparator(java.util.Comparator) Collections(java.util.Collections) Pool(mathax.client.utils.misc.Pool) mathax.client.settings(mathax.client.settings) Rotations(mathax.client.utils.player.Rotations) FindItemResult(mathax.client.utils.player.FindItemResult) EventHandler(mathax.client.eventbus.EventHandler)

Example 10 with FindItemResult

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

the class SpawnProofer method onTickPost.

@EventHandler
private void onTickPost(TickEvent.Post event) {
    if (delay.get() != 0 && ticksWaited < delay.get() - 1) {
        ticksWaited++;
        return;
    }
    if (spawns.isEmpty())
        return;
    FindItemResult block = InvUtils.findInHotbar(itemStack -> blocks.get().contains(Block.getBlockFromItem(itemStack.getItem())));
    if (delay.get() == 0)
        for (BlockPos blockPos : spawns) BlockUtils.place(blockPos, block, rotate.get(), -50, false);
    else {
        if (isLightSource(Block.getBlockFromItem(mc.player.getInventory().getStack(block.slot()).getItem()))) {
            int lowestLightLevel = 16;
            BlockPos.Mutable selectedBlockPos = spawns.get(0);
            for (BlockPos blockPos : spawns) {
                int lightLevel = mc.world.getLightLevel(blockPos);
                if (lightLevel < lowestLightLevel) {
                    lowestLightLevel = lightLevel;
                    selectedBlockPos.set(blockPos);
                }
            }
            BlockUtils.place(selectedBlockPos, block, rotate.get(), -50, false);
        } else
            BlockUtils.place(spawns.get(0), block, rotate.get(), -50, false);
    }
    ticksWaited = 0;
}
Also used : FindItemResult(mathax.client.utils.player.FindItemResult) BlockPos(net.minecraft.util.math.BlockPos) EventHandler(mathax.client.eventbus.EventHandler)

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