Skip to content

Commit c6cc08b

Browse files
rfresh2Avanatiker
andauthored
ChestStealer Rusherhack compat (#447)
* ChestStealer Rusherhack compat * Reduce nesting and this calls Co-authored-by: Constructor <fractalminds@protonmail.com>
1 parent c819baa commit c6cc08b

File tree

2 files changed

+30
-36
lines changed

2 files changed

+30
-36
lines changed

src/main/java/com/lambda/mixin/gui/MixinGuiContainer.java

+26-24
Original file line numberDiff line numberDiff line change
@@ -12,43 +12,45 @@
1212
import org.spongepowered.asm.mixin.injection.Inject;
1313
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1414

15-
import java.io.IOException;
16-
1715
@Mixin(GuiContainer.class)
1816
public class MixinGuiContainer extends GuiScreen {
1917

2018
@Shadow protected int guiLeft;
2119
@Shadow protected int guiTop;
2220
@Shadow protected int xSize;
21+
private final GuiButton stealButton = new LambdaGuiStealButton(guiLeft + xSize + 2, guiTop + 2);
22+
private final GuiButton storeButton = new LambdaGuiStoreButton(guiLeft + xSize + 2, guiTop + 4 + stealButton.height);
2323

24-
private final GuiButton stealButton = new LambdaGuiStealButton(this.guiLeft + this.xSize + 2, this.guiTop + 2);
25-
private final GuiButton storeButton = new LambdaGuiStoreButton(this.guiLeft + this.xSize + 2, this.guiTop + 4 + stealButton.height);
26-
27-
@Inject(method = "initGui", at = @At("HEAD"))
28-
public void initGui(CallbackInfo ci) {
29-
if (ChestStealer.INSTANCE.isValidGui()) {
30-
this.buttonList.add(stealButton);
31-
this.buttonList.add(storeButton);
32-
ChestStealer.updateButton(stealButton, this.guiLeft, this.xSize, this.guiTop);
33-
ChestStealer.updateButton(storeButton, this.guiLeft, this.xSize, this.guiTop);
34-
}
35-
}
24+
@Inject(method = "mouseClicked", at = @At("TAIL"))
25+
public void mouseClicked(int x, int y, int button, CallbackInfo ci) {
26+
if (button != 0) return;
3627

37-
@Override
38-
protected void actionPerformed(GuiButton button) throws IOException {
39-
if (button.id == 696969) {
40-
ChestStealer.INSTANCE.setStealing(!ChestStealer.INSTANCE.getStealing());
41-
} else if (button.id == 420420) {
28+
if (storeButton.mousePressed(mc, x, y)) {
4229
ChestStealer.INSTANCE.setStoring(!ChestStealer.INSTANCE.getStoring());
43-
} else {
44-
super.actionPerformed(button);
30+
} else if (stealButton.mousePressed(mc, x, y)) {
31+
ChestStealer.INSTANCE.setStealing(!ChestStealer.INSTANCE.getStealing());
4532
}
4633
}
4734

48-
@Inject(method = "updateScreen", at = @At("HEAD"))
35+
@Inject(method = "updateScreen", at = @At("TAIL"))
4936
public void updateScreen(CallbackInfo ci) {
50-
ChestStealer.updateButton(stealButton, this.guiLeft, this.xSize, this.guiTop);
51-
ChestStealer.updateButton(storeButton, this.guiLeft, this.xSize, this.guiTop);
37+
if (!ChestStealer.INSTANCE.isValidGui()) return;
38+
39+
if (ChestStealer.INSTANCE.isDisabled()) {
40+
buttonList.remove(storeButton);
41+
buttonList.remove(storeButton);
42+
return;
43+
}
44+
45+
if (!buttonList.contains(stealButton)) {
46+
buttonList.add(stealButton);
47+
}
48+
if (!buttonList.contains(storeButton)) {
49+
buttonList.add(storeButton);
50+
}
51+
52+
ChestStealer.updateButton(stealButton, guiLeft, xSize, guiTop);
53+
ChestStealer.updateButton(storeButton, guiLeft, xSize, guiTop);
5254
}
5355

5456
}

src/main/kotlin/com/lambda/client/module/modules/player/ChestStealer.kt

+4-12
Original file line numberDiff line numberDiff line change
@@ -89,29 +89,21 @@ object ChestStealer : Module(
8989
runSafe {
9090
if (isEnabled && isContainerOpen()) {
9191
if (button.id == 696969) {
92-
val str = if (stealing) {
93-
"Stop"
94-
} else {
95-
"Steal"
96-
}
92+
val name = if (stealing) "Stop" else "Steal"
9793

9894
button.x = left + size + 2
9995
button.y = top + 2
10096
button.enabled = canSteal() and !storing
10197
button.visible = true
102-
button.displayString = str
98+
button.displayString = name
10399
} else if (button.id == 420420) {
104-
val str = if (storing) {
105-
"Stop"
106-
} else {
107-
"Store"
108-
}
100+
val name = if (storing) "Stop" else "Store"
109101

110102
button.x = left + size + 2
111103
button.y = top + 24
112104
button.enabled = canStore() and !stealing
113105
button.visible = true
114-
button.displayString = str
106+
button.displayString = name
115107
}
116108
} else {
117109
button.visible = false

0 commit comments

Comments
 (0)