diff options
author | DoKM <mcazzyman@gmail.com> | 2021-08-31 15:45:34 +0200 |
---|---|---|
committer | DoKM <mcazzyman@gmail.com> | 2021-08-31 15:45:34 +0200 |
commit | ba051e5f37222737e6655e25ce7ea339fe6bc834 (patch) | |
tree | 7a24b9b4846aa7415b72871b4148f9174f5fc34b /src | |
parent | d7f9b39792d17d8ee204a46b5ff8be3c217ea2a1 (diff) | |
download | NotEnoughUpdates-ba051e5f37222737e6655e25ce7ea339fe6bc834.tar.gz NotEnoughUpdates-ba051e5f37222737e6655e25ce7ea339fe6bc834.tar.bz2 NotEnoughUpdates-ba051e5f37222737e6655e25ce7ea339fe6bc834.zip |
Add Ability for third party mods to disable Inventory Buttons
Per request
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/NEUApi.java | 10 | ||||
-rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java | 192 |
2 files changed, 109 insertions, 93 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUApi.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUApi.java new file mode 100644 index 00000000..56a196b4 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUApi.java @@ -0,0 +1,10 @@ +package io.github.moulberry.notenoughupdates; + +import net.minecraftforge.fml.relauncher.ReflectionHelper; + +public class NEUApi { + static boolean disableInventoryButtons = false; + public static void setInventoryButtonsToDisabled(){ + disableInventoryButtons = true; + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java index 97c31a58..9f55e89e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java @@ -567,6 +567,7 @@ public class NEUEventListener { @SubscribeEvent public void onGuiOpen(GuiOpenEvent event) { CraftingOverlay.shouldRender = false; + NEUApi.disableInventoryButtons = false; if((Minecraft.getMinecraft().currentScreen instanceof GuiScreenElementWrapper || Minecraft.getMinecraft().currentScreen instanceof GuiItemRecipe) && @@ -1022,40 +1023,42 @@ public class NEUEventListener { GlStateManager.translate(0, 0, zOffset); - int xSize = ((GuiContainer)event.gui).xSize; - int ySize = ((GuiContainer)event.gui).ySize; - int guiLeft = ((GuiContainer)event.gui).guiLeft; - int guiTop = ((GuiContainer)event.gui).guiTop; + int xSize = ((GuiContainer) event.gui).xSize; + int ySize = ((GuiContainer) event.gui).ySize; + int guiLeft = ((GuiContainer) event.gui).guiLeft; + int guiTop = ((GuiContainer) event.gui).guiTop; - for(NEUConfig.InventoryButton button : NotEnoughUpdates.INSTANCE.config.hidden.inventoryButtons) { - if(!button.isActive()) continue; - if(button.playerInvOnly && !(event.gui instanceof GuiInventory)) continue; + if (!NEUApi.disableInventoryButtons) { + for (NEUConfig.InventoryButton button : NotEnoughUpdates.INSTANCE.config.hidden.inventoryButtons) { + if (!button.isActive()) continue; + if (button.playerInvOnly && !(event.gui instanceof GuiInventory)) continue; - int x = guiLeft+button.x; - int y = guiTop+button.y; - if(button.anchorRight) { - x += xSize; - } - if(button.anchorBottom) { - y += ySize; - } - if(AccessoryBagOverlay.isInAccessoryBag()){ - if(x > guiLeft + xSize && x < guiLeft + xSize + 80 + 28+ 5 && y > guiTop-18 && y < guiTop + 150){ - x += 80+28; + int x = guiLeft + button.x; + int y = guiTop + button.y; + if (button.anchorRight) { + x += xSize; + } + if (button.anchorBottom) { + y += ySize; + } + if (AccessoryBagOverlay.isInAccessoryBag()) { + if (x > guiLeft + xSize && x < guiLeft + xSize + 80 + 28 + 5 && y > guiTop - 18 && y < guiTop + 150) { + x += 80 + 28; + } } - } GlStateManager.color(1, 1, 1, 1f); GlStateManager.enableDepth(); - GlStateManager.enableAlpha(); - Minecraft.getMinecraft().getTextureManager().bindTexture(EDITOR); - Utils.drawTexturedRect(x, y, 18, 18, - button.backgroundIndex*18/256f, (button.backgroundIndex*18+18)/256f, - 18/256f, 36/256f, GL11.GL_NEAREST); - - if(button.icon != null && !button.icon.trim().isEmpty()) { - GuiInvButtonEditor.renderIcon(button.icon, x+1, y+1); + GlStateManager.enableAlpha(); + Minecraft.getMinecraft().getTextureManager().bindTexture(EDITOR); + Utils.drawTexturedRect(x, y, 18, 18, + button.backgroundIndex * 18 / 256f, (button.backgroundIndex * 18 + 18) / 256f, + 18 / 256f, 36 / 256f, GL11.GL_NEAREST); + + if (button.icon != null && !button.icon.trim().isEmpty()) { + GuiInvButtonEditor.renderIcon(button.icon, x + 1, y + 1); + } } } GlStateManager.translate(0, 0, -zOffset); @@ -1132,51 +1135,53 @@ public class NEUEventListener { if(!doInventoryButtons) return; if(NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard() && shouldRenderOverlay(event.gui) && event.gui instanceof GuiContainer) { - int xSize = ((GuiContainer)event.gui).xSize; - int ySize = ((GuiContainer)event.gui).ySize; - int guiLeft = ((GuiContainer)event.gui).guiLeft; - int guiTop = ((GuiContainer)event.gui).guiTop; - - for(NEUConfig.InventoryButton button : NotEnoughUpdates.INSTANCE.config.hidden.inventoryButtons) { - if(!button.isActive()) continue; - if(button.playerInvOnly && !(event.gui instanceof GuiInventory)) continue; + int xSize = ((GuiContainer) event.gui).xSize; + int ySize = ((GuiContainer) event.gui).ySize; + int guiLeft = ((GuiContainer) event.gui).guiLeft; + int guiTop = ((GuiContainer) event.gui).guiTop; + + if (!NEUApi.disableInventoryButtons) { + for (NEUConfig.InventoryButton button : NotEnoughUpdates.INSTANCE.config.hidden.inventoryButtons) { + if (!button.isActive()) continue; + if (button.playerInvOnly && !(event.gui instanceof GuiInventory)) continue; + + int x = guiLeft + button.x; + int y = guiTop + button.y; + if (button.anchorRight) { + x += xSize; + } + if (button.anchorBottom) { + y += ySize; + } + if (AccessoryBagOverlay.isInAccessoryBag()) { + if (x > guiLeft + xSize && x < guiLeft + xSize + 80 + 28 + 5 && y > guiTop - 18 && y < guiTop + 150) { + x += 80 + 28; + } + } - int x = guiLeft+button.x; - int y = guiTop+button.y; - if(button.anchorRight) { - x += xSize; - } - if(button.anchorBottom) { - y += ySize; - } - if(AccessoryBagOverlay.isInAccessoryBag()){ - if(x > guiLeft + xSize && x < guiLeft + xSize + 80 + 28+ 5 && y > guiTop-18 && y < guiTop + 150){ - x += 80+28; + if (x - guiLeft >= 85 && x - guiLeft <= 115 && y - guiTop >= 4 && y - guiTop <= 25) { + disableCraftingText = true; } - } - if(x-guiLeft >= 85 && x-guiLeft <= 115 && y-guiTop >= 4 && y-guiTop <= 25) { - disableCraftingText = true; - } + if (event.mouseX >= x && event.mouseX <= x + 18 && + event.mouseY >= y && event.mouseY <= y + 18) { + hoveringButton = true; + long currentTime = System.currentTimeMillis(); - if(event.mouseX >= x && event.mouseX <= x+18 && - event.mouseY >= y && event.mouseY <= y+18) { - hoveringButton = true; - long currentTime = System.currentTimeMillis(); + if (buttonHovered != button) { + buttonHoveredMillis = currentTime; + buttonHovered = button; + } - if(buttonHovered != button) { - buttonHoveredMillis = currentTime; - buttonHovered = button; - } + if (currentTime - buttonHoveredMillis > 600) { + String command = button.command.trim(); + if (!command.startsWith("/")) { + command = "/" + command; + } - if(currentTime - buttonHoveredMillis > 600) { - String command = button.command.trim(); - if(!command.startsWith("/")) { - command = "/" + command; + Utils.drawHoveringText(Lists.newArrayList("\u00a77" + command), event.mouseX, event.mouseY, + event.gui.width, event.gui.height, -1, Minecraft.getMinecraft().fontRendererObj); } - - Utils.drawHoveringText(Lists.newArrayList("\u00a77"+command), event.mouseX, event.mouseY, - event.gui.width, event.gui.height, -1, Minecraft.getMinecraft().fontRendererObj); } } } @@ -1479,42 +1484,43 @@ public class NEUEventListener { int ySize = ((GuiContainer)event.gui).ySize; int guiLeft = ((GuiContainer)event.gui).guiLeft; int guiTop = ((GuiContainer)event.gui).guiTop; - - for(NEUConfig.InventoryButton button : NotEnoughUpdates.INSTANCE.config.hidden.inventoryButtons) { - if(!button.isActive()) continue; - if(button.playerInvOnly && !(event.gui instanceof GuiInventory)) continue; - - int x = guiLeft+button.x; - int y = guiTop+button.y; - if(button.anchorRight) { - x += xSize; - } - if(button.anchorBottom) { - y += ySize; - } - if(AccessoryBagOverlay.isInAccessoryBag()){ - if(x > guiLeft + xSize && x < guiLeft + xSize + 80 + 28+ 5 && y > guiTop-18 && y < guiTop + 150){ - x += 80+28; + if(!NEUApi.disableInventoryButtons) { + for (NEUConfig.InventoryButton button : NotEnoughUpdates.INSTANCE.config.hidden.inventoryButtons) { + if (!button.isActive()) continue; + if (button.playerInvOnly && !(event.gui instanceof GuiInventory)) continue; + + int x = guiLeft + button.x; + int y = guiTop + button.y; + if (button.anchorRight) { + x += xSize; + } + if (button.anchorBottom) { + y += ySize; + } + if (AccessoryBagOverlay.isInAccessoryBag()) { + if (x > guiLeft + xSize && x < guiLeft + xSize + 80 + 28 + 5 && y > guiTop - 18 && y < guiTop + 150) { + x += 80 + 28; + } } - } - if(mouseX >= x && mouseX <= x+18 && mouseY >= y && mouseY <= y+18) { - if(Minecraft.getMinecraft().thePlayer.inventory.getItemStack() == null) { - int clickType = NotEnoughUpdates.INSTANCE.config.inventoryButtons.clickType; - if((clickType == 0 && Mouse.getEventButtonState()) || (clickType == 1 && !Mouse.getEventButtonState())) { - String command = button.command.trim(); - if(!command.startsWith("/")) { - command = "/" + command; - } - if(ClientCommandHandler.instance.executeCommand(Minecraft.getMinecraft().thePlayer, command) == 0) { - NotEnoughUpdates.INSTANCE.sendChatMessage(command); + if (mouseX >= x && mouseX <= x + 18 && mouseY >= y && mouseY <= y + 18) { + if (Minecraft.getMinecraft().thePlayer.inventory.getItemStack() == null) { + int clickType = NotEnoughUpdates.INSTANCE.config.inventoryButtons.clickType; + if ((clickType == 0 && Mouse.getEventButtonState()) || (clickType == 1 && !Mouse.getEventButtonState())) { + String command = button.command.trim(); + if (!command.startsWith("/")) { + command = "/" + command; + } + if (ClientCommandHandler.instance.executeCommand(Minecraft.getMinecraft().thePlayer, command) == 0) { + NotEnoughUpdates.INSTANCE.sendChatMessage(command); + } } - } } else { event.setCanceled(true); } return; } + } } } } |