Skip to content

Commit dc10f78

Browse files
committed
Updated ChestSearch & TooManyHax
1 parent 1d1b168 commit dc10f78

24 files changed

Lines changed: 846 additions & 58 deletions

src/main/java/net/wurstclient/TooManyHaxFile.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,19 @@ public final class TooManyHaxFile
2424
{
2525
private final Path path;
2626
private final ArrayList<Feature> blockedFeatures;
27+
private final boolean requireSafeToBlock;
2728

2829
public TooManyHaxFile(Path path, ArrayList<Feature> blockedFeatures)
30+
{
31+
this(path, blockedFeatures, true);
32+
}
33+
34+
public TooManyHaxFile(Path path, ArrayList<Feature> blockedFeatures,
35+
boolean requireSafeToBlock)
2936
{
3037
this.path = path;
3138
this.blockedFeatures = blockedFeatures;
39+
this.requireSafeToBlock = requireSafeToBlock;
3240
}
3341

3442
public void load()
@@ -70,7 +78,8 @@ private void setBlockedFeatures(WsonArray wson)
7078
{
7179
Feature feature = WurstClient.INSTANCE.getFeatureByName(name);
7280

73-
if(feature != null && feature.isSafeToBlock())
81+
if(feature != null
82+
&& (!requireSafeToBlock || feature.isSafeToBlock()))
7483
blockedFeatures.add(feature);
7584
}
7685

@@ -106,7 +115,8 @@ public void saveProfile(Path profilePath) throws IOException, JsonException
106115
private JsonArray createJson()
107116
{
108117
JsonArray json = new JsonArray();
109-
blockedFeatures.stream().filter(Feature::isSafeToBlock)
118+
blockedFeatures.stream()
119+
.filter(feature -> !requireSafeToBlock || feature.isSafeToBlock())
110120
.map(Feature::getName).forEach(name -> json.add(name));
111121

112122
return json;

src/main/java/net/wurstclient/WurstClient.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ public void initialize()
163163
this.settingsFile = new SettingsFile(settingsFile, hax, cmds, otfs);
164164
this.settingsFile.load();
165165
hax.tooManyHaxHack.loadBlockedHacksFile();
166+
otfs.hackListOtf.loadHiddenHacksFile();
166167

167168
Path keybindsFile = wurstFolder.resolve("keybinds.json");
168169
keybinds = new KeybindList(keybindsFile);
@@ -286,6 +287,9 @@ public void reloadFromDisk()
286287
hax.reloadFavoriteHax();
287288
}
288289

290+
if(otfs != null)
291+
otfs.hackListOtf.loadHiddenHacksFile();
292+
289293
if(keybinds != null)
290294
keybinds.reload();
291295

src/main/java/net/wurstclient/altgui/AltGuiScreen.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,8 +1671,8 @@ else if(button == GLFW.GLFW_MOUSE_BUTTON_LEFT)
16711671
{
16721672
TooManyHaxHack tooManyHax =
16731673
WurstClient.INSTANCE.getHax().tooManyHaxHack;
1674-
if(feature != tooManyHax && tooManyHax.isEnabled()
1675-
&& tooManyHax.isBlocked(feature))
1674+
if(feature != tooManyHax
1675+
&& tooManyHax.shouldBlockStarting(feature))
16761676
{
16771677
ChatUtils.error(
16781678
feature.getName() + " is blocked by TooManyHax.");
@@ -2681,7 +2681,7 @@ private boolean isHiddenByTooManyHax(Feature feature)
26812681
{
26822682
TooManyHaxHack tooManyHax =
26832683
WurstClient.INSTANCE.getHax().tooManyHaxHack;
2684-
return tooManyHax.isEnabled() && tooManyHax.isBlocked(feature);
2684+
return tooManyHax.shouldHideEverywhere(feature);
26852685
}
26862686

26872687
private void clampScroll()

src/main/java/net/wurstclient/chestsearch/ChestRecorder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,9 @@ private void recordFromStacksInternal(String serverIp, String dimension,
327327
{}
328328
try
329329
{
330+
it.nbt = ChestSearchItemStacks.encode(copy);
330331
String n = copy.toString();
331-
if(n != null && !n.isBlank())
332+
if(it.nbt == null && n != null && !n.isBlank())
332333
{
333334
it.nbt = new JsonPrimitive(n);
334335
if(n.contains("Enchantments")
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright (c) 2014-2026 Wurst-Imperium and contributors.
3+
*
4+
* This source code is subject to the terms of the GNU General Public
5+
* License, version 3. If a copy of the GPL was not distributed with this
6+
* file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt
7+
*/
8+
package net.wurstclient.chestsearch;
9+
10+
import com.google.gson.JsonElement;
11+
import com.mojang.serialization.JsonOps;
12+
import net.minecraft.core.registries.BuiltInRegistries;
13+
import net.minecraft.resources.Identifier;
14+
import net.minecraft.world.item.Item;
15+
import net.minecraft.world.item.ItemStack;
16+
import net.wurstclient.WurstClient;
17+
18+
public final class ChestSearchItemStacks
19+
{
20+
private ChestSearchItemStacks()
21+
{}
22+
23+
public static JsonElement encode(ItemStack stack)
24+
{
25+
if(stack == null || stack.isEmpty() || WurstClient.MC.player == null)
26+
return null;
27+
28+
try
29+
{
30+
return ItemStack.CODEC
31+
.encodeStart(WurstClient.MC.player.registryAccess()
32+
.createSerializationContext(JsonOps.INSTANCE), stack)
33+
.result().orElse(null);
34+
}catch(Throwable t)
35+
{
36+
return null;
37+
}
38+
}
39+
40+
public static ItemStack decode(ChestEntry.ItemEntry item)
41+
{
42+
if(item == null)
43+
return ItemStack.EMPTY;
44+
45+
if(item.nbt != null && WurstClient.MC.player != null)
46+
try
47+
{
48+
ItemStack stack = ItemStack.CODEC
49+
.decode(
50+
WurstClient.MC.player.registryAccess()
51+
.createSerializationContext(JsonOps.INSTANCE),
52+
item.nbt)
53+
.result().map(pair -> pair.getFirst())
54+
.orElse(ItemStack.EMPTY);
55+
if(!stack.isEmpty())
56+
{
57+
stack.setCount(Math.max(1, item.count));
58+
return stack;
59+
}
60+
}catch(Throwable ignored)
61+
{}
62+
63+
try
64+
{
65+
Identifier id = Identifier.tryParse(item.itemId);
66+
if(id == null)
67+
return ItemStack.EMPTY;
68+
Item mcItem = BuiltInRegistries.ITEM.getValue(id);
69+
if(mcItem == null)
70+
return ItemStack.EMPTY;
71+
return new ItemStack(mcItem, Math.max(1, item.count));
72+
}catch(Throwable t)
73+
{
74+
return ItemStack.EMPTY;
75+
}
76+
}
77+
}

src/main/java/net/wurstclient/clickgui/ClickGui.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,8 @@ public void init()
137137
// When TooManyHax is enabled, hide hacks that it disabled from
138138
// the ClickGUI to avoid cluttering the UI. The Navigator should
139139
// keep showing all features, so we only apply this filter here.
140-
if(f instanceof net.wurstclient.hack.Hack && tooManyHax.isEnabled()
141-
&& tooManyHax.isBlocked(f)
142-
&& !((net.wurstclient.hack.Hack)f).isEnabled())
140+
if(f instanceof net.wurstclient.hack.Hack
141+
&& tooManyHax.shouldHideEverywhere(f))
143142
{
144143
continue;
145144
}
@@ -177,9 +176,8 @@ public void init()
177176
&& ((net.wurstclient.hack.Hack)f).isFavorite()))
178177
continue;
179178

180-
if(f instanceof net.wurstclient.hack.Hack && tooManyHax.isEnabled()
181-
&& tooManyHax.isBlocked(f)
182-
&& !((net.wurstclient.hack.Hack)f).isEnabled())
179+
if(f instanceof net.wurstclient.hack.Hack
180+
&& tooManyHax.shouldHideEverywhere(f))
183181
{
184182
continue;
185183
}

src/main/java/net/wurstclient/clickgui/components/FeatureButton.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void handleMouseClick(double mouseX, double mouseY, int mouseButton,
7878
}
7979

8080
TooManyHaxHack tooManyHax = WURST.getHax().tooManyHaxHack;
81-
if(tooManyHax.isEnabled() && tooManyHax.isBlocked(feature))
81+
if(tooManyHax.shouldBlockStarting(feature))
8282
{
8383
ChatUtils.error(feature.getName() + " is blocked by TooManyHax.");
8484
return;

src/main/java/net/wurstclient/clickgui/components/SettingGroupComponent.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import net.wurstclient.clickgui.ClickGuiIcons;
1717
import net.wurstclient.clickgui.ClickGui;
1818
import net.wurstclient.clickgui.Component;
19+
import net.wurstclient.other_features.HackListOtf;
1920
import net.wurstclient.settings.Setting;
2021
import net.wurstclient.settings.SettingGroup;
2122
import net.wurstclient.util.RenderUtils;
@@ -180,7 +181,8 @@ public void extractRenderState(GuiGraphicsExtractor context, int mouseX,
180181
context.fill(x1, y1, x2, y2, bgColor);
181182

182183
int txtColor = WURST.getGui().getTxtColor();
183-
context.text(MC.font, group.getName(), x1 + 4, y1 + 2, txtColor, false);
184+
context.text(MC.font, getDisplayName(), x1 + 4, y1 + 2, txtColor,
185+
false);
184186
ClickGuiIcons.drawMinimizeArrow(context, x2 - 11, y1 + 1, x2 - 1,
185187
y2 - 1, hoverHeader, !expanded);
186188

@@ -216,6 +218,19 @@ public void extractRenderState(GuiGraphicsExtractor context, int mouseX,
216218
}
217219
}
218220

221+
private String getDisplayName()
222+
{
223+
if(!"Hide from HackList".equals(group.getName()))
224+
return group.getName();
225+
226+
HackListOtf hackListOtf = WURST.getOtfs().hackListOtf;
227+
int hiddenCount = hackListOtf.getEnabledHiddenHackCount();
228+
if(hiddenCount <= 0)
229+
return group.getName();
230+
231+
return group.getName() + " [Hidden " + hiddenCount + "]";
232+
}
233+
219234
@Override
220235
public void setParent(Window parent)
221236
{

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,18 +1328,11 @@ else if(scrollOffset > maxScroll)
13281328
{
13291329
try
13301330
{
1331-
net.minecraft.resources.Identifier id =
1332-
net.minecraft.resources.Identifier
1333-
.tryParse(it.itemId);
1334-
if(id != null)
1335-
{
1336-
net.minecraft.world.item.Item item =
1337-
net.minecraft.core.registries.BuiltInRegistries.ITEM
1338-
.getValue(id);
1339-
net.minecraft.world.item.ItemStack stack =
1340-
new net.minecraft.world.item.ItemStack(item, 1);
1331+
net.minecraft.world.item.ItemStack stack =
1332+
net.wurstclient.chestsearch.ChestSearchItemStacks
1333+
.decode(it);
1334+
if(!stack.isEmpty())
13411335
context.item(stack, x + 2, lineY - 2);
1342-
}
13431336
}catch(Throwable ignored)
13441337
{}
13451338
String name =

src/main/java/net/wurstclient/command/CmdProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void process(String input)
5858

5959
TooManyHaxHack tooManyHax =
6060
WurstClient.INSTANCE.getHax().tooManyHaxHack;
61-
if(tooManyHax.isEnabled() && tooManyHax.isBlocked(cmd))
61+
if(tooManyHax.shouldBlockStarting(cmd))
6262
{
6363
ChatUtils.error(cmd.getName() + " is blocked by TooManyHax.");
6464
return;
@@ -177,7 +177,7 @@ private void setHackEnabled(Hack hack, boolean enabled)
177177
{
178178
TooManyHaxHack tooManyHax =
179179
WurstClient.INSTANCE.getHax().tooManyHaxHack;
180-
if(enabled && tooManyHax.isEnabled() && tooManyHax.isBlocked(hack))
180+
if(enabled && tooManyHax.shouldBlockStarting(hack))
181181
{
182182
ChatUtils.error(hack.getName() + " is blocked by TooManyHax.");
183183
return;

0 commit comments

Comments
 (0)