Search in sources :

Example 1 with UpdateSelectedSlotC2SPacket

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

the class InventoryUtils method selectSlot.

public static Hand selectSlot(int slot) {
    if (slot >= 0 && slot <= 36) {
        if (slot < 9) {
            if (slot != mc.player.getInventory().selectedSlot) {
                mc.player.getInventory().selectedSlot = slot;
                mc.player.networkHandler.sendPacket(new UpdateSelectedSlotC2SPacket(slot));
            }
            return Hand.MAIN_HAND;
        } else if (mc.player.playerScreenHandler == mc.player.currentScreenHandler) {
            for (int i = 0; i <= 8; i++) {
                if (mc.player.getInventory().getStack(i).isEmpty()) {
                    mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, slot, 0, SlotActionType.QUICK_MOVE, mc.player);
                    if (i != mc.player.getInventory().selectedSlot) {
                        mc.player.getInventory().selectedSlot = i;
                        mc.player.networkHandler.sendPacket(new UpdateSelectedSlotC2SPacket(i));
                    }
                    return Hand.MAIN_HAND;
                }
            }
            mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, slot, 0, SlotActionType.PICKUP, mc.player);
            mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, 36 + mc.player.getInventory().selectedSlot, 0, SlotActionType.PICKUP, mc.player);
            mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, slot, 0, SlotActionType.PICKUP, mc.player);
            return Hand.MAIN_HAND;
        }
    } else if (slot == 40) {
        return Hand.OFF_HAND;
    }
    return null;
}
Also used : UpdateSelectedSlotC2SPacket(net.minecraft.network.packet.c2s.play.UpdateSelectedSlotC2SPacket)

Example 2 with UpdateSelectedSlotC2SPacket

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

the class AutoTool method onPacketSend.

@BleachSubscribe
public void onPacketSend(EventPacket.Send event) {
    if (event.getPacket() instanceof PlayerActionC2SPacket) {
        PlayerActionC2SPacket p = (PlayerActionC2SPacket) event.getPacket();
        if (p.getAction() == Action.START_DESTROY_BLOCK) {
            if (mc.player.isCreative() || mc.player.isSpectator())
                return;
            queueSlot = -1;
            lastSlot = mc.player.getInventory().selectedSlot;
            int slot = getBestSlot(p.getPos());
            if (slot != mc.player.getInventory().selectedSlot) {
                if (slot < 9) {
                    mc.player.getInventory().selectedSlot = slot;
                    mc.player.networkHandler.sendPacket(new UpdateSelectedSlotC2SPacket(slot));
                } else if (mc.player.playerScreenHandler == mc.player.currentScreenHandler) {
                    boolean itemInHand = !mc.player.getInventory().getMainHandStack().isEmpty();
                    mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, slot, 0, SlotActionType.PICKUP, mc.player);
                    mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, 36 + mc.player.getInventory().selectedSlot, 0, SlotActionType.PICKUP, mc.player);
                    if (itemInHand)
                        mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, slot, 0, SlotActionType.PICKUP, mc.player);
                }
            }
        } else if (p.getAction() == Action.STOP_DESTROY_BLOCK) {
            if (getSetting(1).asToggle().getState()) {
                ItemStack handSlot = mc.player.getMainHandStack();
                if (getSetting(0).asToggle().getState() && handSlot.isDamageable() && handSlot.getMaxDamage() - handSlot.getDamage() < 2 && queueSlot == mc.player.getInventory().selectedSlot) {
                    queueSlot = mc.player.getInventory().selectedSlot == 0 ? 1 : mc.player.getInventory().selectedSlot - 1;
                } else if (lastSlot >= 0 && lastSlot <= 8 && lastSlot != mc.player.getInventory().selectedSlot) {
                    queueSlot = lastSlot;
                }
            }
        }
    }
}
Also used : PlayerActionC2SPacket(net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket) UpdateSelectedSlotC2SPacket(net.minecraft.network.packet.c2s.play.UpdateSelectedSlotC2SPacket) ItemStack(net.minecraft.item.ItemStack) BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe)

Example 3 with UpdateSelectedSlotC2SPacket

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

the class AutoTool method onTick.

@BleachSubscribe
public void onTick(EventTick event) {
    if (queueSlot != -1) {
        mc.player.getInventory().selectedSlot = queueSlot;
        mc.player.networkHandler.sendPacket(new UpdateSelectedSlotC2SPacket(queueSlot));
        queueSlot = -1;
    }
}
Also used : UpdateSelectedSlotC2SPacket(net.minecraft.network.packet.c2s.play.UpdateSelectedSlotC2SPacket) BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe)

Example 4 with UpdateSelectedSlotC2SPacket

use of net.minecraft.network.packet.c2s.play.UpdateSelectedSlotC2SPacket 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 5 with UpdateSelectedSlotC2SPacket

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

the class AutoArmor method onTick.

@BleachSubscribe
public void onTick(EventTick event) {
    if (mc.player.playerScreenHandler != mc.player.currentScreenHandler || !BleachQueue.isEmpty("autoarmor_equip"))
        return;
    if (tickDelay > 0) {
        tickDelay--;
        return;
    }
    tickDelay = (getSetting(2).asToggle().getState() ? getSetting(2).asToggle().getChild(0).asSlider().getValueInt() : 0);
    /* [Slot type, [Armor slot, Armor prot, New armor slot, New armor prot]] */
    Map<EquipmentSlot, int[]> armorMap = new HashMap<>(4);
    armorMap.put(EquipmentSlot.FEET, new int[] { 36, getProtection(mc.player.getInventory().getStack(36)), -1, -1 });
    armorMap.put(EquipmentSlot.LEGS, new int[] { 37, getProtection(mc.player.getInventory().getStack(37)), -1, -1 });
    armorMap.put(EquipmentSlot.CHEST, new int[] { 38, getProtection(mc.player.getInventory().getStack(38)), -1, -1 });
    armorMap.put(EquipmentSlot.HEAD, new int[] { 39, getProtection(mc.player.getInventory().getStack(39)), -1, -1 });
    /* Anti Break */
    if (getSetting(0).asToggle().getState()) {
        for (Entry<EquipmentSlot, int[]> e : armorMap.entrySet()) {
            ItemStack is = mc.player.getInventory().getStack(e.getValue()[0]);
            int armorSlot = (e.getValue()[0] - 34) + (39 - e.getValue()[0]) * 2;
            if (is.isDamageable() && is.getMaxDamage() - is.getDamage() < 7) {
                /* Look for an empty slot to quick move to */
                int forceMoveSlot = -1;
                for (int s = 0; s < 36; s++) {
                    if (mc.player.getInventory().getStack(s).isEmpty()) {
                        mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, armorSlot, 1, SlotActionType.QUICK_MOVE, mc.player);
                        return;
                    } else if (!(mc.player.getInventory().getStack(s).getItem() instanceof ToolItem) && !(mc.player.getInventory().getStack(s).getItem() instanceof ArmorItem) && !(mc.player.getInventory().getStack(s).getItem() instanceof ElytraItem) && mc.player.getInventory().getStack(s).getItem() != Items.TOTEM_OF_UNDYING && forceMoveSlot == -1) {
                        forceMoveSlot = s;
                    }
                }
                /* Bruh no empty spots, then force move to a non-totem/tool/armor item */
                if (forceMoveSlot != -1) {
                    // System.out.println(forceMoveSlot);
                    mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, forceMoveSlot < 9 ? 36 + forceMoveSlot : forceMoveSlot, 1, SlotActionType.THROW, mc.player);
                    mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, armorSlot, 1, SlotActionType.QUICK_MOVE, mc.player);
                    return;
                }
                /* No spots to move to, yeet the armor to not cause any bruh moments */
                mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, armorSlot, 1, SlotActionType.THROW, mc.player);
                return;
            }
        }
    }
    for (int s = 0; s < 36; s++) {
        int prot = getProtection(mc.player.getInventory().getStack(s));
        if (prot > 0) {
            EquipmentSlot slot = (mc.player.getInventory().getStack(s).getItem() instanceof ElytraItem ? EquipmentSlot.CHEST : ((ArmorItem) mc.player.getInventory().getStack(s).getItem()).getSlotType());
            for (Entry<EquipmentSlot, int[]> e : armorMap.entrySet()) {
                if (e.getKey() == slot) {
                    if (prot > e.getValue()[1] && prot > e.getValue()[3]) {
                        e.getValue()[2] = s;
                        e.getValue()[3] = prot;
                    }
                }
            }
        }
    }
    for (Entry<EquipmentSlot, int[]> e : armorMap.entrySet()) {
        if (e.getValue()[2] != -1) {
            if (e.getValue()[1] == -1 && e.getValue()[2] < 9) {
                if (e.getValue()[2] != mc.player.getInventory().selectedSlot) {
                    mc.player.getInventory().selectedSlot = e.getValue()[2];
                    mc.player.networkHandler.sendPacket(new UpdateSelectedSlotC2SPacket(e.getValue()[2]));
                }
                mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, 36 + e.getValue()[2], 1, SlotActionType.QUICK_MOVE, mc.player);
            } else if (mc.player.playerScreenHandler == mc.player.currentScreenHandler) {
                /* Convert inventory slots to container slots */
                int armorSlot = (e.getValue()[0] - 34) + (39 - e.getValue()[0]) * 2;
                int newArmorslot = e.getValue()[2] < 9 ? 36 + e.getValue()[2] : e.getValue()[2];
                mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, newArmorslot, 0, SlotActionType.PICKUP, mc.player);
                mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, armorSlot, 0, SlotActionType.PICKUP, mc.player);
                if (e.getValue()[1] != -1)
                    mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, newArmorslot, 0, SlotActionType.PICKUP, mc.player);
            }
            return;
        }
    }
}
Also used : ArmorItem(net.minecraft.item.ArmorItem) HashMap(java.util.HashMap) UpdateSelectedSlotC2SPacket(net.minecraft.network.packet.c2s.play.UpdateSelectedSlotC2SPacket) EquipmentSlot(net.minecraft.entity.EquipmentSlot) ElytraItem(net.minecraft.item.ElytraItem) ItemStack(net.minecraft.item.ItemStack) ToolItem(net.minecraft.item.ToolItem) BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe)

Aggregations

UpdateSelectedSlotC2SPacket (net.minecraft.network.packet.c2s.play.UpdateSelectedSlotC2SPacket)7 BleachSubscribe (org.bleachhack.eventbus.BleachSubscribe)5 ItemStack (net.minecraft.item.ItemStack)3 PlayerActionC2SPacket (net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket)3 IntArraySet (it.unimi.dsi.fastutil.ints.IntArraySet)1 IntSet (it.unimi.dsi.fastutil.ints.IntSet)1 HashMap (java.util.HashMap)1 EnchantmentHelper (net.minecraft.enchantment.EnchantmentHelper)1 Enchantments (net.minecraft.enchantment.Enchantments)1 EquipmentSlot (net.minecraft.entity.EquipmentSlot)1 ArmorItem (net.minecraft.item.ArmorItem)1 ElytraItem (net.minecraft.item.ElytraItem)1 Items (net.minecraft.item.Items)1 ToolItem (net.minecraft.item.ToolItem)1 CloseHandledScreenC2SPacket (net.minecraft.network.packet.c2s.play.CloseHandledScreenC2SPacket)1 Action (net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket.Action)1 PlayerInteractItemC2SPacket (net.minecraft.network.packet.c2s.play.PlayerInteractItemC2SPacket)1 PlayerMoveC2SPacket (net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket)1 SlotActionType (net.minecraft.screen.slot.SlotActionType)1 Hand (net.minecraft.util.Hand)1