|
12 | 12 | import org.spongepowered.asm.mixin.injection.Inject;
|
13 | 13 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
14 | 14 |
|
15 |
| -import java.io.IOException; |
16 |
| - |
17 | 15 | @Mixin(GuiContainer.class)
|
18 | 16 | public class MixinGuiContainer extends GuiScreen {
|
19 | 17 |
|
20 | 18 | @Shadow protected int guiLeft;
|
21 | 19 | @Shadow protected int guiTop;
|
22 | 20 | @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); |
23 | 23 |
|
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; |
36 | 27 |
|
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)) { |
42 | 29 | 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()); |
45 | 32 | }
|
46 | 33 | }
|
47 | 34 |
|
48 |
| - @Inject(method = "updateScreen", at = @At("HEAD")) |
| 35 | + @Inject(method = "updateScreen", at = @At("TAIL")) |
49 | 36 | 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); |
52 | 54 | }
|
53 | 55 |
|
54 | 56 | }
|
0 commit comments