-
-
Notifications
You must be signed in to change notification settings - Fork 223
Expand file tree
/
Copy pathGuiChestHook.java
More file actions
469 lines (409 loc) · 23.3 KB
/
GuiChestHook.java
File metadata and controls
469 lines (409 loc) · 23.3 KB
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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
package codes.biscuit.skyblockaddons.asm.hooks;
import codes.biscuit.skyblockaddons.SkyblockAddons;
import codes.biscuit.skyblockaddons.asm.utils.ReturnValue;
import codes.biscuit.skyblockaddons.core.Feature;
import codes.biscuit.skyblockaddons.core.InventoryType;
import codes.biscuit.skyblockaddons.core.Message;
import codes.biscuit.skyblockaddons.core.npc.NPCUtils;
import codes.biscuit.skyblockaddons.features.backpacks.BackpackColor;
import codes.biscuit.skyblockaddons.features.backpacks.BackpackInventoryManager;
import codes.biscuit.skyblockaddons.features.backpacks.ContainerPreviewManager;
import codes.biscuit.skyblockaddons.gui.IslandWarpGui;
import codes.biscuit.skyblockaddons.utils.ColorCode;
import codes.biscuit.skyblockaddons.utils.DrawUtils;
import codes.biscuit.skyblockaddons.utils.ItemUtils;
import lombok.Getter;
import lombok.Setter;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.gui.inventory.GuiChest;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Items;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ContainerChest;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import org.apache.commons.lang3.StringUtils;
import org.lwjgl.input.Keyboard;
import java.io.IOException;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
//TODO Fix for Hypixel localization
public class GuiChestHook {
private static GuiTextField textFieldMatch = null;
private static GuiTextField textFieldExclusions = null;
@Setter
@Getter
private static String lastAccessoryBagReforge = null;
private static final Pattern warpPattern = Pattern.compile("(?:§5§o)?§8/warp ([a-z_]*)");
private static final Pattern unlockedPattern = Pattern.compile("(?:§5§o)?§eClick to warp!");
private static final Pattern notUnlockedPattern = Pattern.compile("(?:§5§o)?§cWarp not unlocked!");
private static final Pattern inCombatPattern = Pattern.compile("(?:§5§o)?§cYou're in combat!");
private static final Pattern youAreHerePattern = Pattern.compile("(?:§5§o)?§aYou are here!");
private static IslandWarpGui islandWarpGui = null;
public static void updateScreen() {
if (textFieldMatch != null && textFieldExclusions != null) {
textFieldMatch.updateCursorCounter();
textFieldExclusions.updateCursorCounter();
}
}
/**
* Resets variables when the chest is closed
*/
public static void onGuiClosed() {
SkyblockAddons.getInstance().getInventoryUtils().updateInventoryType();
Keyboard.enableRepeatEvents(false);
islandWarpGui = null;
BackpackInventoryManager.setBackpackColor(null);
}
public static void drawScreenIslands(int mouseX, int mouseY, ReturnValue<?> returnValue) {
Minecraft mc = Minecraft.getMinecraft();
Container playerContainer = mc.thePlayer.openContainer;
if (playerContainer instanceof ContainerChest && SkyblockAddons.getInstance().getConfigValues().isEnabled(Feature.FANCY_WARP_MENU)) {
IInventory chestInventory = ((ContainerChest) playerContainer).getLowerChestInventory();
if (chestInventory.hasCustomName()) {
String chestName = chestInventory.getDisplayName().getUnformattedText();
if (chestName.equals("Fast Travel")) {
Map<IslandWarpGui.Marker, IslandWarpGui.UnlockedStatus> markers = new EnumMap<>(IslandWarpGui.Marker.class);
for (int slot = 0; slot < chestInventory.getSizeInventory(); slot++) {
ItemStack itemStack = chestInventory.getStackInSlot(slot);
if (itemStack != null && (Items.skull == itemStack.getItem() || Items.paper == itemStack.getItem())) {
List<String> lore = ItemUtils.getItemLore(itemStack);
IslandWarpGui.Marker marker = null;
IslandWarpGui.UnlockedStatus status = IslandWarpGui.UnlockedStatus.UNKNOWN;
for (String loreLine : lore) {
Matcher matcher = warpPattern.matcher(loreLine);
if (matcher.matches()) {
marker = IslandWarpGui.Marker.fromWarpName(matcher.group(1));
}
matcher = unlockedPattern.matcher(loreLine);
if (matcher.matches() || youAreHerePattern.matcher(loreLine).matches()) {
status = IslandWarpGui.UnlockedStatus.UNLOCKED;
break;
}
matcher = notUnlockedPattern.matcher(loreLine);
if (matcher.matches()) {
status = IslandWarpGui.UnlockedStatus.NOT_UNLOCKED;
break;
}
matcher = inCombatPattern.matcher(loreLine);
if (matcher.matches()) {
status = IslandWarpGui.UnlockedStatus.IN_COMBAT;
break;
}
}
if (marker != null) {
markers.put(marker, status);
}
}
}
for (IslandWarpGui.Marker marker : IslandWarpGui.Marker.values()) {
if (!markers.containsKey(marker)) {
markers.put(marker, IslandWarpGui.UnlockedStatus.UNKNOWN);
}
}
markers.put(IslandWarpGui.Marker.DWARVEN_FORGE, markers.getOrDefault(IslandWarpGui.Marker.DEEP_CAVERNS, IslandWarpGui.UnlockedStatus.UNKNOWN));
markers.put(IslandWarpGui.Marker.DUNGEON_HUB_ISLAND, markers.getOrDefault(IslandWarpGui.Marker.DUNGEON_HUB, IslandWarpGui.UnlockedStatus.UNKNOWN));
if (islandWarpGui == null || !islandWarpGui.getMarkers().equals(markers)) {
islandWarpGui = new IslandWarpGui(markers);
ScaledResolution scaledresolution = new ScaledResolution(mc);
int i = scaledresolution.getScaledWidth();
int j = scaledresolution.getScaledHeight();
islandWarpGui.setWorldAndResolution(mc, i, j);
}
try {
islandWarpGui.drawScreen(mouseX, mouseY, 0);
} catch (Throwable ex) {
ex.printStackTrace();
}
returnValue.cancel();
} else {
islandWarpGui = null;
}
} else {
islandWarpGui = null;
}
} else {
islandWarpGui = null;
}
}
public static void drawScreen(int guiLeft, int guiTop) {
InventoryType inventoryType = SkyblockAddons.getInstance().getInventoryUtils().updateInventoryType();
if (inventoryType == InventoryType.SALVAGING) {
int ySize = 222 - 108 + 6 * 18;
float x = guiLeft - 69 - 5;
float y = guiTop + ySize / 2F - 72 / 2F;
SkyblockAddons.getInstance().getRenderListener().drawCollectedEssences(x, y, false, false);
} else if (inventoryType == InventoryType.STORAGE_BACKPACK) {
ContainerPreviewManager.saveStorageContainerInventory(SkyblockAddons.getInstance().getInventoryUtils().getInventoryKey());
} else if (inventoryType == InventoryType.ENDER_CHEST) {
ContainerPreviewManager.saveStorageContainerInventory(SkyblockAddons.getInstance().getInventoryUtils().getInventoryKey());
}
if (SkyblockAddons.getInstance().getConfigValues().isEnabled(Feature.REFORGE_FILTER) && textFieldMatch != null &&
(inventoryType== InventoryType.BASIC_REFORGING ||
inventoryType == InventoryType.BASIC_ACCESSORY_BAG_REFORGING)) {
Minecraft mc = Minecraft.getMinecraft();
SkyblockAddons main = SkyblockAddons.getInstance();
String typeToMatch = Message.MESSAGE_REFORGES.getMessage();
String inclusionExample;
String exclusionExample;
int defaultBlue = main.getUtils().getDefaultBlue(255);
float scale = 0.75F;
int x = guiLeft - 160;
if (x<0) {
x = 20;
}
inclusionExample = Message.MESSAGE_REFORGE_INCLUSION_EXAMPLE.getMessage();
exclusionExample = Message.MESSAGE_REFORGE_EXCLUSION_EXAMPLE.getMessage();
GlStateManager.color(1F, 1F, 1F);
GlStateManager.pushMatrix();
GlStateManager.scale(scale, scale, 1);
mc.fontRendererObj.drawString(Message.MESSAGE_TYPE_ENCHANTMENTS.getMessage(typeToMatch), Math.round(x/scale), Math.round((guiTop+40)/scale), defaultBlue);
int width = mc.fontRendererObj.getStringWidth(Message.MESSAGE_SEPARATE_ENCHANTMENTS.getMessage());
if (width > guiLeft - x) {
mc.fontRendererObj.drawSplitString(Message.MESSAGE_SEPARATE_ENCHANTMENTS.getMessage(), Math.round(x/scale), Math.round((guiTop + 50)/scale), textFieldMatch.width - x, defaultBlue);
} else {
mc.fontRendererObj.drawString(Message.MESSAGE_SEPARATE_ENCHANTMENTS.getMessage(), Math.round(x/scale), Math.round((guiTop + 50)/scale), defaultBlue);
}
mc.fontRendererObj.drawString(Message.MESSAGE_ENCHANTS_TO_MATCH.getMessage(typeToMatch), Math.round(x/scale), Math.round((guiTop + 70)/scale), defaultBlue);
mc.fontRendererObj.drawString(Message.MESSAGE_ENCHANTS_TO_EXCLUDE.getMessage(typeToMatch), Math.round(x/scale), Math.round((guiTop + 110)/scale), defaultBlue);
GlStateManager.popMatrix();
textFieldMatch.drawTextBox();
if (StringUtils.isEmpty(textFieldMatch.getText())) {
mc.fontRendererObj.drawString(inclusionExample, x+4, guiTop + 86, ColorCode.DARK_GRAY.getColor());
}
textFieldExclusions.drawTextBox();
if (StringUtils.isEmpty(textFieldExclusions.getText())) {
mc.fontRendererObj.drawString(exclusionExample, x+4, guiTop + 126, ColorCode.DARK_GRAY.getColor());
}
}
}
public static void initGui(IInventory lowerChestInventory, int guiLeft, int guiTop, FontRenderer fontRendererObj) {
if (!SkyblockAddons.getInstance().getUtils().isOnSkyblock()) {
return; // don't draw any overlays outside SkyBlock
}
InventoryType inventoryType = SkyblockAddons.getInstance().getInventoryUtils().updateInventoryType();
if (inventoryType != null) {
if (SkyblockAddons.getInstance().getConfigValues().isEnabled(Feature.REFORGE_FILTER) && inventoryType ==
InventoryType.BASIC_REFORGING || inventoryType == InventoryType.BASIC_ACCESSORY_BAG_REFORGING) {
int xPos = guiLeft - 160;
if (xPos<0) {
xPos = 20;
}
int yPos = guiTop + 80;
textFieldMatch = new GuiTextField(2, fontRendererObj, xPos, yPos, 120, 20);
textFieldMatch.setMaxStringLength(500);
List<String> lockedReforges = SkyblockAddons.getInstance().getUtils().getReforgeMatches();
StringBuilder reforgeBuilder = new StringBuilder();
int i = 1;
for (String reforge : lockedReforges) {
reforgeBuilder.append(reforge);
if (i < lockedReforges.size()) {
reforgeBuilder.append(",");
}
i++;
}
String text = reforgeBuilder.toString();
if (text.length() > 0) {
textFieldMatch.setText(text);
}
yPos += 40;
textFieldExclusions = new GuiTextField(2, fontRendererObj, xPos, yPos, 120, 20);
textFieldExclusions.setMaxStringLength(500);
lockedReforges = SkyblockAddons.getInstance().getUtils().getReforgeExclusions();
reforgeBuilder = new StringBuilder();
i = 1;
for (String enchantment : lockedReforges) {
reforgeBuilder.append(enchantment);
if (i < lockedReforges.size()) {
reforgeBuilder.append(",");
}
i++;
}
text = reforgeBuilder.toString();
if (text.length() > 0) {
textFieldExclusions.setText(text);
}
Keyboard.enableRepeatEvents(true);
}
}
}
public static boolean keyTyped(char typedChar, int keyCode) { // return whether to continue (super.keyTyped(typedChar, keyCode);)
SkyblockAddons main = SkyblockAddons.getInstance();
if (main.getUtils().isOnSkyblock() && main.getConfigValues().isEnabled(Feature.REFORGE_FILTER)) {
InventoryType inventoryType = main.getInventoryUtils().getInventoryType();
if (inventoryType== InventoryType.BASIC_REFORGING || inventoryType == InventoryType.BASIC_ACCESSORY_BAG_REFORGING) {
if (keyCode != Minecraft.getMinecraft().gameSettings.keyBindInventory.getKeyCode() ||
(!textFieldMatch.isFocused() && !textFieldExclusions.isFocused())) {
processTextFields(typedChar, keyCode);
return true;
}
processTextFields(typedChar, keyCode);
} else {
return true;
}
return false;
} else {
return true;
}
}
private static void processTextFields(char typedChar, int keyCode) {
SkyblockAddons main = SkyblockAddons.getInstance();
if (main.getConfigValues().isEnabled(Feature.REFORGE_FILTER) && textFieldMatch != null) {
textFieldMatch.textboxKeyTyped(typedChar, keyCode);
textFieldExclusions.textboxKeyTyped(typedChar, keyCode);
List<String> reforges = new LinkedList<>(Arrays.asList(textFieldMatch.getText().split(",")));
main.getUtils().setReforgeMatches(reforges);
reforges = new LinkedList<>(Arrays.asList(textFieldExclusions.getText().split(",")));
main.getUtils().setReforgeExclusions(reforges);
}
}
public static void handleMouseClick(Slot slotIn, Container slots, IInventory lowerChestInventory, ReturnValue<?> returnValue) {
SkyblockAddons main = SkyblockAddons.getInstance();
if (main.getUtils().isOnSkyblock()) {
if (main.getConfigValues().isEnabled(Feature.REFORGE_FILTER) && !main.getUtils().getReforgeMatches().isEmpty()) {
if (slotIn != null && !slotIn.inventory.equals(Minecraft.getMinecraft().thePlayer.inventory) && slotIn.getHasStack()) {
InventoryType inventoryType = main.getInventoryUtils().getInventoryType();
if (slotIn.getSlotIndex() == 22 && (inventoryType == InventoryType.BASIC_REFORGING || inventoryType == InventoryType.BASIC_ACCESSORY_BAG_REFORGING)) {
Slot itemSlot = slots.getSlot(13);
if (itemSlot != null && itemSlot.getHasStack()) {
if (inventoryType == InventoryType.BASIC_REFORGING) {
ItemStack item = itemSlot.getStack();
if (item.hasDisplayName()) {
String reforge = ItemUtils.getReforge(item);
if (reforge != null) {
if (main.getUtils().enchantReforgeMatches(reforge)) {
main.getUtils().playLoudSound("random.orb", 0.1);
returnValue.cancel();
}
}
}
} else {
if (lastAccessoryBagReforge != null && main.getUtils().enchantReforgeMatches(lastAccessoryBagReforge)) {
main.getUtils().playLoudSound("random.orb", 0.1);
returnValue.cancel();
}
}
}
}
}
}
if (main.getConfigValues().isEnabled(Feature.STOP_DROPPING_SELLING_RARE_ITEMS) && !main.getUtils().isInDungeon() &&
NPCUtils.isSellMerchant(lowerChestInventory) && slotIn != null && slotIn.inventory instanceof InventoryPlayer) {
if (!main.getUtils().getItemDropChecker().canDropItem(slotIn)) {
returnValue.cancel();
}
}
}
}
// TODO: Replace ASM?
public static void mouseClicked(int mouseX, int mouseY, int mouseButton, ReturnValue<?> returnValue) throws IOException {
if (islandWarpGui != null) {
islandWarpGui.mouseClicked(mouseX, mouseY, mouseButton);
returnValue.cancel();
return;
}
if (textFieldMatch != null) {
textFieldMatch.mouseClicked(mouseX, mouseY, mouseButton);
textFieldExclusions.mouseClicked(mouseX, mouseY, mouseButton);
}
}
public static void color(float colorRed, float colorGreen, float colorBlue, float colorAlpha, IInventory lowerChestInventory) { //Item item, ItemStack stack
SkyblockAddons main = SkyblockAddons.getInstance();
if (!main.getUtils().isOnSkyblock()) {
return;
}
Minecraft mc = Minecraft.getMinecraft();
if (main.getConfigValues().isEnabled(Feature.SHOW_BACKPACK_PREVIEW) &&
main.getConfigValues().isEnabled(Feature.MAKE_BACKPACK_INVENTORIES_COLORED) && lowerChestInventory.hasCustomName()) {
if (lowerChestInventory.getDisplayName().getUnformattedText().contains("Backpack")) {
if (BackpackInventoryManager.getBackpackColor() != null) {
BackpackColor color = BackpackInventoryManager.getBackpackColor();
GlStateManager.color(color.getR(), color.getG(), color.getB(), 1);
return;
}
} else if (lowerChestInventory.getDisplayName().getUnformattedText().contains("Bank")) {
ItemStack item = mc.thePlayer.getHeldItem(); // easter egg question mark
if (item != null && item.hasDisplayName() && item.getDisplayName().contains("Piggy Bank")) {
BackpackColor color = BackpackColor.PINK;
GlStateManager.color(color.getR(), color.getG(), color.getB(), 1);
}
return;
}
}
GlStateManager.color(colorRed,colorGreen,colorBlue,colorAlpha);
}
public static int drawString(FontRenderer fontRenderer, String text, int x, int y, int color) {
SkyblockAddons main = SkyblockAddons.getInstance();
if (main.getUtils().isOnSkyblock() && main.getConfigValues().isEnabled(Feature.SHOW_BACKPACK_PREVIEW) &&
main.getConfigValues().isEnabled(Feature.MAKE_BACKPACK_INVENTORIES_COLORED) && BackpackInventoryManager.getBackpackColor() != null) {
return fontRenderer.drawString(text, x,y, BackpackInventoryManager.getBackpackColor().getInventoryTextColor());
}
return fontRenderer.drawString(text,x,y,color);
}
public static void mouseReleased(ReturnValue<?> returnValue) {
if (islandWarpGui != null) {
returnValue.cancel();
}
}
public static void mouseClickMove(ReturnValue<?> returnValue) {
if (islandWarpGui != null) {
returnValue.cancel();
}
}
public static void onRenderChestForegroundLayer(GuiChest guiChest) {
SkyblockAddons main = SkyblockAddons.getInstance();
if (main.getConfigValues().isEnabled(Feature.SHOW_REFORGE_OVERLAY)) {
Minecraft mc = Minecraft.getMinecraft();
if (guiChest.inventorySlots.inventorySlots.size() > 13) {
Slot slot = guiChest.inventorySlots.inventorySlots.get(13);
if (slot != null) {
ItemStack item = slot.getStack();
if (item != null) {
String reforge = null;
if (main.getInventoryUtils().getInventoryType() == InventoryType.BASIC_REFORGING) {
reforge = ItemUtils.getReforge(item);
} else if (main.getInventoryUtils().getInventoryType() == InventoryType.BASIC_ACCESSORY_BAG_REFORGING) {
reforge = GuiChestHook.getLastAccessoryBagReforge();
}
if (reforge != null) {
int color = ColorCode.YELLOW.getColor();
if (main.getConfigValues().isEnabled(Feature.REFORGE_FILTER) &&
!main.getUtils().getReforgeMatches().isEmpty() &&
main.getUtils().enchantReforgeMatches(reforge)) {
color = ColorCode.RED.getColor();
}
int x = slot.xDisplayPosition;
int y = slot.yDisplayPosition;
int stringWidth = mc.fontRendererObj.getStringWidth(reforge);
float renderX = x - 28 - stringWidth / 2F;
int renderY = y + 22;
GlStateManager.disableDepth();
drawTooltipBackground(renderX, renderY, stringWidth, 8);
mc.fontRendererObj.drawString(reforge, renderX, renderY, color, true);
GlStateManager.enableDepth();
}
}
}
}
}
}
private static void drawTooltipBackground(float x, float y, float width, float height) {
int l = -267386864;
DrawUtils.drawRectAbsolute(x - 3, y - 4, x + width + 3, y - 3, l);
DrawUtils.drawRectAbsolute(x - 3, y + height + 3, x + width + 3, y + height + 4, l);
DrawUtils.drawRectAbsolute(x - 3, y - 3, x + width + 3, y + height + 3, l);
DrawUtils.drawRectAbsolute(x - 4, y - 3, x - 3, y + height + 3, l);
DrawUtils.drawRectAbsolute(x + width + 3, y - 3, x + width + 4, y + height + 3, l);
int borderColor = 1347420415;
DrawUtils.drawRectAbsolute(x - 3, y - 3 + 1, x - 3 + 1, y + height + 3 - 1, borderColor);
DrawUtils.drawRectAbsolute(x + width + 2, y - 3 + 1, x + width + 3, y + height + 3 - 1, borderColor);
DrawUtils.drawRectAbsolute(x - 3, y - 3, x + width + 3, y - 3 + 1, borderColor);
DrawUtils.drawRectAbsolute(x - 3, y + height + 2, x + width + 3, y + height + 3, borderColor);
}
}