From 429c320b5baf0dd41696755f08a0efc007e7e608 Mon Sep 17 00:00:00 2001 From: uxmlen <38371923+uxmlen@users.noreply.github.com> Date: Mon, 5 May 2025 14:36:11 +0300 Subject: [PATCH 1/3] fix: AutoEat not switching slots when food runs out Fixed condition that checks for food in current slot to allow switching when food is depleted. --- .../meteorclient/systems/modules/player/AutoEat.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 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 6965b1a14d..39c03e2e7e 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoEat.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoEat.java @@ -124,18 +124,18 @@ private void onTick(TickEvent.Pre event) { // If we are eating check if we should still be eating if (shouldEat()) { // Check if the item in current slot is not food - if (mc.player.getInventory().getStack(slot).get(DataComponentTypes.FOOD) != null) { + if (mc.player.getInventory().getStack(slot).get(DataComponentTypes.FOOD) == null) { // If not try finding a new slot - int slot = findSlot(); + int newSlot = findSlot(); // If no valid slot was found then stop eating - if (slot == -1) { + if (newSlot == -1) { stopEating(); return; } // Otherwise change to the new slot else { - changeSlot(slot); + changeSlot(newSlot); } } From d6fedcc9e5f3bf4242d4a49c6c603536966dbb3f Mon Sep 17 00:00:00 2001 From: uxmlen <38371923+uxmlen@users.noreply.github.com> Date: Mon, 5 May 2025 14:46:52 +0300 Subject: [PATCH 2/3] refactor: reduced nesting --- .../systems/modules/player/AutoEat.java | 66 +++++++++---------- 1 file changed, 32 insertions(+), 34 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 39c03e2e7e..945414850c 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoEat.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoEat.java @@ -34,11 +34,11 @@ public class AutoEat extends Module { @SuppressWarnings("unchecked") private static final Class[] AURAS = new Class[]{KillAura.class, CrystalAura.class, AnchorAura.class, BedAura.class}; + // Settings groups private final SettingGroup sgGeneral = settings.getDefaultGroup(); private final SettingGroup sgThreshold = settings.createGroup("Threshold"); // General - public final Setting> blacklist = sgGeneral.add(new ItemListSetting.Builder() .name("blacklist") .description("Which items to not eat.") @@ -72,7 +72,6 @@ public class AutoEat extends Module { ); // Threshold - private final Setting thresholdMode = sgThreshold.add(new EnumSetting.Builder() .name("threshold-mode") .description("The threshold mode to trigger auto eat.") @@ -100,6 +99,7 @@ public class AutoEat extends Module { .build() ); + // Module state public boolean eating; private int slot, prevSlot; @@ -115,46 +115,44 @@ public void onDeactivate() { if (eating) stopEating(); } + /** + * Main tick handler for the module's eating logic + */ @EventHandler(priority = EventPriority.LOW) private void onTick(TickEvent.Pre event) { - // Skip if Auto Gap is already eating + // Don't eat if AutoGap is already eating if (Modules.get().get(AutoGap.class).isEating()) return; + // case 1: Already eating if (eating) { - // If we are eating check if we should still be eating - if (shouldEat()) { - // Check if the item in current slot is not food - if (mc.player.getInventory().getStack(slot).get(DataComponentTypes.FOOD) == null) { - // If not try finding a new slot - int newSlot = findSlot(); - - // If no valid slot was found then stop eating - if (newSlot == -1) { - stopEating(); - return; - } - // Otherwise change to the new slot - else { - changeSlot(newSlot); - } - } - - // Continue eating - eat(); - } - // If we shouldn't be eating anymore then stop - else { + // Stop eating if we shouldn't eat anymore + if (!shouldEat()) { stopEating(); + return; } - } else { - // If we are not eating check if we should start eating - if (shouldEat()) { - // Try to find a valid slot - slot = findSlot(); - - // If slot was found then start eating - if (slot != -1) startEating(); + + // Check if current item is still valid food + if (mc.player.getInventory().getStack(slot).get(DataComponentTypes.FOOD) == null) { + int newSlot = findSlot(); + + // Stop if no food found + if (newSlot == -1) { + stopEating(); + return; + } + + changeSlot(newSlot); } + + // Continue eating the food + eat(); + return; + } + + // case 2: Not eating yet but should start + if (shouldEat()) { + slot = findSlot(); + if (slot != -1) startEating(); } } From 071daa74b23a338dcfa344391e9c13dc1f6cd4c0 Mon Sep 17 00:00:00 2001 From: uxmlen <38371923+uxmlen@users.noreply.github.com> Date: Mon, 5 May 2025 17:44:05 +0300 Subject: [PATCH 3/3] fix: comment to check current slot --- .../meteorclient/systems/modules/player/AutoEat.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 945414850c..f6f1965c84 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoEat.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoEat.java @@ -131,7 +131,7 @@ private void onTick(TickEvent.Pre event) { return; } - // Check if current item is still valid food + // Check if the item in current slot is not food anymore if (mc.player.getInventory().getStack(slot).get(DataComponentTypes.FOOD) == null) { int newSlot = findSlot();