@@ -244,7 +244,7 @@ private boolean changeSlot(int slot) {
244244 return true ;
245245 }
246246
247- // main inventory move to empty hotbar, abort if none
247+ // main inventory: move to empty hotbar, abort if none
248248 var emptySlot = InvUtils .find (ItemStack ::isEmpty , SlotUtils .HOTBAR_START , SlotUtils .HOTBAR_END ).slot ();
249249 if (emptySlot == -1 ) return false ;
250250
@@ -267,9 +267,13 @@ public boolean shouldEat() {
267267 && (mc .player .getHungerManager ().isNotFull () || food .canAlwaysEat ());
268268 }
269269
270+ /**
271+ * Finds the best slot to eat from, preferring:
272+ * hotbar => offhand => main inventory (if allowed).
273+ */
270274 private int findSlot () {
271275 // prefer best in hotbar
272- int slot = findBestInRange (SlotUtils .HOTBAR_START , SlotUtils .HOTBAR_END );
276+ int slot = findBestFood (SlotUtils .HOTBAR_START , SlotUtils .HOTBAR_END );
273277 if (slot != -1 ) return slot ;
274278
275279 // if hotbar empty, prefer offhand
@@ -279,24 +283,27 @@ private int findSlot() {
279283
280284 // if allowed, search main inventory
281285 if (searchInventory .get ()) {
282- return findBestInRange (SlotUtils .MAIN_START , SlotUtils .MAIN_END );
286+ return findBestFood (SlotUtils .MAIN_START , SlotUtils .MAIN_END );
283287 }
284288
285- return -1 ; // nothing found
289+ return -1 ; // nothing found :(
286290 }
287291
288- private int findBestInRange (int start , int end ) {
292+ private int findBestFood (int start , int end ) {
289293 int best = -1 ;
290294 int bestHunger = -1 ;
291295
292296 for (int i = start ; i <= end ; i ++) {
297+ // Skip if item isn't food
293298 var stack = mc .player .getInventory ().getStack (i );
294299 var food = stack .get (DataComponentTypes .FOOD );
295300 if (food == null ) continue ;
296301
302+ // Skip if item is in blacklist
297303 Item item = stack .getItem ();
298304 if (blacklist .get ().contains (item )) continue ;
299305
306+ // Check if hunger value is better
300307 int hunger = food .nutrition ();
301308 if (hunger > bestHunger ) {
302309 bestHunger = hunger ;
@@ -307,7 +314,6 @@ private int findBestInRange(int start, int end) {
307314 return best ;
308315 }
309316
310-
311317 public enum ThresholdMode {
312318 Health ((health , hunger ) -> health ),
313319 Hunger ((health , hunger ) -> hunger ),
0 commit comments