@@ -148,8 +148,8 @@ private void onTick(TickEvent.Pre event) {
148148 return ;
149149 }
150150
151- // Check if the item in current slot is not food anymore
152- if (!Utils . isFood (mc .player .getInventory ().getItem (slot ))) {
151+ // Check if the item in current slot is no longer edible food
152+ if (!isEdible (mc .player .getInventory ().getItem (slot ))) {
153153 int newSlot = findSlot ();
154154
155155 // Stop if no food found
@@ -271,13 +271,7 @@ public boolean shouldEat() {
271271 if (!thresholdMode .get ().test (healthLow , hungerLow )) return false ;
272272
273273 slot = findSlot ();
274- if (slot == -1 ) return false ;
275-
276- ItemStack item = mc .player .getInventory ().getItem (slot );
277- FoodProperties prop = item .get (DataComponents .FOOD );
278- if (prop == null || !Utils .isFood (item )) return false ;
279-
280- return (mc .player .getFoodData ().needsFood () || prop .canAlwaysEat ());
274+ return slot != -1 ;
281275 }
282276
283277 /**
@@ -286,8 +280,7 @@ public boolean shouldEat() {
286280 */
287281 private int findSlot () {
288282 // prefer offhand
289- Item offHandItem = mc .player .getOffhandItem ().getItem ();
290- if (Utils .isFood (offHandItem ) && !blacklist .get ().contains (offHandItem )) return SlotUtils .OFFHAND ;
283+ if (isEdible (mc .player .getOffhandItem ())) return SlotUtils .OFFHAND ;
291284
292285 // if offhand empty, prefer best in hotbar
293286 int slot = findBestFood (SlotUtils .HOTBAR_START , SlotUtils .HOTBAR_END );
@@ -306,15 +299,10 @@ private int findBestFood(int start, int end) {
306299 float bestHunger = -1 ;
307300
308301 for (int i = start ; i <= end ; i ++) {
309- // Skip if item isn't food
310302 ItemStack stack = mc .player .getInventory ().getItem (i );
311- FoodProperties food = stack .get (DataComponents .FOOD );
312- if (!Utils .isFood (stack )) continue ;
313- if (food == null ) continue ;
303+ if (!isEdible (stack )) continue ;
314304
315- // Skip if item is in blacklist
316- Item item = stack .getItem ();
317- if (blacklist .get ().contains (item )) continue ;
305+ FoodProperties food = stack .get (DataComponents .FOOD );
318306
319307 // Check if hunger value is better
320308 float hunger = prioritise .get ().value (food );
@@ -327,6 +315,13 @@ private int findBestFood(int start, int end) {
327315 return best ;
328316 }
329317
318+ private boolean isEdible (ItemStack stack ) {
319+ if (!Utils .isFood (stack ) || blacklist .get ().contains (stack .getItem ())) return false ;
320+
321+ FoodProperties food = stack .get (DataComponents .FOOD );
322+ return food != null && (mc .player .getFoodData ().needsFood () || food .canAlwaysEat ());
323+ }
324+
330325 public enum ThresholdMode {
331326 Health ((health , _ ) -> health ),
332327 Hunger ((_ , hunger ) -> hunger ),
0 commit comments