Search in sources :

Example 26 with FindItemResult

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

the class AutoShearer method onTick.

@EventHandler
private void onTick(TickEvent.Pre event) {
    entity = null;
    for (Entity entity : mc.world.getEntities()) {
        if (!(entity instanceof SheepEntity) || ((SheepEntity) entity).isSheared() || ((SheepEntity) entity).isBaby() || mc.player.distanceTo(entity) > distance.get())
            continue;
        boolean findNewShears = false;
        if (mc.player.getInventory().getMainHandStack().getItem() instanceof ShearsItem) {
            if (antiBreak.get() && mc.player.getInventory().getMainHandStack().getDamage() >= mc.player.getInventory().getMainHandStack().getMaxDamage() - 1)
                findNewShears = true;
        } else if (mc.player.getInventory().offHand.get(0).getItem() instanceof ShearsItem) {
            if (antiBreak.get() && mc.player.getInventory().offHand.get(0).getDamage() >= mc.player.getInventory().offHand.get(0).getMaxDamage() - 1)
                findNewShears = true;
            else
                offHand = true;
        } else {
            findNewShears = true;
        }
        boolean foundShears = !findNewShears;
        if (findNewShears) {
            FindItemResult shears = InvUtils.findInHotbar(itemStack -> (!antiBreak.get() || (antiBreak.get() && itemStack.getDamage() < itemStack.getMaxDamage() - 1)) && itemStack.getItem() == Items.SHEARS);
            if (InvUtils.swap(shears.slot(), true))
                foundShears = true;
        }
        if (foundShears) {
            this.entity = entity;
            if (rotate.get())
                Rotations.rotate(Rotations.getYaw(entity), Rotations.getPitch(entity), -100, this::interact);
            else
                interact();
            return;
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) SheepEntity(net.minecraft.entity.passive.SheepEntity) SheepEntity(net.minecraft.entity.passive.SheepEntity) FindItemResult(mathax.client.utils.player.FindItemResult) ShearsItem(net.minecraft.item.ShearsItem) EventHandler(mathax.client.eventbus.EventHandler)

Example 27 with FindItemResult

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

the class EChestFarmer method onTick.

@EventHandler
private void onTick(TickEvent.Pre event) {
    // Finding target pos
    if (target == null) {
        if (mc.crosshairTarget == null || mc.crosshairTarget.getType() != HitResult.Type.BLOCK)
            return;
        BlockPos pos = ((BlockHitResult) mc.crosshairTarget).getBlockPos().up();
        BlockState state = mc.world.getBlockState(pos);
        if (state.getMaterial().isReplaceable() || state.getBlock() == Blocks.ENDER_CHEST) {
            target = ((BlockHitResult) mc.crosshairTarget).getBlockPos().up();
        } else
            return;
    }
    // Disable if the block is too far away
    if (PlayerUtils.distanceTo(target) > mc.interactionManager.getReachDistance()) {
        error("Target block pos out of reach.");
        target = null;
        return;
    }
    // Toggle if obby amount reached
    if (selfToggle.get() && InvUtils.find(Items.OBSIDIAN).count() - (ignoreExisting.get() ? startCount : 0) >= amount.get()) {
        InvUtils.swapBack();
        error("Obsidian amount reached, disabling...");
        toggle();
        return;
    }
    // Break existing echest at target pos
    if (mc.world.getBlockState(target).getBlock() == Blocks.ENDER_CHEST) {
        double bestScore = -1;
        int bestSlot = -1;
        for (int i = 0; i < 9; i++) {
            ItemStack itemStack = mc.player.getInventory().getStack(i);
            if (EnchantmentHelper.getLevel(Enchantments.SILK_TOUCH, itemStack) > 0)
                continue;
            double score = itemStack.getMiningSpeedMultiplier(Blocks.ENDER_CHEST.getDefaultState());
            if (score > bestScore) {
                bestScore = score;
                bestSlot = i;
            }
        }
        if (bestSlot == -1)
            return;
        InvUtils.swap(bestSlot, true);
        BlockUtils.breakBlock(target, swingHand.get());
    }
    // Place echest if the target pos is empty
    if (mc.world.getBlockState(target).getMaterial().isReplaceable()) {
        FindItemResult echest = InvUtils.findInHotbar(Items.ENDER_CHEST);
        if (!echest.found()) {
            error("No EChests in your hotbar, disabling...");
            toggle();
            return;
        }
        BlockUtils.place(target, echest, true, 0, true);
    }
}
Also used : BlockState(net.minecraft.block.BlockState) FindItemResult(mathax.client.utils.player.FindItemResult) BlockPos(net.minecraft.util.math.BlockPos) BlockHitResult(net.minecraft.util.hit.BlockHitResult) ItemStack(net.minecraft.item.ItemStack) EventHandler(mathax.client.eventbus.EventHandler)

Example 28 with FindItemResult

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

the class SpawnProofer method onTickPre.

@EventHandler
private void onTickPre(TickEvent.Pre event) {
    if (delay.get() != 0 && ticksWaited < delay.get() - 1)
        return;
    FindItemResult block = InvUtils.findInHotbar(itemStack -> blocks.get().contains(Block.getBlockFromItem(itemStack.getItem())));
    if (!block.found()) {
        error("Found none of the chosen blocks in your hotbar, disabling...");
        toggle();
        return;
    }
    for (BlockPos.Mutable blockPos : spawns) spawnPool.free(blockPos);
    spawns.clear();
    BlockIterator.register(range.get(), range.get(), (blockPos, blockState) -> {
        BlockUtils.MobSpawn spawn = BlockUtils.isValidMobSpawn(blockPos, newMobSpawnLightLevel.get());
        if ((spawn == BlockUtils.MobSpawn.Always && (mode.get() == Mode.Always || mode.get() == Mode.Both)) || spawn == BlockUtils.MobSpawn.Potential && (mode.get() == Mode.Potential || mode.get() == Mode.Both))
            spawns.add(spawnPool.get().set(blockPos));
    });
}
Also used : BlockUtils(mathax.client.utils.world.BlockUtils) FindItemResult(mathax.client.utils.player.FindItemResult) BlockPos(net.minecraft.util.math.BlockPos) EventHandler(mathax.client.eventbus.EventHandler)

Example 29 with FindItemResult

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

the class InfinityMiner method findPickaxe.

private boolean findPickaxe() {
    Predicate<ItemStack> pickaxePredicate = (stack -> stack.getItem() instanceof PickaxeItem && Utils.hasEnchantments(stack, Enchantments.MENDING) && !Utils.hasEnchantments(stack, Enchantments.SILK_TOUCH));
    FindItemResult bestPick = InvUtils.findInHotbar(pickaxePredicate);
    if (bestPick.isOffhand())
        InvUtils.quickMove().fromOffhand().toHotbar(mc.player.getInventory().selectedSlot);
    else if (bestPick.isHotbar())
        InvUtils.swap(bestPick.slot(), false);
    return InvUtils.findInHotbar(pickaxePredicate).isMainHand();
}
Also used : PickaxeItem(net.minecraft.item.PickaxeItem) FindItemResult(mathax.client.utils.player.FindItemResult) ItemStack(net.minecraft.item.ItemStack)

Example 30 with FindItemResult

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

the class LiquidFiller method onTick.

@EventHandler
private void onTick(TickEvent.Pre event) {
    // Update timer according to delay
    if (timer < delay.get()) {
        timer++;
        return;
    } else
        timer = 0;
    // Find slot with a block
    FindItemResult item = InvUtils.findInHotbar(itemStack -> itemStack.getItem() instanceof BlockItem && whitelist.get().contains(Block.getBlockFromItem(itemStack.getItem())));
    if (!item.found())
        return;
    // Loop blocks around the player
    BlockIterator.register(horizontalRadius.get(), verticalRadius.get(), (blockPos, blockState) -> {
        // Check if the block a source liquid block
        if (isSource(blockState)) {
            Block liquid = blockState.getBlock();
            PlaceIn placeIn = placeInLiquids.get();
            if (placeIn == PlaceIn.Both || (placeIn == PlaceIn.Lava && liquid == Blocks.LAVA) || (placeIn == PlaceIn.Water && liquid == Blocks.WATER)) {
                if (BlockUtils.place(blockPos, item, rotate.get(), 0, true))
                    BlockIterator.disableCurrent();
            }
        }
    });
}
Also used : FindItemResult(mathax.client.utils.player.FindItemResult) Block(net.minecraft.block.Block) BlockItem(net.minecraft.item.BlockItem) 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