Skip to content

Commit

Permalink
improvements
Browse files Browse the repository at this point in the history
* added sorting target: "Potion"
* added ItemStack.isSplashPotion(), replaced use of ItemPotion.isSplashPotion(stack.metadata) with it
* removed some commented out lines
* fixed stack trace printing
  • Loading branch information
CzechHek committed Sep 21, 2023
1 parent 5bc67ad commit 698a269
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 47 deletions.
Expand Up @@ -223,7 +223,7 @@ object ModuleManager : Listenable {
// TODO: Remove when stable
displayChatMessage("§cReworked coroutine inventory management has ran into an issue! Please report this: ${it.message}")

LOGGER.error(it.stackTrace)
it.printStackTrace()
}
}
}
Expand Down
Expand Up @@ -17,6 +17,7 @@ import net.ccbluex.liquidbounce.utils.PacketUtils.sendPackets
import net.ccbluex.liquidbounce.utils.Rotation
import net.ccbluex.liquidbounce.utils.RotationUtils.serverRotation
import net.ccbluex.liquidbounce.utils.RotationUtils.setTargetRotation
import net.ccbluex.liquidbounce.utils.item.isSplashPotion
import net.ccbluex.liquidbounce.utils.misc.FallingPlayer
import net.ccbluex.liquidbounce.utils.misc.RandomUtils.nextFloat
import net.ccbluex.liquidbounce.utils.timer.MSTimer
Expand Down Expand Up @@ -128,7 +129,7 @@ object AutoPot : Module("AutoPot", ModuleCategory.COMBAT) {
for (i in startSlot until endSlot) {
val stack = thePlayer.inventoryContainer.getSlot(i).stack

if (stack == null || stack.item !is ItemPotion || !ItemPotion.isSplash(stack.metadata))
if (stack == null || stack.item !is ItemPotion || !stack.isSplashPotion())
continue

val itemPotion = stack.item as ItemPotion
Expand Down
Expand Up @@ -2,7 +2,7 @@

package net.ccbluex.liquidbounce.features.module.modules.`fun`

import kotlinx.coroutines.*
import kotlinx.coroutines.delay
import net.ccbluex.liquidbounce.features.module.Module
import net.ccbluex.liquidbounce.features.module.ModuleCategory
import net.ccbluex.liquidbounce.features.module.modules.movement.InventoryMove
Expand All @@ -18,7 +18,9 @@ import net.ccbluex.liquidbounce.utils.timer.TimeUtils.randomDelay
import net.ccbluex.liquidbounce.value.BoolValue
import net.ccbluex.liquidbounce.value.IntegerValue
import net.ccbluex.liquidbounce.value.ListValue
import net.minecraft.block.*
import net.minecraft.block.BlockContainer
import net.minecraft.block.BlockFalling
import net.minecraft.block.BlockWorkbench
import net.minecraft.client.gui.inventory.GuiInventory
import net.minecraft.enchantment.Enchantment
import net.minecraft.init.Blocks
Expand Down Expand Up @@ -267,7 +269,7 @@ object CoroutineCleaner: Module("CoroutineCleaner", ModuleCategory.BETA) {
val item = stack?.item ?: return false

if (item is ItemPotion) {
val isSplash = ItemPotion.isSplash(stack.itemDamage)
val isSplash = stack.isSplashPotion()
val isHarmful = item.getEffects(stack).any { it.potionID in NEGATIVE_EFFECT_IDS }

// Only keep helpful potions and, if 'onlyGoodPotions' is disabled, also splash harmful potions
Expand Down Expand Up @@ -339,21 +341,6 @@ object CoroutineCleaner: Module("CoroutineCleaner", ModuleCategory.BETA) {
if (stack == otherStack || item.javaClass != otherItem.javaClass)
return@forEachIndexed

/*
if (canBeSortedTo(otherIndex, otherItem)) {
// If both items are already sorted, avoid getting into swapping loop
if (alreadySorted) return@forEachIndexed
for (i in 36..44) {
val hotbarItem = stacks[i]?.item
// If there is a different sortable slot, avoid getting into swapping loop?
if (hotbarItem == null && canBeSortedTo(i, item))
return@forEachIndexed
}
}
*/

val otherStats = parameters(otherStack)

val isOtherSorted = canBeSortedTo(otherIndex, otherItem, stacks.size)
Expand All @@ -366,7 +353,6 @@ object CoroutineCleaner: Module("CoroutineCleaner", ModuleCategory.BETA) {
1 -> return false
0 -> if (!isSorted && index < otherIndex)
return false
//0 -> return index < otherIndex
}
}
}
Expand Down Expand Up @@ -397,6 +383,7 @@ private val SORTING_TARGETS: Map<String, ((Item?) -> Boolean)?> = mapOf(
"Fire" to { it == Items.flint_and_steel || it == Items.lava_bucket || it == Items.bucket },
"Gapple" to { it is ItemAppleGold },
"Pearl" to { it is ItemEnderPearl },
"Potion" to { it is ItemPotion },
"Ignore" to null
)

Expand Down
Expand Up @@ -71,7 +71,7 @@ object CoroutineStealer : Module("CoroutineStealer", ModuleCategory.BETA) {

private var easingProgress = 0f

private var receivedId = 0
private var receivedId: Int? = null

private var stacks = emptyList<ItemStack?>()

Expand Down Expand Up @@ -160,20 +160,18 @@ object CoroutineStealer : Module("CoroutineStealer", ModuleCategory.BETA) {
.sortedBy { it.third == null }

run scheduler@ {
usefulItems.forEachIndexed { index, (slot, stack, sortableTo) ->
if (!shouldExecute()) {
progress = 0f
easingProgress = 0f
usefulItems.forEachIndexed { index, (slot, _, sortableTo) ->
if (!shouldExecute())
return
}

// TODO: might schedule clicks that exceed inventory space at low delays, it will notice that it doesn't have space in inventory next tick, when the scheduled click gets executed
// When stealing items by instantly sorting them, you don't need any space in inventory, yay
if (sortableTo == null && !hasSpaceInInventory())
return@scheduler

// If target is sortable to a hotbar slot, steal it right there, else shift + left-click
TickScheduler.scheduleClick(slot, sortableTo ?: 0, if (sortableTo != null) 2 else 1) {
progress = index / usefulItems.lastIndex.toFloat()
progress = (index + 1) / usefulItems.size.toFloat()
}

delay(randomDelay(minDelay, maxDelay).toLong())
Expand All @@ -182,6 +180,7 @@ object CoroutineStealer : Module("CoroutineStealer", ModuleCategory.BETA) {

// If no clicks were sent in the last loop
if (TickScheduler.isEmpty()) {
progress = 1f
delay(closeDelay.toLong())

break
Expand All @@ -194,13 +193,8 @@ object CoroutineStealer : Module("CoroutineStealer", ModuleCategory.BETA) {
stacks = thePlayer.openContainer.inventory
}

progress = 1f

TickScheduler += {
mc.thePlayer.closeScreen()

progress = 0f
easingProgress = 0f
}

// Wait before the chest gets closed (if it gets closed out of tick loop it could throw npe)
Expand All @@ -210,7 +204,7 @@ object CoroutineStealer : Module("CoroutineStealer", ModuleCategory.BETA) {
// Progress bar
@EventTarget
fun onRender2D(event: Render2DEvent) {
if (!progressBar || progress == 0f)
if (!progressBar || mc.currentScreen !is GuiChest)
return

val (scaledWidth, scaledHeight) = ScaledResolution(mc)
Expand All @@ -224,22 +218,23 @@ object CoroutineStealer : Module("CoroutineStealer", ModuleCategory.BETA) {

drawRect(minX - 2, minY - 2, maxX + 2, maxY + 2, Color(200, 200, 200).rgb)
drawRect(minX, minY, maxX, maxY, Color(50, 50, 50).rgb)
drawRect(
minX,
minY,
minX + (maxX - minX) * easingProgress,
maxY,
Color.HSBtoRGB(easingProgress / 5, 1f, 1f) or 0xFF0000
)
drawRect(minX, minY, minX + (maxX - minX) * easingProgress, maxY, Color.HSBtoRGB(easingProgress / 5, 1f, 1f) or 0xFF0000)
}

@EventTarget
fun onPacket(event: PacketEvent) {
val packet = event.packet

when (packet) {
is C0DPacketCloseWindow, is S2DPacketOpenWindow, is S2EPacketCloseWindow -> receivedId = 0
is C0DPacketCloseWindow, is S2DPacketOpenWindow, is S2EPacketCloseWindow -> receivedId = null
is S30PacketWindowItems -> {
// Chests never have windowId 0
if (packet.func_148911_c() == 0)
return

progress = 0f
easingProgress = 0f

receivedId = packet.func_148911_c()

stacks = packet.itemStacks.toList()
Expand Down
Expand Up @@ -13,6 +13,7 @@ import net.ccbluex.liquidbounce.utils.RotationUtils.targetRotation
import net.ccbluex.liquidbounce.utils.block.BlockUtils.getState
import net.ccbluex.liquidbounce.utils.extensions.toRadians
import net.ccbluex.liquidbounce.utils.extensions.toRadiansD
import net.ccbluex.liquidbounce.utils.item.isSplashPotion
import net.ccbluex.liquidbounce.utils.render.ColorUtils
import net.ccbluex.liquidbounce.utils.render.ColorUtils.interpolateHSB
import net.ccbluex.liquidbounce.utils.render.RenderUtils.disableGlCap
Expand Down Expand Up @@ -50,9 +51,9 @@ object Projectiles : Module("Projectiles", ModuleCategory.RENDER) {
val thePlayer = mc.thePlayer ?: return
val theWorld = mc.theWorld ?: return

val heldItem = thePlayer.heldItem ?: return
val heldStack = thePlayer.heldItem ?: return

val item = heldItem.item
val item = heldStack.item
val renderManager = mc.renderManager
var isBow = false
var motionFactor = 1.5F
Expand Down Expand Up @@ -83,7 +84,7 @@ object Projectiles : Module("Projectiles", ModuleCategory.RENDER) {
gravity = 0.04F
size = 0.25F
motionSlowdown = 0.92F
} else if (item is ItemPotion && ItemPotion.isSplash(mc.thePlayer.heldItem.itemDamage)) {
} else if (item is ItemPotion && heldStack.isSplashPotion()) {
gravity = 0.05F
size = 0.25F
motionFactor = 0.5F
Expand Down Expand Up @@ -111,7 +112,7 @@ object Projectiles : Module("Projectiles", ModuleCategory.RENDER) {
// Motions
var motionX = -sin(yawRadians) * cos(pitchRadians) * if (isBow) 1.0 else 0.4
var motionY = -sin(
(pitch + if (item is ItemPotion && ItemPotion.isSplash(mc.thePlayer.heldItem.itemDamage)) -20 else 0).toRadians()
(pitch + if (item is ItemPotion && heldStack.isSplashPotion()) -20 else 0).toRadians()
) * if (isBow) 1.0 else 0.4
var motionZ = cos(yawRadians) * cos(pitchRadians) * if (isBow) 1.0 else 0.4
val distance = sqrt(motionX * motionX + motionY * motionY + motionZ * motionZ)
Expand Down
Expand Up @@ -125,4 +125,6 @@ fun ItemStack?.hasItemDelayPassed(delay: Int) = this == null

val ItemStack.attackDamage
get() = (attributeModifiers["generic.attackDamage"].firstOrNull()?.amount ?: 0.0) +
1.25 * getEnchantmentLevel(Enchantment.sharpness)
1.25 * getEnchantmentLevel(Enchantment.sharpness)

fun ItemStack.isSplashPotion()= item is ItemPotion && ItemPotion.isSplash(this.metadata)

0 comments on commit 698a269

Please sign in to comment.