Search in sources :

Example 16 with EventHandler

use of mathax.client.eventbus.EventHandler 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 17 with EventHandler

use of mathax.client.eventbus.EventHandler 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 18 with EventHandler

use of mathax.client.eventbus.EventHandler in project Client by MatHax.

the class TextRadarHud method onReceivePacket.

@EventHandler
private void onReceivePacket(PacketEvent.Receive event) {
    if (!totemPops.get())
        return;
    if (!(event.packet instanceof EntityStatusS2CPacket))
        return;
    EntityStatusS2CPacket p = (EntityStatusS2CPacket) event.packet;
    if (p.getStatus() != 35)
        return;
    Entity entity = p.getEntity(mc.world);
    if (!(entity instanceof PlayerEntity))
        return;
    synchronized (totemPopMap) {
        int pops = totemPopMap.getOrDefault(entity.getUuid(), 0);
        totemPopMap.put(entity.getUuid(), ++pops);
    }
}
Also used : AbstractClientPlayerEntity(net.minecraft.client.network.AbstractClientPlayerEntity) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) EntityStatusS2CPacket(net.minecraft.network.packet.s2c.play.EntityStatusS2CPacket) AbstractClientPlayerEntity(net.minecraft.client.network.AbstractClientPlayerEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) EventHandler(mathax.client.eventbus.EventHandler)

Example 19 with EventHandler

use of mathax.client.eventbus.EventHandler 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 20 with EventHandler

use of mathax.client.eventbus.EventHandler in project Client by MatHax.

the class BurrowNotifier method onTick.

@EventHandler
private void onTick(TickEvent.Post event) {
    for (PlayerEntity player : mc.world.getPlayers()) {
        if (isBurrowValid(player)) {
            burrowedPlayers.add(player);
            warning("(highlight)%s(default) is burrowed!", player.getEntityName());
        }
        if (burrowedPlayers.contains(player) && !PlayerUtils.isBurrowed(player, true)) {
            burrowedPlayers.remove(player);
            warning("(highlight)%s(default) is no longer burrowed.", player.getEntityName());
        }
    }
}
Also used : PlayerEntity(net.minecraft.entity.player.PlayerEntity) EventHandler(mathax.client.eventbus.EventHandler)

Aggregations

EventHandler (mathax.client.eventbus.EventHandler)80 BlockPos (net.minecraft.util.math.BlockPos)22 FindItemResult (mathax.client.utils.player.FindItemResult)20 Vec3d (net.minecraft.util.math.Vec3d)12 Entity (net.minecraft.entity.Entity)9 PlayerEntity (net.minecraft.entity.player.PlayerEntity)8 BlockState (net.minecraft.block.BlockState)6 Direction (net.minecraft.util.math.Direction)5 ArrayList (java.util.ArrayList)4 TickEvent (mathax.client.events.world.TickEvent)4 IVec3d (mathax.client.mixininterface.IVec3d)4 Categories (mathax.client.systems.modules.Categories)4 Module (mathax.client.systems.modules.Module)4 InvUtils (mathax.client.utils.player.InvUtils)4 ItemStack (net.minecraft.item.ItemStack)4 mathax.client.settings (mathax.client.settings)3 BlockItem (net.minecraft.item.BlockItem)3 BlockHitResult (net.minecraft.util.hit.BlockHitResult)3 Comparator (java.util.Comparator)2 NoFall (mathax.client.systems.modules.movement.NoFall)2