1818import net .minecraft .world .effect .MobEffectInstance ;
1919import net .minecraft .world .effect .MobEffects ;
2020import net .minecraft .world .entity .Entity ;
21- import net .minecraft .world .entity .TamableAnimal ;
22- import net .minecraft .world .entity .npc .villager .Villager ;
21+ import net .minecraft .world .entity .player .Player ;
2322import net .minecraft .world .entity .player .Inventory ;
2423import net .minecraft .world .food .FoodData ;
2524import net .minecraft .world .food .FoodProperties ;
@@ -76,6 +75,22 @@ public final class AutoEatHack extends Hack implements UpdateListener
7675 new CheckboxSetting ("Eat while walking" ,
7776 "description.wurst.setting.autoeat.eat_while_walking" , false );
7877
78+ private final CheckboxSetting eatWhileFlying = new CheckboxSetting (
79+ "Eat while flying" , "Allows AutoEat to continue while flying." , true );
80+
81+ private final CheckboxSetting eatWhileLookingAtMobs = new CheckboxSetting (
82+ "Eat while looking at mobs" ,
83+ "Allows AutoEat to continue while the crosshair is on a mob." , true );
84+
85+ private final CheckboxSetting eatWhileLookingAtPlayers =
86+ new CheckboxSetting ("Eat while looking at players" ,
87+ "Allows AutoEat to continue while the crosshair is on a player." ,
88+ false );
89+
90+ private final CheckboxSetting eatThroughWalls = new CheckboxSetting (
91+ "Eat through walls" ,
92+ "Allows AutoEat to continue while the crosshair is on a wall." , true );
93+
7994 private final CheckboxSetting allowHunger =
8095 new CheckboxSetting ("Allow hunger effect" ,
8196 "description.wurst.setting.autoeat.allow_hunger" , true );
@@ -104,6 +119,10 @@ public AutoEatHack()
104119 addSetting (allowOffhand );
105120
106121 addSetting (eatWhileWalking );
122+ addSetting (eatWhileFlying );
123+ addSetting (eatWhileLookingAtMobs );
124+ addSetting (eatWhileLookingAtPlayers );
125+ addSetting (eatThroughWalls );
107126 addSetting (allowHunger );
108127 addSetting (allowPoison );
109128 addSetting (allowChorus );
@@ -163,6 +182,39 @@ public void onUpdate()
163182 }
164183 }
165184
185+ /**
186+ * Used by combat hacks to yield before they perform an action that would
187+ * interfere with eating. This includes the inventory-transfer tick before
188+ * AutoEat has started using the item.
189+ */
190+ public boolean shouldPauseOtherActions ()
191+ {
192+ if (isEating ())
193+ return true ;
194+
195+ if (!shouldEat ())
196+ return false ;
197+
198+ LocalPlayer player = MC .player ;
199+ FoodData food = player .getFoodData ();
200+ int foodLevel = food .getFoodLevel ();
201+ int target = (int )(targetHunger .getValue () * 2 );
202+ int min = (int )(minHunger .getValue () * 2 );
203+ int injured = (int )(injuredHunger .getValue () * 2 );
204+
205+ int maxPoints = -1 ;
206+ if (isInjured (player ) && foodLevel < injured )
207+ maxPoints = -1 ;
208+ else if (foodLevel < min )
209+ maxPoints = -1 ;
210+ else if (foodLevel < target )
211+ maxPoints = target - foodLevel ;
212+ else
213+ return false ;
214+
215+ return findBestFoodSlot (maxPoints ) != -1 ;
216+ }
217+
166218 private void eat (int maxPoints )
167219 {
168220 Inventory inventory = MC .player .getInventory ();
@@ -256,12 +308,18 @@ private boolean shouldEat()
256308 return false ;
257309
258310 boolean autoFlyActive = WURST .getHax ().autoFlyHack .isEnabled ();
311+ boolean flying = MC .player .getAbilities ().flying
312+ || WURST .getHax ().flightHack .isEnabled () || autoFlyActive ;
313+ if (flying && !eatWhileFlying .isChecked ())
314+ return false ;
259315
260316 if (!eatWhileWalking .isChecked () && !autoFlyActive
261317 && (MC .player .zza != 0 || MC .player .xxa != 0 ))
262318 return false ;
263319
264- if (!autoFlyActive && isClickable (MC .hitResult ))
320+ boolean mobCombat = WURST .getHax ().multiAuraHack .isFightingMobsOnly ();
321+ if (!autoFlyActive && isClickable (MC .hitResult )
322+ && !(mobCombat && eatWhileLookingAtMobs .isChecked ()))
265323 return false ;
266324
267325 return true ;
@@ -313,8 +371,10 @@ private boolean isClickable(HitResult hitResult)
313371 if (hitResult instanceof EntityHitResult )
314372 {
315373 Entity entity = ((EntityHitResult )hitResult ).getEntity ();
316- return entity instanceof Villager
317- || entity instanceof TamableAnimal ;
374+ if (entity instanceof Player )
375+ return !eatWhileLookingAtPlayers .isChecked ();
376+
377+ return !eatWhileLookingAtMobs .isChecked ();
318378 }
319379
320380 if (hitResult instanceof BlockHitResult )
@@ -324,8 +384,11 @@ private boolean isClickable(HitResult hitResult)
324384 return false ;
325385
326386 Block block = MC .level .getBlockState (pos ).getBlock ();
327- return block instanceof BaseEntityBlock
328- || block instanceof CraftingTableBlock ;
387+ if (block instanceof BaseEntityBlock
388+ || block instanceof CraftingTableBlock )
389+ return true ;
390+
391+ return !eatThroughWalls .isChecked ();
329392 }
330393
331394 return false ;
0 commit comments