aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/rosegoldaddons/utils/OpenSkyblockGui.java
blob: 2b14d144cb5d4da287ee414aae9a786002e0f178 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
package rosegoldaddons.utils;

import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiChest;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ContainerChest;
import net.minecraft.inventory.Slot;
import net.minecraft.util.BlockPos;
import net.minecraft.util.Vec3;
import net.minecraft.util.Vec3i;
import net.minecraftforge.client.event.GuiScreenEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import rosegoldaddons.Main;
import rosegoldaddons.commands.Rosedrobe;
import rosegoldaddons.commands.Rosepet;
import rosegoldaddons.features.SexAura;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

public class OpenSkyblockGui {
    private static boolean openTrades = false;
    public static boolean doTrades = false;
    private static int deb = 0;
    public static int die = -1;
    public static boolean sellAll = false;
    public static boolean selling = false;
    public static int enableChat = -1;
    public static boolean doVisit = false;
    private static boolean didVisit = false;
    private static final KeyBinding[] binds = Main.mc.gameSettings.keyBindings;
    private static int sellAttempts = 0;
    public static boolean storeInChest = false;
    public static boolean storing = false;
    public static boolean openedChest = false;

    public static String[] endermanDrops = {
            "summoning eye", "ender pearl", "bone", "obsidian", "crystal fragment", "eye of ender", "end stone", "arrow", "combat exp, rune"
    };

    @SubscribeEvent
    public void guiDraw(GuiScreenEvent.BackgroundDrawnEvent event) {
        if (!Rosedrobe.openWardrobe && !openTrades && !Rosepet.openPetS && !sellAll && !storeInChest) return;
        if (event.gui instanceof GuiChest) {
            Container container = ((GuiChest) event.gui).inventorySlots;
            if (container instanceof ContainerChest) {
                String chestName = ((ContainerChest) container).getLowerChestInventory().getDisplayName().getUnformattedText();
                if (Rosedrobe.openWardrobe) {
                    if (chestName.contains("Pets")) {
                        clickSlot(48, 0, 0);
                        clickSlot(32, 0, 1);
                        if (Rosedrobe.slot > 0) {
                            clickSlot(Rosedrobe.slot + 35, 0, 2);
                            Main.mc.thePlayer.closeScreen();
                        }
                        Rosedrobe.openWardrobe = false;
                    }
                } else if (openTrades) {
                    if (chestName.contains("Pets")) {
                        clickSlot(48, 0, 0);
                        clickSlot(22, 0, 1);
                        openTrades = false;
                    }
                } else if (Rosepet.openPetS) {
                    if (chestName.contains("Pets")) {
                        int currPage = 1;
                        int lastPage = 1;
                        if (chestName.startsWith("(")) {
                            currPage = Integer.parseInt(chestName.substring(chestName.indexOf("(") + 1, chestName.indexOf("/")));
                            lastPage = Integer.parseInt(chestName.substring(chestName.indexOf("/") + 1, chestName.indexOf(")")));
                        }
                        String petName = Rosepet.name;
                        int petSlot = Rosepet.petSlot;
                        if (petSlot != 0) {
                            clickSlot(petSlot - 1, 0, 0);
                            Rosepet.petSlot = 0;
                            Rosepet.openPetS = false;
                            return;
                        }
                        if (!petName.equals("")) {
                            List<Slot> chestInventory = ((GuiChest) Main.mc.currentScreen).inventorySlots.inventorySlots;
                            for (Slot slot : chestInventory) {
                                if (!slot.getHasStack()) continue;
                                if (slot.getStack().getDisplayName().contains(petName)) {
                                    clickSlot(slot.slotNumber, 0, 0);
                                    Main.mc.thePlayer.closeScreen();
                                    Rosepet.openPetS = false;
                                    return;
                                }
                            }
                            if (currPage < lastPage) {
                                clickSlot(53, 0, 0);
                            } else {
                                Rosepet.openPetS = false;
                                Main.mc.thePlayer.closeScreen();
                                ChatUtils.sendMessage("No pet named " + petName + " found.");
                            }
                        } else {
                            ChatUtils.sendMessage("Invalid Pet Name");
                            Rosepet.openPetS = false;
                        }

                    }
                } else if (sellAll && deb == 0) {
                    selling = true;
                    if (chestName.contains("Bazaar")) {
                        List<Slot> chestInventory = ((GuiChest) Main.mc.currentScreen).inventorySlots.inventorySlots;
                        for (Slot slot : chestInventory) {
                            if (!slot.getHasStack()) continue;
                            if (slot.getStack().getDisplayName().contains("Inventory Now")) {
                                if (slot.getStack().serializeNBT().toString().contains("don't have items")) {
                                    ChatUtils.sendMessage("Couldn't find any items to sell to bazaar");
                                    sellAttempts = 0;
                                    sellAll = false;
                                    selling = false;
                                    Main.mc.thePlayer.closeScreen();
                                } else {
                                    clickSlot(slot.slotNumber, 0, 0);
                                }
                            }
                        }
                    } else if (chestName.contains("you sure?")) {
                        List<Slot> chestInventory = ((GuiChest) Main.mc.currentScreen).inventorySlots.inventorySlots;
                        for (Slot slot : chestInventory) {
                            if (!slot.getHasStack()) continue;
                            if (slot.getStack().getDisplayName().contains("whole inventory")) {
                                clickSlot(slot.slotNumber, 0, 0);
                                sellAttempts++;
                                deb = 5;
                                break;
                            } else if (slot.getStack().getDisplayName().contains("sold!")) {
                                ChatUtils.sendMessage("Sold!");
                                sellAttempts = 0;
                                sellAll = false;
                                selling = false;
                                Main.mc.thePlayer.closeScreen();
                                return;
                            }
                        }
                    }
                } else if(storeInChest && deb == 0) {
                    storing = true;
                    if (chestName.contains("Chest")) {
                        List<Slot> chestInventory = ((GuiChest) Main.mc.currentScreen).inventorySlots.inventorySlots;
                        for (Slot slot : chestInventory) {
                            if (!slot.getHasStack()) continue;
                            if(slot.slotNumber < 53) continue;
                            String display = slot.getStack().getDisplayName().toLowerCase();
                            for(String drop : endermanDrops) {
                                if (display.contains(drop)) {
                                    clickSlot(slot.slotNumber, 0, 1, 0);
                                    deb = 5;
                                    return;
                                }
                            }
                        }
                        ChatUtils.sendMessage("done storing");
                        storeInChest = false;
                        storing = false;
                        openedChest = false;
                        Main.mc.thePlayer.closeScreen();
                    }
                }
            }
        }
    }

    @SubscribeEvent
    public void debounce(TickEvent.ClientTickEvent event) {
        if (event.phase == TickEvent.Phase.END) return;
        if (deb > 0) deb--;
        if(storeInChest && !openedChest && !ShadyRotation.running) {
            storing = true;
            Vec3 chest = closestChest();
            if(chest == null) {
                ChatUtils.sendMessage("No chest found in island, going back to macroing");
                storeInChest = false;
                storing = false;
            } else {
                ShadyRotation.smoothLook(ShadyRotation.vec3ToRotation(chest), Main.configFile.smoothLookVelocity, () -> {
                    rightClick();
                    openedChest = true;
                });
            }
        }
        if (sellAttempts > 9) {
            Main.mc.thePlayer.closeScreen();
            Main.mc.thePlayer.sendChatMessage("/bz");
            sellAttempts = 0;
        }
        if (deb == 0 && didVisit && doVisit) {
            doVisit = false;
            didVisit = false;
            Main.mc.thePlayer.sendChatMessage("/trade " + removeFormatting(SexAura.sender.split(" ")[1]));
            doTrades = true;
            die = 200;
        }
        if (doTrades) {
            if (die > 0) {
                die--;
            }
        }
        if (die == 0) {
            doTrades = false;
            enableChat = 40;
            die = -1;
        }
        if (enableChat > 0) enableChat--;
        if (enableChat == 0) {
            SexAura.blocked = false;
            enableChat = -1;
        }
    }

    @SubscribeEvent
    public void onTick(TickEvent event) {
        if (Main.mc.thePlayer == null || Main.mc.theWorld == null) return;
        if (Main.configFile.stopKeyboard || SexAura.blocked) {
            for (KeyBinding keyBinding : binds) {
                KeyBinding.setKeyBindState(keyBinding.getKeyCode(), false);
            }
        }
    }

    @SubscribeEvent
    public void guiDraw2(GuiScreenEvent.BackgroundDrawnEvent event) {
        if(!doVisit) return;
        if (event.gui instanceof GuiChest) {
            Container container = ((GuiChest) event.gui).inventorySlots;
            if (container instanceof ContainerChest) {
                if (doVisit && deb == 0) {
                    List<Slot> chestInventory = ((GuiChest) Main.mc.currentScreen).inventorySlots.inventorySlots;
                    for (Slot slot : chestInventory) {
                        if (!slot.getHasStack()) continue;
                        if (slot.getStack().getDisplayName().contains("Visit player")) {
                            if (!didVisit) {
                                clickSlot(slot.slotNumber, 0, 0);
                                didVisit = true;
                                deb = 100;
                            }
                        }
                    }
                }
                if (doTrades && deb == 0) {
                    List<Slot> chestInventory = ((GuiChest) Main.mc.currentScreen).inventorySlots.inventorySlots;
                    if (!chestInventory.get(30).getHasStack()) {
                        for (int i = chestInventory.size() - 1; i > 0; i--) {
                            Slot slot = chestInventory.get(i);
                            if (!slot.getHasStack()) continue;
                            if (slot.getStack().getDisplayName().contains("SkyBlock")) continue;
                            if (slot.slotNumber < 44) continue;
                            clickSlot(slot.slotNumber, 1, 0);
                            deb = 5;
                        }
                    }
                    if (chestInventory.get(39).getHasStack() && (chestInventory.get(39).getStack().getDisplayName().contains("Warning!") || chestInventory.get(39).getStack().getDisplayName().contains("Deal!"))) {
                        clickSlot(39, 0, 0);
                        doTrades = false;
                        enableChat = 40;
                    }
                }
            }
        }
    }

    public static void openTradesMenu() {
        openTrades = true;
        Main.mc.thePlayer.sendChatMessage("/pets");
    }

    private void clickSlot(int slot, int type, int windowAdd) {
        Main.mc.playerController.windowClick(Main.mc.thePlayer.openContainer.windowId + windowAdd, slot, type, 0, Main.mc.thePlayer);
    }

    private void clickSlot(int slot, int type, int mode, int windowAdd) {
        Main.mc.playerController.windowClick(Main.mc.thePlayer.openContainer.windowId + windowAdd, slot, type, mode, Main.mc.thePlayer);
    }

    private String removeFormatting(String input) {
        return input.replaceAll("§[0-9a-fk-or]", "");
    }

    private Vec3 closestChest() {
        if (Main.mc.theWorld == null) return null;
        if (Main.mc.thePlayer == null) return null;
        int r = 6;
        BlockPos playerPos = Main.mc.thePlayer.getPosition();
        playerPos.add(0, 1, 0);
        Vec3 playerVec = Main.mc.thePlayer.getPositionVector();
        Vec3i vec3i = new Vec3i(r, r, r);
        ArrayList<Vec3> chests = new ArrayList<>();
        for (BlockPos blockPos : BlockPos.getAllInBox(playerPos.add(vec3i), playerPos.subtract(vec3i))) {
            IBlockState blockState = Main.mc.theWorld.getBlockState(blockPos);
            if (blockState.getBlock() == Blocks.chest) {
                chests.add(new Vec3(blockPos.getX() + 0.5, blockPos.getY(), blockPos.getZ() + 0.5));
            }
        }

        double smallest = 9999;
        Vec3 closest = null;
        for (Vec3 chest : chests) {
            double dist = chest.distanceTo(playerVec);
            if (dist < smallest) {
                smallest = dist;
                closest = chest;
            }
        }
        return closest;
    }

    public static void rightClick() {
        try {
            Method rightClickMouse;
            try {
                rightClickMouse = Minecraft.class.getDeclaredMethod("rightClickMouse");
            } catch (NoSuchMethodException e) {
                rightClickMouse = Minecraft.class.getDeclaredMethod("func_147121_ag");
            }
            rightClickMouse.setAccessible(true);
            rightClickMouse.invoke(Main.mc);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}