Skip to content

Commit e5e823f

Browse files
committed
Toggle for ChestSearch
1 parent f286b29 commit e5e823f

File tree

3 files changed

+84
-33
lines changed

3 files changed

+84
-33
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ I did not, nor could I copy their code directly as most are Meteor based mods. S
164164
![WayPoints](https://i.imgur.com/dxFc17N.png) ![Waypoint Manager](https://i.imgur.com/K2xGVqc.png) ![Waypoint Editor](https://i.imgur.com/23i14s1.png)
165165

166166
### Chest Search
167-
- Automatically or manually scan each chest you open and store its contents in a JSON file per server
167+
- Automatically or manually scan each chest you open and store its contents in a JSON file per server (You can also disable entirely)
168168
- Able to detect chest changes that you make, so adding or removing items instantly updates the JSON
169169
- Unable to detect chest changes that other players make
170170
- Able to delete entries

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

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import net.wurstclient.Category;
1111
import net.wurstclient.hack.Hack;
1212
import net.wurstclient.settings.ColorSetting;
13+
import net.wurstclient.settings.EnumSetting;
1314
import net.wurstclient.settings.SliderSetting;
1415
import net.wurstclient.settings.SliderSetting.ValueDisplay;
1516
import net.wurstclient.settings.CheckboxSetting;
@@ -18,9 +19,10 @@ public final class ChestSearchHack extends Hack
1819
{
1920
private static final int DISPLAY_RADIUS_UNLIMITED = 2001;
2021

21-
private final net.wurstclient.settings.CheckboxSetting automaticMode =
22-
new net.wurstclient.settings.CheckboxSetting("Automatic mode",
23-
"Automatically scan chests on open.", true);
22+
private final EnumSetting<Mode> modeSetting = new EnumSetting<>("Mode",
23+
"Automatic scans instantly, Manual requires pressing the Scan button,"
24+
+ " and Off disables ChestSearch entirely.",
25+
Mode.values(), Mode.AUTOMATIC);
2426
private final SliderSetting waypointTimeSec = new SliderSetting(
2527
"Waypoint time (s)", 60, 5, 600, 5, ValueDisplay.INTEGER);
2628
private final SliderSetting espTimeSec =
@@ -59,7 +61,7 @@ public ChestSearchHack()
5961
setCategory(Category.ITEMS);
6062
// automatic/manual toggle should appear above the timeouts in the
6163
// clickui so add it first
62-
addSetting(automaticMode);
64+
addSetting(modeSetting);
6365
addSetting(waypointTimeSec);
6466
addSetting(espTimeSec);
6567
// expose cleaner settings in navigator so user can tune them
@@ -130,7 +132,29 @@ public int getWaypointTimeMs()
130132

131133
public boolean isAutomaticMode()
132134
{
133-
return automaticMode.isChecked();
135+
return getMode() == Mode.AUTOMATIC;
136+
}
137+
138+
public boolean isManualMode()
139+
{
140+
return getMode() == Mode.MANUAL;
141+
}
142+
143+
public boolean isOffMode()
144+
{
145+
return getMode() == Mode.OFF;
146+
}
147+
148+
public Mode getMode()
149+
{
150+
try
151+
{
152+
Mode mode = modeSetting.getSelected();
153+
return mode != null ? mode : Mode.AUTOMATIC;
154+
}catch(Throwable t)
155+
{
156+
return Mode.AUTOMATIC;
157+
}
134158
}
135159

136160
public int getEspTimeMs()
@@ -175,4 +199,24 @@ protected void onEnable()
175199
{}
176200
setEnabled(false);
177201
}
202+
203+
public enum Mode
204+
{
205+
AUTOMATIC("Automatic"),
206+
MANUAL("Manual"),
207+
OFF("Off");
208+
209+
private final String displayName;
210+
211+
private Mode(String displayName)
212+
{
213+
this.displayName = displayName;
214+
}
215+
216+
@Override
217+
public String toString()
218+
{
219+
return displayName;
220+
}
221+
}
178222
}

src/main/java/net/wurstclient/mixin/GenericContainerScreenMixin.java

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import net.wurstclient.chestsearch.ChestRecorder;
4242
import net.wurstclient.clickgui.screens.ChestSearchScreen;
4343
import net.wurstclient.hacks.AutoStealHack;
44+
import net.wurstclient.hacks.ChestSearchHack;
4445
import net.wurstclient.hacks.QuickShulkerHack;
4546

4647
@Mixin(ContainerScreen.class)
@@ -93,6 +94,7 @@ public void init()
9394
super.init();
9495
if(!WurstClient.INSTANCE.isEnabled())
9596
return;
97+
final ChestSearchHack chestSearchHack = wurst$getChestSearchHack();
9698
if(autoSteal.areButtonsVisible())
9799
{
98100
addRenderableWidget(Button
@@ -130,13 +132,11 @@ public void init()
130132
// ChestSearch hack settings.
131133
try
132134
{
133-
net.wurstclient.hacks.ChestSearchHack csh =
134-
WurstClient.INSTANCE.getHax().chestSearchHack;
135-
boolean showScan = true;
135+
boolean showScan = false;
136136
try
137137
{
138-
if(csh != null)
139-
showScan = !csh.isAutomaticMode();
138+
if(chestSearchHack != null)
139+
showScan = chestSearchHack.isManualMode();
140140
}catch(Throwable ignored)
141141
{}
142142
if(showScan)
@@ -149,6 +149,13 @@ public void init()
149149
// Attempt to record the chest contents when the container screen opens.
150150
try
151151
{
152+
try
153+
{
154+
if(chestSearchHack != null && chestSearchHack.isOffMode())
155+
return;
156+
}catch(Throwable ignored)
157+
{}
158+
152159
ChestConfig cfg = new ChestConfig();
153160
if(!cfg.enabled)
154161
return;
@@ -628,11 +635,8 @@ else if(inv != null
628635
{
629636
try
630637
{
631-
net.wurstclient.hacks.ChestSearchHack csh =
632-
WurstClient.INSTANCE
633-
.getHax().chestSearchHack;
634-
boolean doAuto =
635-
csh == null || csh.isAutomaticMode();
638+
boolean doAuto = chestSearchHack == null
639+
|| chestSearchHack.isAutomaticMode();
636640
if(doAuto)
637641
{
638642
int px =
@@ -705,11 +709,8 @@ else if(inv != null
705709
}
706710
try
707711
{
708-
net.wurstclient.hacks.ChestSearchHack csh =
709-
WurstClient.INSTANCE
710-
.getHax().chestSearchHack;
711-
boolean doAuto =
712-
csh == null || csh.isAutomaticMode();
712+
boolean doAuto = chestSearchHack == null
713+
|| chestSearchHack.isAutomaticMode();
713714
if(doAuto)
714715
{
715716
int px =
@@ -759,10 +760,8 @@ else if(inv != null
759760
// automatic mode)
760761
try
761762
{
762-
net.wurstclient.hacks.ChestSearchHack csh =
763-
WurstClient.INSTANCE
764-
.getHax().chestSearchHack;
765-
if(csh == null || csh.isAutomaticMode())
763+
if(chestSearchHack == null
764+
|| chestSearchHack.isAutomaticMode())
766765
chestRecorder.onChestOpened(fServerIp,
767766
fDimension,
768767
GenericContainerScreenMixin.this.clickedX,
@@ -799,9 +798,8 @@ else if(inv != null
799798
this.chestSlotOrder = new java.util.ArrayList<>(slotOrder);
800799
try
801800
{
802-
net.wurstclient.hacks.ChestSearchHack csh =
803-
WurstClient.INSTANCE.getHax().chestSearchHack;
804-
if(csh == null || csh.isAutomaticMode())
801+
if(chestSearchHack == null
802+
|| chestSearchHack.isAutomaticMode())
805803
chestRecorder.onChestOpened(fServerIp, fDimension,
806804
GenericContainerScreenMixin.this.clickedX,
807805
GenericContainerScreenMixin.this.clickedY,
@@ -857,11 +855,8 @@ public void run()
857855
{
858856
try
859857
{
860-
net.wurstclient.hacks.ChestSearchHack csh =
861-
WurstClient.INSTANCE
862-
.getHax().chestSearchHack;
863-
boolean doAuto =
864-
csh == null || csh.isAutomaticMode();
858+
boolean doAuto = chestSearchHack == null
859+
|| chestSearchHack.isAutomaticMode();
865860
if(doAuto)
866861
{
867862
int px =
@@ -1291,6 +1286,18 @@ public void removed()
12911286
{}
12921287
}
12931288

1289+
@Unique
1290+
private ChestSearchHack wurst$getChestSearchHack()
1291+
{
1292+
try
1293+
{
1294+
return WurstClient.INSTANCE.getHax().chestSearchHack;
1295+
}catch(Throwable ignored)
1296+
{
1297+
return null;
1298+
}
1299+
}
1300+
12941301
@Unique
12951302
private BlockPos wurst$normalizeContainerPos(BlockPos pos)
12961303
{

0 commit comments

Comments
 (0)