Skip to content

Commit

Permalink
Added AutoPot module. (CCBlueX#619)
Browse files Browse the repository at this point in the history
* Added AutoPot module.

* Small AutoPot changes + other module minor code changes.

* Made AutoSoup + AutoPot change slots, interact, etc the packet method.

Co-authored-by: kawaiinekololis <[email protected]>
  • Loading branch information
mems01 and 1zun4 authored Oct 17, 2021
1 parent e391653 commit 6b80723
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ object ModuleManager : Listenable, Iterable<Module> by modules {
ModuleAutoFish,
ModuleMobOwners,
ModuleGhostHand,
ModuleAutoPot,
ModuleAirJump
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ object ModuleAutoGapple : Module("AutoGapple", Category.COMBAT) {
saveSlot = true
}
player.inventory.selectedSlot = slot

// Avoid sword shield
wait(2)
eating = true
mc.options.keyUse.isPressed = true
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
* This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce)
*
* Copyright (c) 2016 - 2021 CCBlueX
*
* LiquidBounce is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LiquidBounce is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LiquidBounce. If not, see <https://www.gnu.org/licenses/>.
*/

package net.ccbluex.liquidbounce.features.module.modules.combat

import net.ccbluex.liquidbounce.event.repeatable
import net.ccbluex.liquidbounce.features.module.Category
import net.ccbluex.liquidbounce.features.module.Module
import net.ccbluex.liquidbounce.utils.aiming.Rotation
import net.ccbluex.liquidbounce.utils.aiming.RotationManager
import net.ccbluex.liquidbounce.utils.aiming.RotationsConfigurable
import net.ccbluex.liquidbounce.utils.entity.FallingPlayer
import net.ccbluex.liquidbounce.utils.item.convertClientSlotToServerSlot
import net.minecraft.client.gui.screen.ingame.InventoryScreen
import net.minecraft.entity.effect.StatusEffects
import net.minecraft.item.SplashPotionItem
import net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket
import net.minecraft.network.packet.c2s.play.CloseHandledScreenC2SPacket
import net.minecraft.network.packet.c2s.play.PlayerInteractItemC2SPacket
import net.minecraft.network.packet.c2s.play.UpdateSelectedSlotC2SPacket
import net.minecraft.potion.PotionUtil
import net.minecraft.screen.slot.SlotActionType
import net.minecraft.util.Hand
import org.apache.commons.lang3.RandomUtils

/**
* AutoPot module
*
* Automatically throws healing potions whenever your health is low.
*/

object ModuleAutoPot : Module("AutoPot", Category.COMBAT) {

private val delay by int("Delay", 10, 10..20)
private val health by int("Health", 18, 1..20)
private val tillGroundDistance by float("TillGroundDistance", 2f, 1f..5f)

val rotations = tree(RotationsConfigurable())

val repeatable = repeatable {
if (player.isDead) {
return@repeatable
}

val potHotBar = findPotion(0, 8)
val potInvSlot = findPotion(9, 40)

if (potHotBar == null && potInvSlot == null) {
return@repeatable
}

if (player.health < health) {
if (potHotBar != null) {
val collisionBlock = FallingPlayer.fromPlayer(player).findCollision(20)?.pos

if (player.y - (collisionBlock?.y ?: 0) > tillGroundDistance) {
return@repeatable
}

if (potHotBar != player.inventory.selectedSlot) {
network.sendPacket(UpdateSelectedSlotC2SPacket(potHotBar))
}

if (player.pitch <= 80) {
RotationManager.aimAt(
Rotation(player.yaw, RandomUtils.nextFloat(80f, 90f)),
configurable = rotations
)
}

// Using timer so as to avoid sword shield
wait(2)
network.sendPacket(PlayerInteractItemC2SPacket(Hand.MAIN_HAND))

if (potHotBar != player.inventory.selectedSlot) {
network.sendPacket(UpdateSelectedSlotC2SPacket(player.inventory.selectedSlot))
}

wait(delay)

return@repeatable
} else {
val serverSlot = convertClientSlotToServerSlot(potInvSlot!!)

val openInventory = mc.currentScreen !is InventoryScreen

if (openInventory) {
network.sendPacket(
ClientCommandC2SPacket(
player,
ClientCommandC2SPacket.Mode.OPEN_INVENTORY
)
)
}

interaction.clickSlot(0, serverSlot, 0, SlotActionType.QUICK_MOVE, player)

if (openInventory) {
network.sendPacket(CloseHandledScreenC2SPacket(0))
}

return@repeatable
}
}
}

private fun findPotion(startSlot: Int, endSlot: Int): Int? {
for (slot in startSlot..endSlot) {
val stack = player.inventory.getStack(slot)
if (stack.item is SplashPotionItem) {
for (effect in PotionUtil.getPotionEffects(stack)) {
if (effect.effectType == StatusEffects.INSTANT_HEALTH) {
return slot
}
}
}
}
return null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@ import net.ccbluex.liquidbounce.utils.item.convertClientSlotToServerSlot
import net.ccbluex.liquidbounce.utils.item.findHotbarSlot
import net.ccbluex.liquidbounce.utils.item.findInventorySlot
import net.minecraft.client.gui.screen.ingame.InventoryScreen
import net.minecraft.item.Item
import net.minecraft.item.Items
import net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket
import net.minecraft.network.packet.c2s.play.CloseHandledScreenC2SPacket
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket
import net.minecraft.network.packet.c2s.play.PlayerInteractItemC2SPacket
import net.minecraft.network.packet.c2s.play.*
import net.minecraft.screen.slot.SlotActionType
import net.minecraft.util.Hand
import net.minecraft.util.math.BlockPos
Expand All @@ -48,9 +44,6 @@ object ModuleAutoSoup : Module("AutoSoup", Category.COMBAT) {
private val bowl by enumChoice("Bowl", BowlMode.DROP, BowlMode.values())
private val health by int("Health", 18, 1..20)

private var lastSlot = -1
private var saveSlot = false

val repeatable = repeatable {
val mushroomStewSlot = findHotbarSlot(Items.MUSHROOM_STEW)

Expand All @@ -74,73 +67,56 @@ object ModuleAutoSoup : Module("AutoSoup", Category.COMBAT) {
Direction.DOWN
)
)
if (saveSlot) {
player.inventory.selectedSlot = lastSlot
saveSlot = false
}
network.sendPacket(UpdateSelectedSlotC2SPacket(player.inventory.selectedSlot))
when (bowl) {
BowlMode.DROP -> {
utilizeInventory(bowlHotbarSlot, 1, SlotActionType.THROW, false)
}
BowlMode.MOVE -> {
val openInventory = mc.currentScreen !is InventoryScreen

if (openInventory) {
network.sendPacket(ClientCommandC2SPacket(player, ClientCommandC2SPacket.Mode.OPEN_INVENTORY))
}

// If there is neither an empty slot nor an empty bowl, then replace whatever there is on slot 9
if (!player.inventory.getStack(9).isEmpty || player.inventory.getStack(9).item != Items.BOWL) {
utilizeInventory(bowlHotbarSlot, 0, SlotActionType.PICKUP, true)
utilizeInventory(9, 0, SlotActionType.PICKUP, true)
utilizeInventory(bowlHotbarSlot, 0, SlotActionType.PICKUP, false)
utilizeInventory(9, 0, SlotActionType.PICKUP, false)
utilizeInventory(bowlHotbarSlot, 0, SlotActionType.PICKUP, true)
} else {
// If there is, simply shift + click the empty bowl from hotbar
utilizeInventory(bowlHotbarSlot, 0, SlotActionType.QUICK_MOVE, true)
}

if (openInventory) {
network.sendPacket(CloseHandledScreenC2SPacket(0))
}
}
}
return@repeatable
}

if (player.health < health) {
if (mushroomStewSlot != null) {
if (!saveSlot) {
lastSlot = player.inventory.selectedSlot
saveSlot = true
if (mushroomStewSlot != player.inventory.selectedSlot) {
network.sendPacket(UpdateSelectedSlotC2SPacket(mushroomStewSlot))
}
player.inventory.selectedSlot = mushroomStewSlot
// Using timer so as to avoid sword shield
wait(2)
network.sendPacket(PlayerInteractItemC2SPacket(Hand.MAIN_HAND))
return@repeatable
} else {
// Search for the specific item in inventory and quick move it to hotbar
if (bowlInvSlot != null) {
utilizeInventory(bowlInvSlot, 0, SlotActionType.QUICK_MOVE, false)
utilizeInventory(bowlInvSlot, 0, SlotActionType.QUICK_MOVE, true)
}
return@repeatable
}
}
}

private fun utilizeInventory(slot: Int, button: Int, slotActionType: SlotActionType, onlyActions: Boolean) {
private fun utilizeInventory(slot: Int, button: Int, slotActionType: SlotActionType, close: Boolean) {
val serverSlot = convertClientSlotToServerSlot(slot)
val openInventory = mc.currentScreen !is InventoryScreen

if (!onlyActions) {
if (openInventory) {
network.sendPacket(ClientCommandC2SPacket(player, ClientCommandC2SPacket.Mode.OPEN_INVENTORY))
}
if (openInventory) {
network.sendPacket(ClientCommandC2SPacket(player, ClientCommandC2SPacket.Mode.OPEN_INVENTORY))
}

interaction.clickSlot(0, serverSlot, button, slotActionType, player)

if (!onlyActions) {
if (close) {
if (openInventory) {
network.sendPacket(CloseHandledScreenC2SPacket(0))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ object ModuleVelocity : Module("Velocity", Category.COMBAT) {
}

// Modify packet according to the specified values
packet.velocityX = (packet.velocityX * horizontal).toInt()
packet.velocityY = (packet.velocityY * vertical).toInt()
packet.velocityZ = (packet.velocityZ * horizontal).toInt()
packet.velocityX *= horizontal.toInt()
packet.velocityY *= vertical.toInt()
packet.velocityZ *= horizontal.toInt()
} else if (packet is ExplosionS2CPacket) { // Check if velocity is affected by explosion
// note: explosion packets are being used by hypixel to trick poorly made cheats.

Expand All @@ -85,9 +85,9 @@ object ModuleVelocity : Module("Velocity", Category.COMBAT) {
}

// Modify packet according to the specified values
packet.playerVelocityX = packet.playerVelocityX * horizontal
packet.playerVelocityY = packet.playerVelocityY * vertical
packet.playerVelocityZ = packet.playerVelocityZ * horizontal
packet.playerVelocityX *= horizontal
packet.playerVelocityY *= vertical
packet.playerVelocityZ *= horizontal
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/assets/liquidbounce/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@

"liquidbounce.module.sleepWalker.description": "Allows you to walk while sleeping, also makes your hitbox small.",

"liquidbounce.module.dankBobbing.description": "Adds more bobbing effect."
"liquidbounce.module.dankBobbing.description": "Adds more bobbing effect.",

"liquidbounce.module.autoPot.description": "Automatically throws healing potions whenever your health is low."

}

0 comments on commit 6b80723

Please sign in to comment.