Skip to content

Commit f0bd299

Browse files
committed
Added Dump Button To AutoSteal
1 parent 2080b99 commit f0bd299

File tree

4 files changed

+98
-18
lines changed

4 files changed

+98
-18
lines changed

75288be12

Lines changed: 0 additions & 10 deletions
This file was deleted.

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

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ public void store(AbstractContainerScreen<?> screen, int rows)
6161
startClickingSlots(screen, rows * 9, rows * 9 + 36, false);
6262
}
6363

64+
public void dump(AbstractContainerScreen<?> screen, int rows)
65+
{
66+
startDroppingSlots(screen, 0, rows * 9);
67+
}
68+
6469
private void startClickingSlots(AbstractContainerScreen<?> screen, int from,
6570
int to, boolean steal)
6671
{
@@ -72,11 +77,21 @@ private void startClickingSlots(AbstractContainerScreen<?> screen, int from,
7277
.start(() -> shiftClickSlots(screen, from, to, steal));
7378
}
7479

80+
private void startDroppingSlots(AbstractContainerScreen<?> screen, int from,
81+
int to)
82+
{
83+
if(thread != null && thread.isAlive())
84+
thread.interrupt();
85+
86+
thread = Thread.ofPlatform().name("AutoSteal")
87+
.uncaughtExceptionHandler((t, e) -> e.printStackTrace()).daemon()
88+
.start(() -> dropSlots(screen, from, to));
89+
}
90+
7591
private void shiftClickSlots(AbstractContainerScreen<?> screen, int from,
7692
int to, boolean steal)
7793
{
78-
List<Slot> slots = IntStream.range(from, to)
79-
.mapToObj(i -> screen.getMenu().slots.get(i)).toList();
94+
List<Slot> slots = collectSlots(screen, from, to);
8095

8196
if(reverseSteal.isChecked() && steal)
8297
slots = slots.reversed();
@@ -162,6 +177,40 @@ private void shiftClickSlots(AbstractContainerScreen<?> screen, int from,
162177
}
163178
}
164179

180+
private void dropSlots(AbstractContainerScreen<?> screen, int from, int to)
181+
{
182+
List<Slot> slots = collectSlots(screen, from, to);
183+
184+
for(Slot slot : slots)
185+
try
186+
{
187+
if(slot.getItem().isEmpty())
188+
continue;
189+
190+
Thread.sleep(delay.getValueI());
191+
192+
if(MC.screen == null)
193+
break;
194+
195+
screen.slotClicked(slot, slot.index, 1, ClickType.THROW);
196+
197+
}catch(InterruptedException e)
198+
{
199+
Thread.currentThread().interrupt();
200+
break;
201+
}
202+
}
203+
204+
private List<Slot> collectSlots(AbstractContainerScreen<?> screen, int from,
205+
int to)
206+
{
207+
int totalSlots = screen.getMenu().slots.size();
208+
int safeFrom = Math.max(0, Math.min(from, totalSlots));
209+
int safeTo = Math.max(safeFrom, Math.min(to, totalSlots));
210+
return IntStream.range(safeFrom, safeTo)
211+
.mapToObj(i -> screen.getMenu().slots.get(i)).toList();
212+
}
213+
165214
private java.util.Set<Item> getInventoryItemTypes()
166215
{
167216
java.util.Set<Item> types = new java.util.HashSet<>();

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,34 @@ public void init()
105105
if(!WurstClient.INSTANCE.isEnabled())
106106
return;
107107
final ChestSearchHack chestSearchHack = wurst$getChestSearchHack();
108+
boolean autoButtonsPlaced = false;
109+
final int autoButtonHeight = 12;
110+
final int autoButtonY = topPos - autoButtonHeight - 4;
108111
if(autoSteal.areButtonsVisible())
109112
{
113+
autoButtonsPlaced = true;
114+
final int buttonWidth = 44;
115+
final int buttonSpacing = 3;
116+
final int rightMargin = 6;
117+
int dumpX = leftPos + imageWidth - rightMargin - buttonWidth;
118+
int storeX = dumpX - buttonSpacing - buttonWidth;
119+
int stealX = storeX - buttonSpacing - buttonWidth;
120+
110121
addRenderableWidget(Button
111122
.builder(Component.literal("Steal"),
112123
b -> autoSteal.steal(this, containerRows))
113-
.bounds(leftPos + imageWidth - 108, topPos + 4, 50, 12)
124+
.bounds(stealX, autoButtonY, buttonWidth, autoButtonHeight)
114125
.build());
115126
addRenderableWidget(Button
116127
.builder(Component.literal("Store"),
117128
b -> autoSteal.store(this, containerRows))
118-
.bounds(leftPos + imageWidth - 56, topPos + 4, 50, 12).build());
129+
.bounds(storeX, autoButtonY, buttonWidth, autoButtonHeight)
130+
.build());
131+
addRenderableWidget(Button
132+
.builder(Component.literal("Dump"),
133+
b -> autoSteal.dump(this, containerRows))
134+
.bounds(dumpX, autoButtonY, buttonWidth, autoButtonHeight)
135+
.build());
119136
}
120137
if(autoSteal.isEnabled())
121138
autoSteal.steal(this, containerRows);
@@ -129,10 +146,13 @@ public void init()
129146
// visually outside the chest/inventory GUI. Use the same
130147
// positioning/size as the inventory screen button so it
131148
// appears outside the form consistently.
149+
int quickButtonY =
150+
autoButtonsPlaced ? autoButtonY - 20 : topPos - 20;
132151
Button quickButton = Button
133152
.builder(Component.literal("QuickShulker"),
134153
b -> quickShulker.triggerFromGui())
135-
.bounds(leftPos + imageWidth - 90, topPos - 20, 80, 16).build();
154+
.bounds(leftPos + imageWidth - 90, quickButtonY, 80, 16)
155+
.build();
136156
quickButton.active = !quickShulker.isBusy();
137157
addRenderableWidget(quickButton);
138158
}

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,36 @@ public void init()
4444
if(!WurstClient.INSTANCE.isEnabled())
4545
return;
4646

47+
boolean autoButtonsPlaced = false;
48+
final int autoButtonHeight = 12;
49+
final int autoButtonY = topPos - autoButtonHeight - 4;
4750
if(autoSteal.areButtonsVisible())
4851
{
52+
autoButtonsPlaced = true;
53+
final int buttonWidth = 44;
54+
final int buttonSpacing = 3;
55+
final int rightMargin = 6;
56+
int dumpX = leftPos + imageWidth - rightMargin - buttonWidth;
57+
int storeX = dumpX - buttonSpacing - buttonWidth;
58+
int stealX = storeX - buttonSpacing - buttonWidth;
59+
4960
addRenderableWidget(Button
5061
.builder(Component.literal("Steal"),
5162
b -> autoSteal.steal(this, 3))
52-
.bounds(leftPos + imageWidth - 108, topPos + 4, 50, 12)
63+
.bounds(stealX, autoButtonY, buttonWidth, autoButtonHeight)
5364
.build());
5465

5566
addRenderableWidget(Button
5667
.builder(Component.literal("Store"),
5768
b -> autoSteal.store(this, 3))
58-
.bounds(leftPos + imageWidth - 56, topPos + 4, 50, 12).build());
69+
.bounds(storeX, autoButtonY, buttonWidth, autoButtonHeight)
70+
.build());
71+
72+
addRenderableWidget(Button
73+
.builder(Component.literal("Dump"),
74+
b -> autoSteal.dump(this, 3))
75+
.bounds(dumpX, autoButtonY, buttonWidth, autoButtonHeight)
76+
.build());
5977
}
6078

6179
if(autoSteal.isEnabled())
@@ -67,10 +85,13 @@ public void init()
6785
// place the QuickShulker button outside the shulker UI so it
6886
// doesn't overlap the container background, matching the
6987
// inventory screen placement
88+
int quickButtonY =
89+
autoButtonsPlaced ? autoButtonY - 20 : topPos - 20;
7090
Button quickButton = Button
7191
.builder(Component.literal("QuickShulker"),
7292
b -> quickShulker.triggerFromGui())
73-
.bounds(leftPos + imageWidth - 90, topPos - 20, 80, 16).build();
93+
.bounds(leftPos + imageWidth - 90, quickButtonY, 80, 16)
94+
.build();
7495
quickButton.active = !quickShulker.isBusy();
7596
addRenderableWidget(quickButton);
7697
}

0 commit comments

Comments
 (0)