Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(nextgen): SmartEat #1766

Merged
merged 68 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
7b12026
Update theme
Ell1ott Feb 5, 2022
fedb9a2
Update theme
Ell1ott Feb 5, 2022
aee4508
white design
Ell1ott Feb 6, 2022
e0d76d6
Update theme
Ell1ott Feb 10, 2022
4d9dd41
Update theme
Ell1ott Feb 10, 2022
fcdbe7d
Update theme
Ell1ott Feb 12, 2022
0b9e5ed
Update theme
Ell1ott Feb 13, 2022
2cf2ad1
Update theme
Ell1ott Feb 14, 2022
18523e5
added moduleS
Ell1ott Mar 20, 2022
0dd5cd6
Update theme
Ell1ott Mar 20, 2022
f29def9
Update ModuleAimbot.kt
Jun 28, 2022
24a08cb
Merge branch 'nextgen' of https://github.com/CCBlueX/LiquidBounce int…
Jun 28, 2022
d8b3c79
Merge branch 'nextgen' of https://github.com/Ell1ott/LiquidBounce int…
Jun 28, 2022
16405f8
Update theme
Jun 30, 2022
8da283a
Merge branch 'nextgen' of https://github.com/Ell1ott/LiquidBounce int…
Jun 30, 2022
48ceb3a
Update theme
Jun 30, 2022
93349a7
Update theme
Jul 31, 2022
b0ccc7a
fixed bow aimbot
Ell1ott May 31, 2023
e4813f8
Merge branch 'nextgen' of https://github.com/Ell1ott/LiquidBounce int…
Ell1ott May 31, 2023
4688e79
Revert "Merge branch 'nextgen' of https://github.com/Ell1ott/LiquidBo…
Ell1ott May 31, 2023
85eb491
Merge remote-tracking branch 'upstream/nextgen' into nextgen
Ell1ott May 31, 2023
82e3b47
armor comparitor settings
Ell1ott May 31, 2023
1612e25
added toolassword option
Ell1ott May 31, 2023
58e58b6
Update .gitignore
Ell1ott May 31, 2023
9947da4
Merge pull request #1 from Ell1ott/inventory-cleaner-fix
Ell1ott May 31, 2023
0d0f09b
Merge branch 'nextgen' of https://github.com/Ell1ott/LiquidBounce int…
Ell1ott May 31, 2023
173b5d6
enchantment factors settings
Ell1ott Jun 1, 2023
e70c0c9
fixed errors
Ell1ott Jun 5, 2023
42c1fff
Merge remote-tracking branch 'upstream/nextgen' into nextgen
Ell1ott Sep 14, 2023
685a95a
add smart eat module
Ell1ott Dec 28, 2023
6e5ad41
make the module work
Ell1ott Dec 28, 2023
c693778
use event
Ell1ott Dec 29, 2023
c3e03c8
add prefer options
Ell1ott Dec 31, 2023
226eced
update deafult values
Ell1ott Dec 31, 2023
aa8df95
Merge branch 'nextgen' into smart-eat-fixed
Ell1ott Jan 9, 2024
90812df
add autoEat
Ell1ott Jan 9, 2024
5e4c150
fix some mixins
Ell1ott Jan 11, 2024
fdfe6d2
Merge branch 'bartione-comp' into smart-eat-fixed
Ell1ott Jan 11, 2024
d24e38a
make auto eat work
Ell1ott Jan 11, 2024
aff91a0
Revert "fix some mixins"
Ell1ott Jan 11, 2024
4f5e426
formatting
Ell1ott Jan 11, 2024
83b65bd
use HotbarItemSlot
Ell1ott Jan 13, 2024
56b349d
use new slot handling
Ell1ott Jan 13, 2024
bce2f53
Merge branch 'nextgen' into smart-eat-fixed
Ell1ott Jan 14, 2024
fd363c2
Update ModuleIgnite.kt
Ell1ott Jan 14, 2024
8f6bd55
Merge branch 'nextgen' into smart-eat-fixed
Ell1ott Jan 14, 2024
190be5e
add documentation
Ell1ott Jan 19, 2024
51232e7
added getItemScore function to clean code up
Ell1ott Jan 19, 2024
221b9dc
rename prefers
Ell1ott Jan 19, 2024
9aff3c8
Merge branch 'nextgen' into smart-eat-fixed
Ell1ott Jan 19, 2024
80030f5
addd missed return
Ell1ott Jan 19, 2024
572b557
Merge branch 'nextgen' into smart-eat-fixed
Ell1ott Jan 25, 2024
8c4ebfa
Update ModuleSmartEat.kt
Ell1ott Jan 25, 2024
025a87f
Merge branch 'nextgen' into smart-eat-fixed
Ell1ott Feb 5, 2024
76a9131
reset gitignore
Ell1ott Feb 5, 2024
75311e4
reset some things
Ell1ott Feb 5, 2024
0bbbae4
Update ModuleManager.kt
Ell1ott Feb 5, 2024
6ec2cc0
inventory cleaner merge fix
Ell1ott Feb 5, 2024
51cb692
Update ModuleManager.kt
Ell1ott Feb 5, 2024
7c8de28
migrate to improved Configurable system
Ell1ott Feb 5, 2024
6891cd7
Suppress "ReturnCount"
Ell1ott Feb 5, 2024
d58fb9a
Merge branch 'nextgen' into smart-eat-fixed
Ell1ott Feb 22, 2024
1ad9b2c
remove empty lines
Ell1ott Feb 22, 2024
d8e160c
Update MixinClientPlayerInteractionManager.java
Ell1ott Feb 22, 2024
9caa8ab
Improve comparison
superblaubeere27 Feb 26, 2024
19f37dc
Fixed comparison
superblaubeere27 Feb 27, 2024
03edff3
Merge branch 'nextgen' into smart-eat-fixed
superblaubeere27 Mar 9, 2024
7586785
Improved a few last things
superblaubeere27 Mar 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,23 @@
import net.ccbluex.liquidbounce.event.events.AttackEvent;
import net.ccbluex.liquidbounce.event.events.BlockBreakingProgressEvent;
import net.ccbluex.liquidbounce.event.events.CancelBlockBreakingEvent;
import net.ccbluex.liquidbounce.event.events.PlayerInteractedItem;
import net.ccbluex.liquidbounce.event.events.GameModeChangeEvent;
import net.ccbluex.liquidbounce.features.module.modules.combat.ModuleAutoBow;
import net.ccbluex.liquidbounce.features.module.modules.combat.ModuleAutoClicker;
import net.ccbluex.liquidbounce.features.module.modules.combat.ModuleSmartEat;
import net.ccbluex.liquidbounce.features.module.modules.player.ModuleReach;
import net.ccbluex.liquidbounce.utils.aiming.Rotation;
import net.ccbluex.liquidbounce.utils.aiming.RotationManager;
import net.ccbluex.liquidbounce.utils.client.SilentHotbar;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.network.ClientPlayerInteractionManager;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.GameMode;
Expand Down Expand Up @@ -123,6 +129,12 @@ private void hookFixRotation(Args args) {
args.set(4, rotation.getPitch());
}

@Inject(method = "interactItem", at = @At("RETURN"))
private void hookItemInteract(PlayerEntity player, Hand hand, CallbackInfoReturnable<ActionResult> cir) {
final PlayerInteractedItem cancelEvent = new PlayerInteractedItem(player, hand, cir.getReturnValue());
EventManager.INSTANCE.callEvent(cancelEvent);
}

@Inject(method = "stopUsingItem", at = @At("HEAD"))
private void stopUsingItem(PlayerEntity player, CallbackInfo callbackInfo) {
ModuleAutoBow.onStopUsingItem();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ val ALL_EVENT_CLASSES: Array<KClass<out Event>> = arrayOf(
PlayerJumpEvent::class,
PlayerAfterJumpEvent::class,
PlayerUseMultiplier::class,
PlayerInteractedItem::class,
PlayerVelocityStrafe::class,
PlayerStrideEvent::class,
PlayerSafeWalkEvent::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import net.ccbluex.liquidbounce.event.EventState
import net.ccbluex.liquidbounce.utils.client.Nameable
import net.ccbluex.liquidbounce.web.socket.protocol.event.WebSocketEvent
import net.minecraft.entity.MovementType
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.util.ActionResult
import net.minecraft.util.Hand
import net.minecraft.util.math.Vec3d

// Entity events bound to client-user entity
Expand Down Expand Up @@ -66,6 +69,9 @@ class PlayerAfterJumpEvent : Event()
@Nameable("playerUseMultiplier")
class PlayerUseMultiplier(var forward: Float, var sideways: Float) : Event()

@Nameable("playerInteractedItem")
class PlayerInteractedItem(val player: PlayerEntity, val hand: Hand, val actionResult: ActionResult) : Event()

@Nameable("playerStrafe")
class PlayerVelocityStrafe(val movementInput: Vec3d, val speed: Float, val yaw: Float, var velocity: Vec3d) : Event()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ import net.ccbluex.liquidbounce.features.module.modules.movement.step.ModuleStep
import net.ccbluex.liquidbounce.features.module.modules.movement.terrainspeed.ModuleTerrainSpeed
import net.ccbluex.liquidbounce.features.module.modules.player.*
import net.ccbluex.liquidbounce.features.module.modules.player.autoplay.ModuleAutoPlay
import net.ccbluex.liquidbounce.features.module.modules.player.chestStealer.ModuleChestStealer
import net.ccbluex.liquidbounce.features.module.modules.player.invcleaner.ModuleInventoryCleaner
import net.ccbluex.liquidbounce.features.module.modules.player.nofall.ModuleNoFall
import net.ccbluex.liquidbounce.features.module.modules.player.invcleaner.ModuleInventoryCleaner
import net.ccbluex.liquidbounce.features.module.modules.render.*
import net.ccbluex.liquidbounce.features.module.modules.render.murdermystery.ModuleMurderMystery
import net.ccbluex.liquidbounce.features.module.modules.render.nametags.ModuleNametags
Expand Down Expand Up @@ -197,7 +196,6 @@ object ModuleManager : Listenable, Iterable<Module> by modules {
ModuleAutoTotem,
ModuleAutoWalk,
ModuleBlink,
ModuleChestStealer,
ModuleEagle,
ModuleFastUse,
ModuleInventoryCleaner,
Expand All @@ -207,6 +205,7 @@ object ModuleManager : Listenable, Iterable<Module> by modules {
ModuleRegen,
ModuleZoot,
ModuleAutoPlay,
ModuleSmartEat,

// Render
ModuleAnimations,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
/*
* This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce)
*
* Copyright (c) 2015 - 2023 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.config.ToggleableConfigurable
import net.ccbluex.liquidbounce.event.events.OverlayRenderEvent
import net.ccbluex.liquidbounce.event.events.PlayerInteractedItem
import net.ccbluex.liquidbounce.event.handler
import net.ccbluex.liquidbounce.event.repeatable
import net.ccbluex.liquidbounce.features.module.Category
import net.ccbluex.liquidbounce.features.module.Module
import net.ccbluex.liquidbounce.features.module.modules.player.invcleaner.HotbarItemSlot
import net.ccbluex.liquidbounce.render.renderEnvironmentForGUI
import net.ccbluex.liquidbounce.utils.client.SilentHotbar
import net.ccbluex.liquidbounce.utils.item.Hotbar
import net.ccbluex.liquidbounce.utils.sorting.ComparatorChain
import net.ccbluex.liquidbounce.utils.sorting.compareByCondition
import net.minecraft.client.gui.DrawContext
import net.minecraft.client.option.KeyBinding
import net.minecraft.entity.effect.StatusEffects
import net.minecraft.item.ItemStack
import net.minecraft.item.Items
import net.minecraft.potion.PotionUtil
import net.minecraft.util.ActionResult
import net.minecraft.util.Identifier
import net.minecraft.util.UseAction
import kotlin.math.absoluteValue
import kotlin.math.max

/**
* SmartEat module
*
* Makes it easier to eat
*/

object ModuleSmartEat : Module("SmartEat", Category.PLAYER) {
private val HOTBAR_OFFHAND_LEFT_TEXTURE = Identifier("hud/hotbar_offhand_left")

This comment was marked as resolved.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs some attention from the Frontend :o @SenkJu


private val swapBackDelay by int("SwapBackDelay", 5, 1..20)

private val preferGappleHealth by float("PreferGappleHealthThreshold", 9f, 0f..20f)
private val preferNotchAppleHealth by float("PreferNotchAppleHealthThreshold", 2f, 0f..20f)
private val preferHealthPotHealth by float("PreferHealthPotHealthThreshold", 12f, 0f..20f)

private object Estimator {
fun findBestFood(): HotbarItemSlot? {
val comparator = ComparatorChain<Pair<HotbarItemSlot, FoodEstimationData>>(
// If there is an indication for a special item, we should use it. Items with lower health threshold
// are preferred since their usage is probably more urgent.
compareByDescending { it.second.healthThreshold },
compareBy { it.second.restoredHunger },
// Use the closest slot
compareByDescending { (it.first.hotbarSlot - SilentHotbar.serversideSlot).absoluteValue },
// Just for stabilization reasons
compareBy { SilentHotbar.serversideSlot }
)

return Hotbar.slots
.mapNotNull { slot -> getFoodEstimationData(slot.itemStack)?.let { slot to it } }
.maxWithOrNull(comparator)?.first
}

private class FoodEstimationData(val restoredHunger: Int = 0, val healthThreshold: Int = 20)

private fun getFoodEstimationData(itemStack: ItemStack): FoodEstimationData? {
val item = itemStack.item

val prefersGapples = player.health <= preferGappleHealth
val prefersNotchApple = player.health <= preferNotchAppleHealth
val prefersHealthPot = player.health <= preferHealthPotHealth

return when {
prefersGapples && item == Items.POTION -> {
val hasHealthEffect =
PotionUtil.getPotionEffects(itemStack).any {
it.effectType == StatusEffects.INSTANT_HEALTH
}

if (hasHealthEffect)
FoodEstimationData(healthThreshold = preferHealthPotHealth.toInt())
else
null
}
prefersHealthPot && item == Items.GOLDEN_APPLE -> {
FoodEstimationData(
healthThreshold = preferHealthPotHealth.toInt(),
restoredHunger = item.foodComponent!!.hunger
)
}
prefersNotchApple && item == Items.ENCHANTED_GOLDEN_APPLE -> {
FoodEstimationData(
healthThreshold = preferNotchAppleHealth.toInt(),
restoredHunger = item.foodComponent!!.hunger
)
}
item.foodComponent != null -> FoodEstimationData(restoredHunger = item.foodComponent!!.hunger)
else -> null
}
}
}

private object SilentOffhand : ToggleableConfigurable(this, "SilentOffhand", true) {
private object RenderSlot : ToggleableConfigurable(this, "RenderSlot", true) {
private val offset by int("Offset", 26, 0..40)
val renderHandler = handler<OverlayRenderEvent> {
renderEnvironmentForGUI {
// MC-Rendering code for off-hand

val currentFood = Estimator.findBestFood() ?: return@renderEnvironmentForGUI
val dc = DrawContext(mc, mc.bufferBuilders.entityVertexConsumers)
val scaledWidth = dc.scaledWindowWidth
val scaledHeight = dc.scaledWindowHeight
val i: Int = scaledWidth / 2
val x = i - 91 - 26 - offset
val y = scaledHeight - 16 - 3
dc.drawItemInSlot(mc.textRenderer, currentFood.itemStack, x, y)
dc.drawItem(currentFood.itemStack, x, y)
dc.drawGuiTexture(
HOTBAR_OFFHAND_LEFT_TEXTURE, i - 91 - 29 - offset,
scaledHeight - 23, 29, 24
)
}
}
}

val InteractionHandler = handler<PlayerInteractedItem> { event ->
if (!enabled)
return@handler
if (event.actionResult != ActionResult.PASS)
return@handler

val currentFood = Estimator.findBestFood() ?: return@handler

val alwaysEdible = currentFood.itemStack.item.foodComponent?.isAlwaysEdible == false

if (!player.canConsume(false) && alwaysEdible) {
return@handler
}

SilentHotbar.selectSlotSilently(
this@SilentOffhand,
currentFood.hotbarSlot,
swapBackDelay.coerceAtLeast(5)
)
}

val tickHandler = repeatable {
val useAction = player.activeItem.useAction

if (useAction != UseAction.EAT && useAction != UseAction.DRINK)
return@repeatable
if (!SilentHotbar.isSlotModified(this@SilentOffhand))
return@repeatable

// if we are already eating, we want to keep the silent slot
SilentHotbar.selectSlotSilently(this@SilentOffhand, SilentHotbar.serversideSlot, swapBackDelay)
}

init {
tree(RenderSlot)
}
}

private object AutoEat : ToggleableConfigurable(this, "AutoEat", true) {
private val minHunger by int("MinHunger", 15, 0..20)

private val tickHandler = repeatable {

if (player.hungerManager.foodLevel < minHunger) {
waitUntil {
eat()
player.hungerManager.foodLevel > minHunger
}

KeyBinding.setKeyPressed(mc.options.useKey.boundKey, false)
}
}

fun eat() {
val currentBestFood = Estimator.findBestFood() ?: return

SilentHotbar.selectSlotSilently(AutoEat, currentBestFood.hotbarSlot, swapBackDelay)

KeyBinding.setKeyPressed(mc.options.useKey.boundKey, true)
}
}


init {
tree(SilentOffhand)
tree(AutoEat)
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ internal object NoFallMLG : Choice("MLG") {

val options = BlockPlacementTargetFindingOptions(
listOf(Vec3i(0, 0, 0)),
player.inventory.getStack(itemForMLG!!),
itemForMLG!!.itemStack,
CenterTargetPositionFactory,
BlockPlacementTargetFindingOptions.PRIORITIZE_LEAST_BLOCK_DISTANCE,
player.pos
Expand Down Expand Up @@ -106,7 +106,7 @@ internal object NoFallMLG : Choice("MLG") {
}

val item = itemForMLG ?: return@repeatable
SilentHotbar.selectSlotSilently(this, item, 1)
SilentHotbar.selectSlotSilently(this, item.hotbarSlotForServer, 1)

doPlacement(rayTraceResult)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ internal object NoFallRettungsplatform : Choice("Rettungsplatform") {
return@repeatable
}

useHotbarSlotOrOffhand(HotbarItemSlot(itemToPlatform))
useHotbarSlotOrOffhand(itemToPlatform)

// Wait 5 seconds
waitTicks(20 * 5)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ object ModuleIgnite : Module("Ignite", Category.WORLD) {

val options = BlockPlacementTargetFindingOptions(
listOf(Vec3i(0, 0, 0)),
player.inventory.getStack(slot),
slot.itemStack,
CenterTargetPositionFactory,
BlockPlacementTargetFindingOptions.PRIORITIZE_LEAST_BLOCK_DISTANCE,
player.pos
Expand Down Expand Up @@ -133,7 +133,7 @@ object ModuleIgnite : Module("Ignite", Category.WORLD) {

CombatManager.pauseCombatForAtLeast(1)

SilentHotbar.selectSlotSilently(this, slot, 1)
SilentHotbar.selectSlotSilently(this, slot.hotbarSlotForServer, 1)

doPlacement(raycast, Hand.MAIN_HAND)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ object ModuleAutoFarm : Module("AutoFarm", Category.WORLD) {

item ?: return@repeatable

SilentHotbar.selectSlotSilently(this, item, AutoPlaceCrops.swapBackDelay.random())
SilentHotbar.selectSlotSilently(this, item.hotbarSlotForServer, AutoPlaceCrops.swapBackDelay.random())
doPlacement(rayTraceResult)

waitTicks(interactDelay.random())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ object SilentHotbar : Listenable {
}
}

/**
* Returns if the slot is currently getting modified by a given requester
*/
fun isSlotModified(requester: Any?) = hotbarState?.requester == requester

val tickHandler = handler<GameTickEvent>(priority = 1001) {
val hotbarState = hotbarState ?: return@handler

Expand Down
Loading
Loading