-
-
Notifications
You must be signed in to change notification settings - Fork 223
Expand file tree
/
Copy pathGuiContainerHook.java
More file actions
135 lines (123 loc) · 7.2 KB
/
GuiContainerHook.java
File metadata and controls
135 lines (123 loc) · 7.2 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
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.features.backpacks.ContainerPreviewManager;
import codes.biscuit.skyblockaddons.utils.ColorCode;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ContainerPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.util.ResourceLocation;
public class GuiContainerHook {
private static final ResourceLocation LOCK = new ResourceLocation("skyblockaddons", "lock.png");
private static final int OVERLAY_RED = ColorCode.RED.getColor(127);
private static final int OVERLAY_GREEN = ColorCode.GREEN.getColor(127);
public static void keyTyped(int keyCode) {
ContainerPreviewManager.onContainerKeyTyped(keyCode);
}
public static void drawBackpacks(GuiContainer guiContainer, int mouseX, int mouseY, FontRenderer fontRendererObj) {
ContainerPreviewManager.drawContainerPreviews(guiContainer, mouseX, mouseY);
}
public static void setLastSlot() {
SkyblockAddons.getInstance().getUtils().setLastHoveredSlot(-1);
}
public static void drawGradientRect(GuiContainer guiContainer, int left, int top, int right, int bottom, int startColor, int endColor, Slot theSlot) {
if (ContainerPreviewManager.isFrozen()) {
return;
}
SkyblockAddons main = SkyblockAddons.getInstance();
if (theSlot != null && theSlot.getHasStack() && main.getConfigValues().isEnabled(Feature.DISABLE_EMPTY_GLASS_PANES) && main.getUtils().isEmptyGlassPane(theSlot.getStack())) {
return;
}
Container container = Minecraft.getMinecraft().thePlayer.openContainer;
if (theSlot != null) {
int slotNum = theSlot.slotNumber + main.getInventoryUtils().getSlotDifference(container);
main.getUtils().setLastHoveredSlot(slotNum);
if (main.getConfigValues().isEnabled(Feature.LOCK_SLOTS) &&
main.getUtils().isOnSkyblock() && main.getConfigValues().getLockedSlots().contains(slotNum)
&& (slotNum >= 9 || container instanceof ContainerPlayer && slotNum >= 5)) {
guiContainer.drawGradientRect(left, top, right, bottom, OVERLAY_RED, OVERLAY_RED);
return;
}
}
guiContainer.drawGradientRect(left, top, right, bottom, startColor, endColor);
}
public static void drawSlot(GuiContainer guiContainer, Slot slot) {
SkyblockAddons main = SkyblockAddons.getInstance();
Minecraft mc = Minecraft.getMinecraft();
Container container = mc.thePlayer.openContainer;
if (slot != null) {
if (main.getConfigValues().isEnabled(Feature.LOCK_SLOTS) &&
main.getUtils().isOnSkyblock()) {
int slotNum = slot.slotNumber + main.getInventoryUtils().getSlotDifference(container);
if (main.getConfigValues().getLockedSlots().contains(slotNum)
&& (slotNum >= 9 || container instanceof ContainerPlayer && slotNum >= 5)) {
GlStateManager.disableLighting();
GlStateManager.disableDepth();
GlStateManager.color(1,1,1,0.4F);
GlStateManager.enableBlend();
mc.getTextureManager().bindTexture(LOCK);
mc.ingameGUI.drawTexturedModalRect(slot.xDisplayPosition, slot.yDisplayPosition, 0, 0, 16, 16);
GlStateManager.enableLighting();
GlStateManager.enableDepth();
}
}
}
}
public static void keyTyped(GuiContainer guiContainer, int keyCode, Slot theSlot, ReturnValue<?> returnValue) {
SkyblockAddons main = SkyblockAddons.getInstance();
Minecraft mc = Minecraft.getMinecraft();
if (main.getUtils().isOnSkyblock()) {
if (main.getConfigValues().isEnabled(Feature.LOCK_SLOTS) && (keyCode != 1 && keyCode != mc.gameSettings.keyBindInventory.getKeyCode())) {
int slot = main.getUtils().getLastHoveredSlot();
boolean isHotkeying = false;
if (mc.thePlayer.inventory.getItemStack() == null && theSlot != null) {
for (int i = 0; i < 9; ++i) {
if (keyCode == mc.gameSettings.keyBindsHotbar[i].getKeyCode()) {
slot = i + 36; // They are hotkeying, the actual slot is the targeted one, +36 because
isHotkeying = true;
}
}
}
if (slot >= 9 || mc.thePlayer.openContainer instanceof ContainerPlayer && slot >= 5) {
if (main.getConfigValues().getLockedSlots().contains(slot)) {
if (main.getLockSlotKey().getKeyCode() == keyCode) {
main.getUtils().playLoudSound("random.orb", 1);
main.getConfigValues().getLockedSlots().remove(slot);
main.getConfigValues().saveConfig();
} else if (isHotkeying || mc.gameSettings.keyBindDrop.getKeyCode() == keyCode) {
// Only buttons that would cause an item to move/drop out of the slot will be canceled
returnValue.cancel(); // slot is locked
main.getUtils().playLoudSound("note.bass", 0.5);
return;
}
} else {
if (main.getLockSlotKey().getKeyCode() == keyCode) {
main.getUtils().playLoudSound("random.orb", 0.1);
main.getConfigValues().getLockedSlots().add(slot);
main.getConfigValues().saveConfig();
}
}
}
}
if (mc.gameSettings.keyBindDrop.getKeyCode() == keyCode && main.getConfigValues().isEnabled(Feature.STOP_DROPPING_SELLING_RARE_ITEMS) && !main.getUtils().isInDungeon()) {
if (!main.getUtils().getItemDropChecker().canDropItem(theSlot)) returnValue.cancel();
}
}
}
/**
* This method returns true to CANCEL the click in a GUI (lol I get confused)
*/
public static boolean onHandleMouseClick(Slot slot, int slotId, int clickedButton, int clickType) {
SkyblockAddons main = SkyblockAddons.getInstance();
return slot != null && slot.getHasStack() && main.getConfigValues().isEnabled(Feature.DISABLE_EMPTY_GLASS_PANES) &&
main.getUtils().isEmptyGlassPane(slot.getStack()) && main.getUtils().isOnSkyblock() && !main.getUtils().isInDungeon() &&
(main.getInventoryUtils().getInventoryType() != InventoryType.ULTRASEQUENCER || main.getUtils().isGlassPaneColor(slot.getStack(), EnumDyeColor.BLACK));
}
}