Skip to content

fix: AutoEat not switching slots when food runs out #5380

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
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 @@ -34,11 +34,11 @@ public class AutoEat extends Module {
@SuppressWarnings("unchecked")
private static final Class<? extends Module>[] 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<List<Item>> blacklist = sgGeneral.add(new ItemListSetting.Builder()
.name("blacklist")
.description("Which items to not eat.")
Expand Down Expand Up @@ -72,7 +72,6 @@ public class AutoEat extends Module {
);

// Threshold

private final Setting<ThresholdMode> thresholdMode = sgThreshold.add(new EnumSetting.Builder<ThresholdMode>()
.name("threshold-mode")
.description("The threshold mode to trigger auto eat.")
Expand Down Expand Up @@ -100,6 +99,7 @@ public class AutoEat extends Module {
.build()
);

// Module state
public boolean eating;
private int slot, prevSlot;

Expand All @@ -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();
}
}

Expand Down