From 1101e84e8d9b49fdb542fe3c7759838c705fb305 Mon Sep 17 00:00:00 2001 From: DesiCow Date: Sat, 4 Feb 2023 21:41:59 +0530 Subject: [PATCH] Better Auto Eat threshold Select "health", "hunger", "any", "both" thresholds to trigger auto eat. --- .../systems/modules/player/AutoEat.java | 49 +++++++++++++++++-- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoEat.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoEat.java index 57725b8cd8..2ed7a92a6c 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoEat.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoEat.java @@ -26,12 +26,13 @@ import java.util.ArrayList; import java.util.List; +import java.util.function.BiPredicate; public class AutoEat extends Module { private static final Class[] AURAS = new Class[] { KillAura.class, CrystalAura.class, AnchorAura.class, BedAura.class }; private final SettingGroup sgGeneral = settings.getDefaultGroup(); - private final SettingGroup sgHunger = settings.createGroup("Hunger"); + private final SettingGroup sgThreshold = settings.createGroup("Threshold"); // General @@ -67,14 +68,32 @@ public class AutoEat extends Module { .build() ); - // Hunger + // Threshold - private final Setting hungerThreshold = sgHunger.add(new IntSetting.Builder() + private final Setting thresholdMode = sgThreshold.add(new EnumSetting.Builder() + .name("threshold-mode") + .description("The threshold mode to trigger auto eat.") + .defaultValue(ThresholdMode.Any) + .build() + ); + + private final Setting healthThreshold = sgThreshold.add(new DoubleSetting.Builder() + .name("health-threshold") + .description("The level of health you eat at.") + .defaultValue(10) + .range(1, 19) + .sliderRange(1, 19) + .visible(() -> thresholdMode.get() != ThresholdMode.Hunger) + .build() + ); + + private final Setting hungerThreshold = sgThreshold.add(new IntSetting.Builder() .name("hunger-threshold") .description("The level of hunger you eat at.") .defaultValue(16) .range(1, 19) .sliderRange(1, 19) + .visible(() -> thresholdMode.get() != ThresholdMode.Health) .build() ); @@ -207,8 +226,11 @@ private void changeSlot(int slot) { this.slot = slot; } - private boolean shouldEat() { - return mc.player.getHungerManager().getFoodLevel() <= hungerThreshold.get(); + public boolean shouldEat() { + boolean health = mc.player.getHealth() <= healthThreshold.get(); + boolean hunger = mc.player.getHungerManager().getFoodLevel() <= hungerThreshold.get(); + + return thresholdMode.get().test(health, hunger); } private int findSlot() { @@ -237,4 +259,21 @@ private int findSlot() { return slot; } + + public enum ThresholdMode { + Health((health, hunger) -> health), + Hunger((health, hunger) -> hunger), + Any((health, hunger) -> health || hunger), + Both((health, hunger) -> health && hunger); + + private final BiPredicate predicate; + + ThresholdMode(BiPredicate predicate) { + this.predicate = predicate; + } + + public boolean test(boolean health, boolean hunger) { + return predicate.test(health, hunger); + } + } }