Search in sources :

Example 1 with PlayerInteractItemC2SPacket

use of net.minecraft.network.packet.c2s.play.PlayerInteractItemC2SPacket in project BleachHack by BleachDrinker420.

the class AutoEXP method onTick.

@BleachSubscribe
public void onTick(EventTick event) {
    if (mc.player.currentScreenHandler != mc.player.playerScreenHandler)
        return;
    int xpSlot = InventoryUtils.getSlot(true, i -> mc.player.getInventory().getStack(i).getItem() == Items.EXPERIENCE_BOTTLE);
    if (xpSlot == -1)
        return;
    int damage = getSetting(3).asSlider().getValueInt();
    double target = getSetting(4).asSlider().getValue();
    if (slot != -1) {
        if (xpNeeded == 0) {
            ItemStack item = slot < 45 ? mc.player.currentScreenHandler.getSlot(slot).getStack() : mc.player.getOffHandStack();
            if (item.isDamaged() && item.getMaxDamage() - item.getDamage() <= damage)
                return;
            for (int i = 1; i <= 4; i++) {
                ItemStack stack = mc.player.currentScreenHandler.getSlot(i).getStack();
                if (!stack.isEmpty()) {
                    for (int j = 5; j <= 8; j++) {
                        if (mc.player.currentScreenHandler.getSlot(j).canInsert(stack)) {
                            mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, i, 0, SlotActionType.PICKUP, mc.player);
                            mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, j, 0, SlotActionType.PICKUP, mc.player);
                            return;
                        }
                    }
                }
            }
            if (slot >= 46) {
                if (slot - 46 != mc.player.getInventory().selectedSlot) {
                    mc.player.getInventory().selectedSlot = slot - 46;
                    mc.player.networkHandler.sendPacket(new UpdateSelectedSlotC2SPacket(slot - 46));
                }
                mc.player.networkHandler.sendPacket(new PlayerActionC2SPacket(Action.SWAP_ITEM_WITH_OFFHAND, BlockPos.ORIGIN, Direction.DOWN));
            }
            delay = 0;
            slot = -1;
            return;
        }
        for (int i = 5; i <= 8; i++) {
            if (i != slot && EnchantmentHelper.getLevel(Enchantments.MENDING, mc.player.currentScreenHandler.getSlot(i).getStack()) != 0) {
                for (int j = 1; j <= 4; j++) {
                    ItemStack craftingStack = mc.player.currentScreenHandler.getSlot(j).getStack();
                    if (!craftingStack.isDamageable()) {
                        mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, i, 0, SlotActionType.PICKUP, mc.player);
                        mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, j, 0, SlotActionType.PICKUP, mc.player);
                        if (!craftingStack.isEmpty())
                            mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, j, 1, SlotActionType.THROW, mc.player);
                        return;
                    }
                }
            }
        }
        if (slot > 8 && slot < 45) {
            if (slot - 36 != mc.player.getInventory().selectedSlot) {
                mc.player.getInventory().selectedSlot = slot - 36;
                mc.player.networkHandler.sendPacket(new UpdateSelectedSlotC2SPacket(slot - 36));
            }
            mc.player.networkHandler.sendPacket(new PlayerActionC2SPacket(Action.SWAP_ITEM_WITH_OFFHAND, BlockPos.ORIGIN, Direction.DOWN));
            // hack
            slot += 10;
            return;
        }
        delay++;
        if (delay >= getSetting(6).asSlider().getValueInt()) {
            delay = 0;
            int toThrow = Math.min(getSetting(5).asSlider().getValueInt(), xpNeeded);
            if (toThrow != 0) {
                mc.player.networkHandler.sendPacket(new PlayerMoveC2SPacket.LookAndOnGround(mc.player.getYaw(), 90, mc.player.isOnGround()));
                for (int t = 0; t < toThrow; t++) {
                    if (InventoryUtils.selectSlot(false, i -> mc.player.getInventory().getStack(i).getItem() == Items.EXPERIENCE_BOTTLE) == Hand.MAIN_HAND) {
                        // Trying to use without bruh
                        mc.player.networkHandler.sendPacket(new PlayerInteractItemC2SPacket(Hand.MAIN_HAND));
                        ItemStack itemStack2 = mc.player.getMainHandStack().use(mc.world, mc.player, Hand.MAIN_HAND).getValue();
                        if (itemStack2 != mc.player.getMainHandStack()) {
                            mc.player.setStackInHand(Hand.MAIN_HAND, itemStack2);
                        }
                        xpNeeded--;
                    }
                }
            }
        }
        return;
    }
    IntSet slots = new IntArraySet();
    if (getSetting(0).asToggle().getState()) {
        slots.add(5);
        slots.add(6);
        slots.add(7);
        slots.add(8);
    }
    if (getSetting(1).asToggle().getState())
        slots.add(36 + mc.player.getInventory().selectedSlot);
    if (getSetting(2).asToggle().getState())
        slots.add(45);
    if (getSetting(0).asToggle().getState()) {
        for (int s : slots) {
            ItemStack item = mc.player.currentScreenHandler.getSlot(s).getStack();
            if (item.isDamageable() && item.getMaxDamage() - item.getDamage() <= damage && item.getMaxDamage() - item.getDamage() < item.getMaxDamage() * target) {
                slot = s;
                xpNeeded = (int) Math.ceil((item.getMaxDamage() * target - (item.getMaxDamage() - item.getDamage())) / 14d);
                return;
            }
        }
    }
}
Also used : BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe) SettingSlider(org.bleachhack.setting.module.SettingSlider) CloseHandledScreenC2SPacket(net.minecraft.network.packet.c2s.play.CloseHandledScreenC2SPacket) ModuleCategory(org.bleachhack.module.ModuleCategory) PlayerInteractItemC2SPacket(net.minecraft.network.packet.c2s.play.PlayerInteractItemC2SPacket) InventoryUtils(org.bleachhack.util.InventoryUtils) IntArraySet(it.unimi.dsi.fastutil.ints.IntArraySet) PlayerActionC2SPacket(net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket) BlockPos(net.minecraft.util.math.BlockPos) Items(net.minecraft.item.Items) EnchantmentHelper(net.minecraft.enchantment.EnchantmentHelper) Module(org.bleachhack.module.Module) Action(net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket.Action) Direction(net.minecraft.util.math.Direction) ItemStack(net.minecraft.item.ItemStack) UpdateSelectedSlotC2SPacket(net.minecraft.network.packet.c2s.play.UpdateSelectedSlotC2SPacket) Enchantments(net.minecraft.enchantment.Enchantments) PlayerMoveC2SPacket(net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket) IntSet(it.unimi.dsi.fastutil.ints.IntSet) Hand(net.minecraft.util.Hand) SettingToggle(org.bleachhack.setting.module.SettingToggle) SlotActionType(net.minecraft.screen.slot.SlotActionType) EventPacket(org.bleachhack.event.events.EventPacket) EventTick(org.bleachhack.event.events.EventTick) PlayerActionC2SPacket(net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket) IntSet(it.unimi.dsi.fastutil.ints.IntSet) UpdateSelectedSlotC2SPacket(net.minecraft.network.packet.c2s.play.UpdateSelectedSlotC2SPacket) PlayerMoveC2SPacket(net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket) PlayerInteractItemC2SPacket(net.minecraft.network.packet.c2s.play.PlayerInteractItemC2SPacket) IntArraySet(it.unimi.dsi.fastutil.ints.IntArraySet) ItemStack(net.minecraft.item.ItemStack) BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe)

Example 2 with PlayerInteractItemC2SPacket

use of net.minecraft.network.packet.c2s.play.PlayerInteractItemC2SPacket in project meteor-crash-addon by AntiCope.

the class TryUseCrash method onTick.

@EventHandler
private void onTick(TickEvent.Post event) {
    BlockHitResult bhr = new BlockHitResult(new Vec3d(.5, .5, .5), Direction.DOWN, mc.player.getBlockPos(), false);
    net.minecraft.network.packet.c2s.play.PlayerInteractItemC2SPacket packet = new PlayerInteractItemC2SPacket(Hand.MAIN_HAND);
    PlayerInteractBlockC2SPacket packet1 = new PlayerInteractBlockC2SPacket(Hand.MAIN_HAND, bhr);
    if (mc.getNetworkHandler() == null)
        return;
    for (int i = 0; i < packets.get(); i++) {
        mc.getNetworkHandler().sendPacket(packet);
        mc.getNetworkHandler().sendPacket(packet1);
    }
}
Also used : PlayerInteractItemC2SPacket(net.minecraft.network.packet.c2s.play.PlayerInteractItemC2SPacket) PlayerInteractItemC2SPacket(net.minecraft.network.packet.c2s.play.PlayerInteractItemC2SPacket) BlockHitResult(net.minecraft.util.hit.BlockHitResult) Vec3d(net.minecraft.util.math.Vec3d) PlayerInteractBlockC2SPacket(net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket) EventHandler(meteordevelopment.orbit.EventHandler)

Aggregations

PlayerInteractItemC2SPacket (net.minecraft.network.packet.c2s.play.PlayerInteractItemC2SPacket)2 IntArraySet (it.unimi.dsi.fastutil.ints.IntArraySet)1 IntSet (it.unimi.dsi.fastutil.ints.IntSet)1 EventHandler (meteordevelopment.orbit.EventHandler)1 EnchantmentHelper (net.minecraft.enchantment.EnchantmentHelper)1 Enchantments (net.minecraft.enchantment.Enchantments)1 ItemStack (net.minecraft.item.ItemStack)1 Items (net.minecraft.item.Items)1 CloseHandledScreenC2SPacket (net.minecraft.network.packet.c2s.play.CloseHandledScreenC2SPacket)1 PlayerActionC2SPacket (net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket)1 Action (net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket.Action)1 PlayerInteractBlockC2SPacket (net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket)1 PlayerMoveC2SPacket (net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket)1 UpdateSelectedSlotC2SPacket (net.minecraft.network.packet.c2s.play.UpdateSelectedSlotC2SPacket)1 SlotActionType (net.minecraft.screen.slot.SlotActionType)1 Hand (net.minecraft.util.Hand)1 BlockHitResult (net.minecraft.util.hit.BlockHitResult)1 BlockPos (net.minecraft.util.math.BlockPos)1 Direction (net.minecraft.util.math.Direction)1 Vec3d (net.minecraft.util.math.Vec3d)1