mirror of https://github.com/kami-blue/client
[fix] AutoEat places block after eating
This commit is contained in:
parent
7e763ffb2f
commit
bbf7d0fae1
|
@ -9,6 +9,7 @@ import me.zeroeightsix.kami.util.BaritoneUtils.pause
|
||||||
import me.zeroeightsix.kami.util.BaritoneUtils.unpause
|
import me.zeroeightsix.kami.util.BaritoneUtils.unpause
|
||||||
import me.zeroeightsix.kami.util.combat.CombatUtils
|
import me.zeroeightsix.kami.util.combat.CombatUtils
|
||||||
import me.zeroeightsix.kami.util.items.*
|
import me.zeroeightsix.kami.util.items.*
|
||||||
|
import me.zeroeightsix.kami.util.threads.runSafe
|
||||||
import me.zeroeightsix.kami.util.threads.safeListener
|
import me.zeroeightsix.kami.util.threads.safeListener
|
||||||
import net.minecraft.client.settings.KeyBinding
|
import net.minecraft.client.settings.KeyBinding
|
||||||
import net.minecraft.init.Items
|
import net.minecraft.init.Items
|
||||||
|
@ -25,8 +26,8 @@ object AutoEat : Module(
|
||||||
description = "Automatically eat when hungry",
|
description = "Automatically eat when hungry",
|
||||||
category = Category.PLAYER
|
category = Category.PLAYER
|
||||||
) {
|
) {
|
||||||
private val foodLevel by setting("BelowHunger", 15, 1..20, 1)
|
private val belowHunger by setting("BelowHunger", 15, 1..20, 1)
|
||||||
private val healthLevel by setting("BelowHealth", 10, 1..20, 1)
|
private val belowHealth by setting("BelowHealth", 10, 1..20, 1)
|
||||||
private val eatBadFood by setting("EatBadFood", false)
|
private val eatBadFood by setting("EatBadFood", false)
|
||||||
private val pauseBaritone by setting("PauseBaritone", true)
|
private val pauseBaritone by setting("PauseBaritone", true)
|
||||||
|
|
||||||
|
@ -35,101 +36,90 @@ object AutoEat : Module(
|
||||||
|
|
||||||
init {
|
init {
|
||||||
onDisable {
|
onDisable {
|
||||||
unpause()
|
stopEating()
|
||||||
eating = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
safeListener<TickEvent.ClientTickEvent> { event ->
|
safeListener<TickEvent.ClientTickEvent> {
|
||||||
if (CombatSetting.isActive()) return@safeListener
|
if (it.phase != TickEvent.Phase.START || CombatSetting.isActive()) return@safeListener
|
||||||
|
|
||||||
if (eating) {
|
if (shouldEat()) {
|
||||||
if (!player.isHandActive && event.phase == TickEvent.Phase.END) stopEating()
|
if (isValid(player.heldItemOffhand)) {
|
||||||
return@safeListener
|
eat(EnumHand.OFF_HAND)
|
||||||
}
|
} else if (swapToFood()) {
|
||||||
|
eat(EnumHand.MAIN_HAND)
|
||||||
if (event.phase != TickEvent.Phase.START) return@safeListener
|
}
|
||||||
|
} else if (eating) {
|
||||||
if (isValid(player.heldItemOffhand)) {
|
stopEating()
|
||||||
startEating(EnumHand.OFF_HAND)
|
|
||||||
} else if (swapToFood()) {
|
|
||||||
startEating(EnumHand.MAIN_HAND)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun SafeClientEvent.swapToFood(): Boolean {
|
private fun SafeClientEvent.shouldEat() =
|
||||||
lastSlot = player.inventory.currentItem
|
player.foodStats.foodLevel < belowHunger
|
||||||
|
|| CombatUtils.getHealthSmart(player) < belowHealth
|
||||||
|
|
||||||
val hasFoodInSlot = swapToItem<ItemFood> { isValid(it) }
|
private fun SafeClientEvent.eat(hand: EnumHand) {
|
||||||
|
if (pauseBaritone) pause()
|
||||||
|
|
||||||
if (!hasFoodInSlot) {
|
KeyBinding.setKeyBindState(mc.gameSettings.keyBindUseItem.keyCode, true)
|
||||||
lastSlot = -1
|
playerController.processRightClick(player, world, hand)
|
||||||
|
|
||||||
val slotFrom = player.storageSlots.firstItem<ItemFood, Slot> {
|
eating = true
|
||||||
isValid(it)
|
|
||||||
} ?: return false
|
|
||||||
|
|
||||||
moveToHotbar(slotFrom) {
|
|
||||||
val item = it.item
|
|
||||||
item !is ItemTool && item !is ItemBlock
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun SafeClientEvent.stopEating() {
|
private fun stopEating() {
|
||||||
if (lastSlot != -1) {
|
unpause()
|
||||||
swapToSlot(lastSlot)
|
|
||||||
lastSlot = -1
|
runSafe {
|
||||||
|
if (lastSlot != -1) {
|
||||||
|
swapToSlot(lastSlot)
|
||||||
|
lastSlot = -1
|
||||||
|
}
|
||||||
|
KeyBinding.setKeyBindState(mc.gameSettings.keyBindUseItem.keyCode, false)
|
||||||
|
playerController.onStoppedUsingItem(player)
|
||||||
}
|
}
|
||||||
|
|
||||||
eating = false
|
eating = false
|
||||||
unpause()
|
|
||||||
|
|
||||||
KeyBinding.setKeyBindState(mc.gameSettings.keyBindUseItem.keyCode, false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun SafeClientEvent.startEating(hand: EnumHand) {
|
private fun SafeClientEvent.swapToFood(): Boolean {
|
||||||
if (pauseBaritone && !eating) {
|
if (isValid(player.heldItemMainhand)) return true
|
||||||
pause()
|
|
||||||
|
lastSlot = player.inventory.currentItem
|
||||||
|
val hasFoodInSlot = swapToItem<ItemFood> { isValid(it) }
|
||||||
|
|
||||||
|
return if (!hasFoodInSlot) {
|
||||||
|
lastSlot = -1
|
||||||
|
moveFoodToHotbar()
|
||||||
|
false
|
||||||
|
} else {
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
player.activeHand = hand
|
|
||||||
|
|
||||||
eating = true
|
|
||||||
KeyBinding.setKeyBindState(mc.gameSettings.keyBindUseItem.keyCode, true)
|
|
||||||
playerController.processRightClick(player, world, hand)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun SafeClientEvent.isValid(stack: ItemStack): Boolean {
|
private fun SafeClientEvent.moveFoodToHotbar() {
|
||||||
val item = stack.item
|
val slotFrom = player.storageSlots.firstItem<ItemFood, Slot> {
|
||||||
if (item !is ItemFood) return false
|
isValid(it)
|
||||||
|
} ?: return
|
||||||
|
|
||||||
return passItemCheck(stack) && (player.foodStats.foodLevel < foodLevel
|
moveToHotbar(slotFrom) {
|
||||||
|| CombatUtils.getHealthSmart(player) < healthLevel)
|
val item = it.item
|
||||||
}
|
item !is ItemTool && item !is ItemBlock
|
||||||
|
|
||||||
private fun passItemCheck(stack: ItemStack): Boolean {
|
|
||||||
val item = stack.item
|
|
||||||
|
|
||||||
// Excluded Chorus Fruit since it is mainly used to teleport the player
|
|
||||||
if (item == Items.CHORUS_FRUIT) {
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The player will not auto eat the food below if the EatBadFood setting is disabled
|
|
||||||
if (!eatBadFood && (item == Items.ROTTEN_FLESH
|
|
||||||
|| item == Items.SPIDER_EYE
|
|
||||||
|| item == Items.POISONOUS_POTATO
|
|
||||||
|| (item == Items.FISH && (stack.metadata == 3 || stack.metadata == 2)) // Puffer fish, Clown fish
|
|
||||||
|| item == Items.CHORUS_FRUIT)) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// If EatBadFood is enabled, just allow them to eat it
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun isValid(itemStack: ItemStack): Boolean {
|
||||||
|
val item = itemStack.item
|
||||||
|
|
||||||
|
return item is ItemFood
|
||||||
|
&& item != Items.CHORUS_FRUIT
|
||||||
|
&& (eatBadFood || !isBadFood(itemStack, item))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isBadFood(itemStack: ItemStack, item: ItemFood) =
|
||||||
|
item == Items.ROTTEN_FLESH
|
||||||
|
|| item == Items.SPIDER_EYE
|
||||||
|
|| item == Items.POISONOUS_POTATO
|
||||||
|
|| item == Items.FISH && (itemStack.metadata == 3 || itemStack.metadata == 2) // Puffer fish, Clown fish
|
||||||
}
|
}
|
Loading…
Reference in New Issue