Skip to content

Commit 69b807b

Browse files
committed
Update AutoEat, ChestSearch, MultiAura
1 parent e10f464 commit 69b807b

4 files changed

Lines changed: 149 additions & 14 deletions

File tree

src/main/java/net/wurstclient/clickgui/screens/ChestSearchScreen.java

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import net.minecraft.client.input.MouseButtonEvent;
1919
import net.minecraft.core.BlockPos;
2020
import net.minecraft.network.chat.Component;
21+
import net.minecraft.world.item.ItemStack;
2122
import net.minecraft.world.phys.Vec3;
2223
import net.wurstclient.WurstClient;
2324
import net.wurstclient.chestsearch.SlotHighlighter;
@@ -26,6 +27,7 @@
2627
import net.wurstclient.chestsearch.ChestManager;
2728
import net.wurstclient.chestsearch.ChestEntry;
2829
import net.wurstclient.hacks.WaypointsHack;
30+
import net.wurstclient.hacks.EnchantmentHandlerHack;
2931
import net.wurstclient.waypoints.Waypoint;
3032
import net.wurstclient.waypoints.WaypointDimension;
3133

@@ -1328,11 +1330,11 @@ else if(scrollOffset > maxScroll)
13281330
{
13291331
for(ChestEntry.ItemEntry it : matches)
13301332
{
1333+
ItemStack stack =
1334+
net.wurstclient.chestsearch.ChestSearchItemStacks
1335+
.decode(it);
13311336
try
13321337
{
1333-
net.minecraft.world.item.ItemStack stack =
1334-
net.wurstclient.chestsearch.ChestSearchItemStacks
1335-
.decode(it);
13361338
if(!stack.isEmpty())
13371339
context.item(stack, x + 2, lineY - 2);
13381340
}catch(Throwable ignored)
@@ -1363,6 +1365,32 @@ else if(scrollOffset > maxScroll)
13631365
: ItemNameUtils.sanitizePath(ench);
13641366
String baseName = ItemNameUtils
13651367
.buildEnchantmentName(eid, path);
1368+
boolean coloredName = false;
1369+
try
1370+
{
1371+
var handler = WurstClient.INSTANCE
1372+
.getHax().enchantmentHandlerHack;
1373+
if(handler != null && handler.isEnabled()
1374+
&& handler
1375+
.shouldColorEnchantmentsInChestSearch())
1376+
{
1377+
String colored = EnchantmentHandlerHack
1378+
.getColoredEnchantmentDisplay(path,
1379+
it.enchantmentLevels != null
1380+
&& ei < it.enchantmentLevels
1381+
.size()
1382+
? it.enchantmentLevels
1383+
.get(ei)
1384+
.intValue()
1385+
: 1);
1386+
if(colored != null)
1387+
{
1388+
baseName = colored;
1389+
coloredName = true;
1390+
}
1391+
}
1392+
}catch(Throwable ignored)
1393+
{}
13661394
String levelText = "";
13671395
try
13681396
{
@@ -1371,7 +1399,7 @@ else if(scrollOffset > maxScroll)
13711399
{
13721400
int lvl = it.enchantmentLevels.get(ei)
13731401
.intValue();
1374-
if(lvl > 0)
1402+
if(lvl > 0 && !coloredName)
13751403
levelText = " " + Component
13761404
.translatable(
13771405
"enchantment.level." + lvl)

src/main/java/net/wurstclient/hacks/AutoEatHack.java

Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
import net.minecraft.world.effect.MobEffectInstance;
1919
import net.minecraft.world.effect.MobEffects;
2020
import 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;
2322
import net.minecraft.world.entity.player.Inventory;
2423
import net.minecraft.world.food.FoodData;
2524
import 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;

src/main/java/net/wurstclient/hacks/EnchantmentHandlerHack.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ public final class EnchantmentHandlerHack extends Hack
115115
new CheckboxSetting("Show slot numbers", false);
116116
private final CheckboxSetting colorEnchantments =
117117
new CheckboxSetting("Color enchantments", true);
118+
private final CheckboxSetting colorEnchantmentsInChestSearch =
119+
new CheckboxSetting("Color enchantments in Chest Search",
120+
"Applies EnchantmentHandler's enchantment colors to Chest Search results.",
121+
true);
118122
private final CheckboxSetting showColorsInTooltips =
119123
new CheckboxSetting("Show colors in tool tips",
120124
"Applies EnchantmentHandler's enchantment colors to item tooltips.",
@@ -200,6 +204,7 @@ public EnchantmentHandlerHack()
200204
addSetting(useItemIcons);
201205
addSetting(showSlotNumbers);
202206
addSetting(colorEnchantments);
207+
addSetting(colorEnchantmentsInChestSearch);
203208
addSetting(showColorsInTooltips);
204209
addSetting(iconScale);
205210
addSetting(includePlayerInventory);
@@ -2026,6 +2031,12 @@ public boolean shouldShowColorsInTooltips()
20262031
return showColorsInTooltips.isChecked();
20272032
}
20282033

2034+
public boolean shouldColorEnchantmentsInChestSearch()
2035+
{
2036+
return colorEnchantments.isChecked()
2037+
&& colorEnchantmentsInChestSearch.isChecked();
2038+
}
2039+
20292040
public static Component getColoredEnchantmentName(
20302041
Holder<Enchantment> holder, int level)
20312042
{
@@ -2036,13 +2047,25 @@ public static Component getColoredEnchantmentName(
20362047
.map(registryKey -> registryKey.identifier()).orElse(null);
20372048
String path = id != null ? id.getPath()
20382049
: sanitizePath(holder.getRegisteredName());
2039-
String display = ENCHANT_DISPLAY.get(path);
2050+
String display = getColoredEnchantmentDisplay(path, level);
20402051
if(display == null)
20412052
return Enchantment.getFullname(holder, level);
20422053

2054+
return Component.literal(display);
2055+
}
2056+
2057+
public static String getColoredEnchantmentDisplay(String path, int level)
2058+
{
2059+
if(path == null || path.isEmpty())
2060+
return null;
2061+
2062+
String display = ENCHANT_DISPLAY.get(path);
2063+
if(display == null)
2064+
return null;
2065+
20432066
if(level > 1)
20442067
display += " \u00a7f" + level;
2045-
return Component.literal(display);
2068+
return display;
20462069
}
20472070

20482071
public static Component colorizeTooltipLine(ItemStack stack, Component line)

src/main/java/net/wurstclient/hacks/MultiAuraHack.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.util.stream.Stream;
1515
import net.minecraft.world.InteractionHand;
1616
import net.minecraft.world.entity.Entity;
17+
import net.minecraft.world.entity.player.Player;
1718
import net.wurstclient.Category;
1819
import net.wurstclient.SearchTags;
1920
import net.wurstclient.events.RenderListener;
@@ -67,6 +68,7 @@ public final class MultiAuraHack extends Hack
6768
false);
6869

6970
private final List<Entity> currentTargets = new ArrayList<>();
71+
private final List<Entity> lastTargets = new ArrayList<>();
7072

7173
public MultiAuraHack()
7274
{
@@ -111,13 +113,15 @@ protected void onDisable()
111113
EVENTS.remove(UpdateListener.class, this);
112114
EVENTS.remove(RenderListener.class, this);
113115
currentTargets.clear();
116+
lastTargets.clear();
114117
}
115118

116119
@Override
117120
public void onUpdate()
118121
{
119122
currentTargets.clear();
120-
if(pauseForAutoEat.isChecked() && WURST.getHax().autoEatHack.isEating())
123+
if(pauseForAutoEat.isChecked()
124+
&& WURST.getHax().autoEatHack.shouldPauseOtherActions())
121125
return;
122126

123127
speed.updateTimer();
@@ -152,7 +156,12 @@ public void onUpdate()
152156
ArrayList<Entity> entities =
153157
stream.collect(Collectors.toCollection(ArrayList::new));
154158
if(entities.isEmpty())
159+
{
160+
lastTargets.clear();
155161
return;
162+
}
163+
lastTargets.clear();
164+
lastTargets.addAll(entities);
156165
currentTargets.addAll(entities);
157166

158167
if(maceSupportActive)
@@ -191,6 +200,18 @@ public void onUpdate()
191200
}
192201
}
193202

203+
/**
204+
* Returns true when MultiAura's last target set consisted only of mobs.
205+
* AutoEat uses this because a wall hit result hides the mob behind it.
206+
*/
207+
public boolean isFightingMobsOnly()
208+
{
209+
if(!isEnabled() || lastTargets.isEmpty())
210+
return false;
211+
212+
return lastTargets.stream().noneMatch(Player.class::isInstance);
213+
}
214+
194215
@Override
195216
public void onRender(PoseStack matrixStack, float partialTicks)
196217
{

0 commit comments

Comments
 (0)