Search in sources :

Example 21 with FindItemResult

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

the class Quiver method onActivate.

@Override
public void onActivate() {
    FindItemResult bow = InvUtils.findInHotbar(Items.BOW);
    if (!bow.isHotbar()) {
        error("No bow found, disabling...");
        toggle();
    }
    mc.options.useKey.setPressed(false);
    mc.interactionManager.stopUsingItem(mc.player);
    InvUtils.swap(bow.slot(), true);
    arrowSlots.clear();
    List<StatusEffect> usedEffects = new ArrayList<>();
    for (int i = mc.player.getInventory().size(); i > 0; i--) {
        if (i == mc.player.getInventory().selectedSlot)
            continue;
        ItemStack item = mc.player.getInventory().getStack(i);
        if (item.getItem() != Items.TIPPED_ARROW)
            continue;
        List<StatusEffectInstance> effects = PotionUtil.getPotionEffects(item);
        if (effects.isEmpty())
            continue;
        StatusEffect effect = effects.get(0).getEffectType();
        if (this.effects.get().contains(effect) && !usedEffects.contains(effect) && (!hasEffect(effect) || !checkEffects.get())) {
            usedEffects.add(effect);
            arrowSlots.add(i);
        }
    }
}
Also used : StatusEffect(net.minecraft.entity.effect.StatusEffect) StatusEffectInstance(net.minecraft.entity.effect.StatusEffectInstance) FindItemResult(mathax.client.utils.player.FindItemResult) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

Example 22 with FindItemResult

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

the class AutoEXP method onTick.

@EventHandler
private void onTick(TickEvent.Pre event) {
    if (playerNearStop.get() && TargetUtils.isPlayerNear(playerNearStopRange.get()))
        return;
    if (repairingI == -1) {
        if (mode.get() != Mode.Hands) {
            for (int i = 0; i < mc.player.getInventory().armor.size(); i++) {
                if (needsRepair(mc.player.getInventory().armor.get(i), minThreshold.get())) {
                    repairingI = SlotUtils.ARMOR_START + i;
                    break;
                }
            }
        }
        if (mode.get() != Mode.Armor && repairingI == -1) {
            for (Hand hand : Hand.values()) {
                if (needsRepair(mc.player.getStackInHand(hand), minThreshold.get())) {
                    repairingI = hand == Hand.MAIN_HAND ? mc.player.getInventory().selectedSlot : SlotUtils.OFFHAND;
                    break;
                }
            }
        }
    }
    if (repairingI != -1) {
        if (!needsRepair(mc.player.getInventory().getStack(repairingI), maxThreshold.get())) {
            repairingI = -1;
            return;
        }
        FindItemResult exp = InvUtils.find(Items.EXPERIENCE_BOTTLE);
        if (exp.found()) {
            if (!exp.isHotbar() && !exp.isOffhand()) {
                if (!replenish.get())
                    return;
                InvUtils.move().from(exp.slot()).toHotbar(slot.get() - 1);
            }
            Rotations.rotate(mc.player.getYaw(), 90, () -> {
                if (exp.getHand() != null)
                    mc.interactionManager.interactItem(mc.player, mc.world, exp.getHand());
                else {
                    InvUtils.swap(exp.slot(), true);
                    mc.interactionManager.interactItem(mc.player, mc.world, Hand.MAIN_HAND);
                    InvUtils.swapBack();
                }
            });
        }
    }
}
Also used : FindItemResult(mathax.client.utils.player.FindItemResult) Hand(net.minecraft.util.Hand) EventHandler(mathax.client.eventbus.EventHandler)

Example 23 with FindItemResult

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

the class Notebot method onTickSetup.

private void onTickSetup() {
    if (ticks < delay.get())
        return;
    ticks = 0;
    if (currentNote >= uniqueNotes.size()) {
        stage = Stage.Playing;
        info("Loading done.");
        Play();
        return;
    }
    int index = currentNote + offset;
    BlockPos pos;
    if (index < scannedNoteblocks.size()) {
        pos = scannedNoteblocks.get(index);
        if (mc.world.getBlockState(pos).getBlock() != Blocks.NOTE_BLOCK)
            offset++;
        else {
            blockPositions.put(uniqueNotes.get(currentNote), pos);
            stage = Stage.Tune;
        }
        return;
    }
    FindItemResult noteBlock = InvUtils.findInHotbar(Items.NOTE_BLOCK);
    if (!noteBlock.found()) {
        error("Not enough noteblocks");
        disable();
        return;
    }
    index -= scannedNoteblocks.size();
    try {
        pos = mc.player.getBlockPos().add(possibleBlockPos.get(index));
    } catch (IndexOutOfBoundsException e) {
        error("Not enough valid positions.");
        disable();
        return;
    }
    if (!isValidEmptySpot(pos) || !NotebotUtils.isValidInstrument(pos, instrument.get())) {
        offset++;
        return;
    }
    if (!BlockUtils.place(pos, noteBlock, true, 100, true))
        offset++;
    else {
        blockPositions.put(uniqueNotes.get(currentNote), pos);
        stage = Stage.Tune;
    }
}
Also used : FindItemResult(mathax.client.utils.player.FindItemResult) BlockPos(net.minecraft.util.math.BlockPos)

Example 24 with FindItemResult

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

the class LocateCommand method build.

@Override
public void build(LiteralArgumentBuilder<CommandSource> builder) {
    builder.then(literal("buried_treasure").executes(s -> {
        ItemStack stack = mc.player.getInventory().getMainHandStack();
        if (stack.getItem() != Items.FILLED_MAP) {
            error("You need to hold a treasure map first");
            return SINGLE_SUCCESS;
        }
        NbtCompound tag = stack.getNbt();
        NbtList nbt1 = (NbtList) tag.get("Decorations");
        if (nbt1 == null) {
            error("Couldn't locate the cross. Are you holding a (highlight)treasure map(default)?");
            return SINGLE_SUCCESS;
        }
        NbtCompound iconNBT = nbt1.getCompound(0);
        if (iconNBT == null) {
            error("Couldn't locate the cross. Are you holding a (highlight)treasure map(default)?");
            return SINGLE_SUCCESS;
        }
        Vec3d coords = new Vec3d(iconNBT.getDouble("x"), iconNBT.getDouble("y"), iconNBT.getDouble("z"));
        BaseText text = new LiteralText("Buried Treasure located at ");
        text.append(ChatUtils.formatCoords(coords));
        text.append(".");
        info(text);
        return SINGLE_SUCCESS;
    }));
    builder.then(literal("lodestone").executes(s -> {
        ItemStack stack = mc.player.getInventory().getMainHandStack();
        if (stack.getItem() != Items.COMPASS) {
            error("You need to hold a lodestone compass");
            return SINGLE_SUCCESS;
        }
        NbtCompound tag = stack.getNbt();
        if (tag == null) {
            error("Couldn't get the NBT data. Are you holding a (highlight)lodestone(default) compass?");
            return SINGLE_SUCCESS;
        }
        NbtCompound nbt1 = tag.getCompound("LodestonePos");
        if (nbt1 == null) {
            error("Couldn't get the NBT data. Are you holding a (highlight)lodestone(default) compass?");
            return SINGLE_SUCCESS;
        }
        Vec3d coords = new Vec3d(nbt1.getDouble("X"), nbt1.getDouble("Y"), nbt1.getDouble("Z"));
        BaseText text = new LiteralText("Lodestone located at ");
        text.append(ChatUtils.formatCoords(coords));
        text.append(".");
        info(text);
        return SINGLE_SUCCESS;
    }));
    builder.then(literal("mansion").executes(s -> {
        ItemStack stack = mc.player.getInventory().getMainHandStack();
        if (stack.getItem() != Items.FILLED_MAP) {
            error("You need to hold a woodland explorer map first");
            return SINGLE_SUCCESS;
        }
        NbtCompound tag = stack.getNbt();
        NbtList nbt1 = (NbtList) tag.get("Decorations");
        if (nbt1 == null) {
            error("Couldn't locate the mansion. Are you holding a (highlight)woodland explorer map(default)?");
            return SINGLE_SUCCESS;
        }
        NbtCompound iconNBT = nbt1.getCompound(0);
        if (iconNBT == null) {
            error("Couldn't locate the mansion. Are you holding a (highlight)woodland explorer map(default)?");
            return SINGLE_SUCCESS;
        }
        Vec3d coords = new Vec3d(iconNBT.getDouble("x"), iconNBT.getDouble("y"), iconNBT.getDouble("z"));
        BaseText text = new LiteralText("Mansion located at ");
        text.append(ChatUtils.formatCoords(coords));
        text.append(".");
        info(text);
        return SINGLE_SUCCESS;
    }));
    builder.then(literal("stronghold").executes(s -> {
        FindItemResult eye = InvUtils.findInHotbar(Items.ENDER_EYE);
        if (eye.found()) {
            BaritoneAPI.getProvider().getPrimaryBaritone().getCommandManager().execute("follow entity minecraft:eye_of_ender");
            firstStart = null;
            firstEnd = null;
            secondStart = null;
            secondEnd = null;
            MatHax.EVENT_BUS.subscribe(this);
            info("Please throw the first Eye of Ender");
        } else {
            Vec3d coords = findByBlockList(strongholdBlocks);
            if (coords == null) {
                error("No stronghold found nearby. You can use (highlight)Ender Eyes(default) for more success.");
                return SINGLE_SUCCESS;
            }
            BaseText text = new LiteralText("Stronghold located at ");
            text.append(ChatUtils.formatCoords(coords));
            text.append(".");
            info(text);
        }
        return SINGLE_SUCCESS;
    }));
    builder.then(literal("nether_fortress").executes(s -> {
        Vec3d coords = findByBlockList(netherFortressBlocks);
        if (coords == null) {
            error("No nether fortress found.");
            return SINGLE_SUCCESS;
        }
        BaseText text = new LiteralText("Fortress located at ");
        text.append(ChatUtils.formatCoords(coords));
        text.append(".");
        info(text);
        return SINGLE_SUCCESS;
    }));
    builder.then(literal("monument").executes(s -> {
        ItemStack stack = mc.player.getInventory().getMainHandStack();
        if (stack.getItem() == Items.FILLED_MAP) {
            NbtCompound tag = stack.getNbt();
            if (tag != null) {
                NbtList nbt1 = (NbtList) tag.get("Decorations");
                if (nbt1 != null) {
                    NbtCompound iconNBT = nbt1.getCompound(0);
                    if (iconNBT != null) {
                        Vec3d coords = new Vec3d(iconNBT.getDouble("x"), iconNBT.getDouble("y"), iconNBT.getDouble("z"));
                        BaseText text = new LiteralText("Monument located at ");
                        text.append(ChatUtils.formatCoords(coords));
                        text.append(".");
                        info(text);
                        return SINGLE_SUCCESS;
                    }
                }
            }
        }
        Vec3d coords = findByBlockList(monumentBlocks);
        if (coords == null) {
            error("No monument found. You can try using a (highlight)Ocean explorer map(default) for more success.");
            return SINGLE_SUCCESS;
        }
        BaseText text = new LiteralText("Monument located at ");
        text.append(ChatUtils.formatCoords(coords));
        text.append(".");
        info(text);
        return SINGLE_SUCCESS;
    }));
    builder.then(literal("cancel").executes(s -> {
        cancel();
        return SINGLE_SUCCESS;
    }));
}
Also used : EntityType(net.minecraft.entity.EntityType) LiteralText(net.minecraft.text.LiteralText) Arrays(java.util.Arrays) PacketEvent(mathax.client.events.packets.PacketEvent) NbtList(net.minecraft.nbt.NbtList) EventHandler(mathax.client.eventbus.EventHandler) SINGLE_SUCCESS(com.mojang.brigadier.Command.SINGLE_SUCCESS) ItemStack(net.minecraft.item.ItemStack) PlaySoundS2CPacket(net.minecraft.network.packet.s2c.play.PlaySoundS2CPacket) BaseText(net.minecraft.text.BaseText) Block(net.minecraft.block.Block) SoundEvents(net.minecraft.sound.SoundEvents) Vec3d(net.minecraft.util.math.Vec3d) Command(mathax.client.systems.commands.Command) EntitySpawnS2CPacket(net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket) BaritoneAPI(baritone.api.BaritoneAPI) MatHax(mathax.client.MatHax) ChatUtils(mathax.client.utils.misc.ChatUtils) BlockPos(net.minecraft.util.math.BlockPos) Items(net.minecraft.item.Items) LiteralArgumentBuilder(com.mojang.brigadier.builder.LiteralArgumentBuilder) Blocks(net.minecraft.block.Blocks) CommandSource(net.minecraft.command.CommandSource) InvUtils(mathax.client.utils.player.InvUtils) NbtCompound(net.minecraft.nbt.NbtCompound) List(java.util.List) FindItemResult(mathax.client.utils.player.FindItemResult) BaseText(net.minecraft.text.BaseText) NbtCompound(net.minecraft.nbt.NbtCompound) FindItemResult(mathax.client.utils.player.FindItemResult) NbtList(net.minecraft.nbt.NbtList) ItemStack(net.minecraft.item.ItemStack) Vec3d(net.minecraft.util.math.Vec3d) LiteralText(net.minecraft.text.LiteralText)

Example 25 with FindItemResult

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

the class AutoNametag method onTick.

@EventHandler
private void onTick(TickEvent.Pre event) {
    // Nametag in hobar
    FindItemResult findNametag = InvUtils.findInHotbar(Items.NAME_TAG);
    if (!findNametag.found()) {
        error("No Nametag in Hotbar");
        toggle();
        return;
    }
    // Target
    target = TargetUtils.get(entity -> {
        if (PlayerUtils.distanceTo(entity) > range.get())
            return false;
        if (!entities.get().getBoolean(entity.getType()))
            return false;
        if (entity.hasCustomName())
            return renametag.get() && entity.getCustomName() != mc.player.getInventory().getStack(findNametag.slot()).getName();
        return false;
    }, priority.get());
    if (target == null)
        return;
    // Swapping slots
    InvUtils.swap(findNametag.slot(), true);
    offHand = findNametag.isOffhand();
    // Interaction
    if (rotate.get())
        Rotations.rotate(Rotations.getYaw(target), Rotations.getPitch(target), -100, this::interact);
    else
        interact();
}
Also used : EntityType(net.minecraft.entity.EntityType) Entity(net.minecraft.entity.Entity) Object2BooleanMap(it.unimi.dsi.fastutil.objects.Object2BooleanMap) SortPriority(mathax.client.utils.entity.SortPriority) PlayerUtils(mathax.client.utils.player.PlayerUtils) Items(net.minecraft.item.Items) EventHandler(mathax.client.eventbus.EventHandler) InvUtils(mathax.client.utils.player.InvUtils) TickEvent(mathax.client.events.world.TickEvent) FindItemResult(mathax.client.utils.player.FindItemResult) Categories(mathax.client.systems.modules.Categories) Hand(net.minecraft.util.Hand) Module(mathax.client.systems.modules.Module) TargetUtils(mathax.client.utils.entity.TargetUtils) mathax.client.settings(mathax.client.settings) Rotations(mathax.client.utils.player.Rotations) FindItemResult(mathax.client.utils.player.FindItemResult) 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