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..f6f1965c84 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 slot = findSlot(); - - // If no valid slot was found then stop eating - if (slot == -1) { - stopEating(); - return; - } - // Otherwise change to the new slot - else { - changeSlot(slot); - } - } - - // 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 the item in current slot is not food anymore + 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(); } }