diff options
author | Roman / Nea <roman.graef@gmail.com> | 2022-01-16 01:02:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-15 19:02:23 -0500 |
commit | 2aa911fa84399a5a8cc9f36715246c7f3eee7133 (patch) | |
tree | aa4ef88d1fee55727102ff30f97dc157e1744b90 /src | |
parent | 1b43f822ad82efe33b983338f328d52f22d23957 (diff) | |
download | NotEnoughUpdates-2aa911fa84399a5a8cc9f36715246c7f3eee7133.tar.gz NotEnoughUpdates-2aa911fa84399a5a8cc9f36715246c7f3eee7133.tar.bz2 NotEnoughUpdates-2aa911fa84399a5a8cc9f36715246c7f3eee7133.zip |
Fix crafting overlay (#64)
* Fix crafting overlay
* bbbbbbbbbbbbbbbbbbbbbbbbbb
* Update src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java
* Update src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java
* Update src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java
* Update src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java
* Update src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java
* Update src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java
* Update src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java
* Update src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java
* Update src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java
Co-authored-by: IRONM00N <64110067+IRONM00N@users.noreply.github.com>
Diffstat (limited to 'src')
6 files changed, 199 insertions, 161 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java index 65e121eb..4b6cd511 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java @@ -20,6 +20,7 @@ import io.github.moulberry.notenoughupdates.miscgui.*; import io.github.moulberry.notenoughupdates.options.NEUConfig; import io.github.moulberry.notenoughupdates.overlays.*; import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer; +import io.github.moulberry.notenoughupdates.recipes.CraftingOverlay; import io.github.moulberry.notenoughupdates.util.*; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.*; @@ -585,7 +586,6 @@ public class NEUEventListener { @SubscribeEvent public void onGuiOpen(GuiOpenEvent event) { - CraftingOverlay.shouldRender = false; NEUApi.disableInventoryButtons = false; if ((Minecraft.getMinecraft().currentScreen instanceof GuiScreenElementWrapper || @@ -1142,14 +1142,6 @@ public class NEUEventListener { String containerName = null; GuiScreen guiScreen = Minecraft.getMinecraft().currentScreen; - if (guiScreen instanceof GuiChest) { - GuiChest eventGui = (GuiChest) guiScreen; - ContainerChest cc = (ContainerChest) eventGui.inventorySlots; - containerName = cc.getLowerChestInventory().getDisplayName().getUnformattedText(); - if (containerName.equals("Craft Item")) { - CraftingOverlay.render(); - } - } if (GuiCustomEnchant.getInstance().shouldOverride(containerName)) { return; @@ -1651,14 +1643,6 @@ public class NEUEventListener { String containerName = null; GuiScreen guiScreen = Minecraft.getMinecraft().currentScreen; - if (guiScreen instanceof GuiChest) { - GuiChest eventGui = (GuiChest) guiScreen; - ContainerChest cc = (ContainerChest) eventGui.inventorySlots; - containerName = cc.getLowerChestInventory().getDisplayName().getUnformattedText(); - if (CraftingOverlay.shouldRender && containerName.equals("Craft Item")) { - CraftingOverlay.keyInput(); - } - } if (GuiCustomEnchant.getInstance().shouldOverride(containerName) && GuiCustomEnchant.getInstance().keyboardInput()) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java index b3d13351..e5497cd0 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java @@ -3,7 +3,7 @@ package io.github.moulberry.notenoughupdates; import com.google.gson.*; import io.github.moulberry.notenoughupdates.auction.APIManager; import io.github.moulberry.notenoughupdates.miscgui.GuiItemRecipe; -import io.github.moulberry.notenoughupdates.overlays.CraftingOverlay; +import io.github.moulberry.notenoughupdates.recipes.CraftingOverlay; import io.github.moulberry.notenoughupdates.recipes.CraftingRecipe; import io.github.moulberry.notenoughupdates.recipes.Ingredient; import io.github.moulberry.notenoughupdates.recipes.NeuRecipe; @@ -22,7 +22,8 @@ import org.apache.commons.io.FileUtils; import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.Display; -import javax.swing.*; +import javax.swing.JDialog; +import javax.swing.JOptionPane; import java.io.*; import java.net.URL; import java.net.URLConnection; @@ -80,11 +81,14 @@ public class NEUManager { public File configFile; public HotmInformation hotm; + public CraftingOverlay craftingOverlay; + public NEUManager(NotEnoughUpdates neu, File configLocation) { this.neu = neu; this.configLocation = configLocation; this.auctionManager = new APIManager(this); this.hotm = new HotmInformation(neu); + this.craftingOverlay = new CraftingOverlay(this); GIT_COMMITS_URL = neu.config.hidden.repoCommitsURL; @@ -127,16 +131,16 @@ public class NEUManager { public void resetRepo() { try { Utils.recursiveDelete(new File(configLocation, "repo")); - } catch (Exception ignored) {} + } catch (Exception ignored) { + } try { new File(configLocation, "currentCommit.json").delete(); } catch (Exception ignored) {} } /** - * Called when the game is first loaded. Compares the local repository to the github repository and handles - * the downloading of new/updated files. This then calls the "loadItem" method for every item in the local - * repository. + * Called when the game is first loaded. Compares the local repository to the github repository and handles the + * downloading of new/updated files. This then calls the "loadItem" method for every item in the local repository. */ public void loadItemInformation() { /*File repoFile = new File(configLocation, "repo2"); @@ -315,8 +319,8 @@ public class NEUManager { } /** - * Loads the item in to the itemMap and also stores various words associated with this item - * in to titleWordMap and loreWordMap. These maps are used in the searching algorithm. + * Loads the item in to the itemMap and also stores various words associated with this item in to titleWordMap and + * loreWordMap. These maps are used in the searching algorithm. */ public void loadItem(String internalName) { itemstackCache.remove(internalName); @@ -418,8 +422,8 @@ public class NEUManager { } /** - * Searches a string for a query. This method is used to mimic the behaviour of the - * more complex map-based search function. This method is used for the chest-item-search feature. + * Searches a string for a query. This method is used to mimic the behaviour of the more complex map-based search + * function. This method is used for the chest-item-search feature. */ public boolean searchString(String toSearch, String query) { int lastMatch = -1; @@ -443,8 +447,8 @@ public class NEUManager { } /** - * Checks whether an itemstack matches a certain query, following the same rules implemented by the - * more complex map-based search function. + * Checks whether an itemstack matches a certain query, following the same rules implemented by the more complex + * map-based search function. */ public boolean doesStackMatchSearch(ItemStack stack, String query) { if (query.startsWith("title:")) { @@ -498,8 +502,7 @@ public class NEUManager { } /** - * Calls search for each query, separated by | - * eg. search(A|B) = search(A) + search(B) + * Calls search for each query, separated by | eg. search(A|B) = search(A) + search(B) */ public Set<String> search(String query, boolean multi) { if (multi) { @@ -607,11 +610,10 @@ public class NEUManager { } /** - * Splits a search query into an array of strings delimited by a space character. Then, matches the query to - * the start of words in the various maps (title & lore). The small query does not need to match the whole entry - * of the map, only the beginning. eg. "ench" and "encha" will both match "enchanted". All sub queries must - * follow a word matching the previous sub query. eg. "ench po" will match "enchanted pork" but will not match - * "pork enchanted". + * Splits a search query into an array of strings delimited by a space character. Then, matches the query to the + * start of words in the various maps (title & lore). The small query does not need to match the whole entry of the + * map, only the beginning. eg. "ench" and "encha" will both match "enchanted". All sub queries must follow a word + * matching the previous sub query. eg. "ench po" will match "enchanted pork" but will not match "pork enchanted". */ public Set<String> search(String query, TreeMap<String, HashMap<String, List<Integer>>> wordMap) { HashMap<String, List<Integer>> matches = null; @@ -850,7 +852,7 @@ public class NEUManager { if (container != null && container.getLowerChestInventory().getDisplayName().getUnformattedText().equals("Craft Item")) { Optional<NeuRecipe> recipe = recipesFor.stream().filter(it -> it instanceof CraftingRecipe).findAny(); if (recipe.isPresent()) { - CraftingOverlay.updateItem((CraftingRecipe) recipe.get()); + craftingOverlay.setShownRecipe((CraftingRecipe) recipe.get()); return; } } @@ -866,6 +868,10 @@ public class NEUManager { displayGuiItemRecipe(internalName, ""); } + public void showRecipe(String internalName) { + showRecipe(getItemInformation().get(internalName)); + } + /** * Takes an item stack and produces a JsonObject. */ @@ -947,7 +953,6 @@ public class NEUManager { if (!usagesMap.containsKey(internalName)) return false; Set<NeuRecipe> usages = usagesMap.get(internalName); if (usages.isEmpty()) return false; - Utils.sendCloseScreenPacket(); Minecraft.getMinecraft().displayGuiScreen( new GuiItemRecipe("Item Usages", new ArrayList<>(usages), this)); return true; @@ -957,7 +962,6 @@ public class NEUManager { if (!recipesMap.containsKey(internalName)) return false; Set<NeuRecipe> recipes = recipesMap.get(internalName); if (recipes.isEmpty()) return false; - Utils.sendCloseScreenPacket(); Minecraft.getMinecraft().displayGuiScreen( new GuiItemRecipe(text != null ? text : "Item Recipe", new ArrayList<>(recipes), this)); return true; @@ -1085,8 +1089,8 @@ public class NEUManager { } /** - * From here to the end of the file are various helper functions for creating and writing json files, - * in particular json files representing skyblock item data. + * From here to the end of the file are various helper functions for creating and writing json files, in particular + * json files representing skyblock item data. */ public JsonObject createItemJson(String internalname, String itemid, String displayname, String[] lore, String crafttext, String infoType, String[] info, diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/CraftingOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/CraftingOverlay.java deleted file mode 100644 index c0cbef0f..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/CraftingOverlay.java +++ /dev/null @@ -1,103 +0,0 @@ -package io.github.moulberry.notenoughupdates.overlays; - -import com.google.gson.JsonObject; -import io.github.moulberry.notenoughupdates.NEUManager; -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.recipes.CraftingRecipe; -import io.github.moulberry.notenoughupdates.recipes.Ingredient; -import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.Gui; -import net.minecraft.client.gui.inventory.GuiChest; -import net.minecraft.inventory.ContainerChest; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import org.lwjgl.input.Keyboard; -import org.lwjgl.input.Mouse; - -import java.util.List; - -public class CraftingOverlay { - private static final ItemStack[] items = new ItemStack[9]; - private static final NEUManager manager = NotEnoughUpdates.INSTANCE.manager; - public static boolean shouldRender = false; - private static String text = null; - - public static void render() { - if (shouldRender) { - ContainerChest container = (ContainerChest) Minecraft.getMinecraft().thePlayer.openContainer; - GuiChest gc = (GuiChest) Minecraft.getMinecraft().currentScreen; - FontRenderer ft = Minecraft.getMinecraft().fontRendererObj; - int width = Utils.peekGuiScale().getScaledWidth(); - int height = Utils.peekGuiScale().getScaledHeight(); - int mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth; - int mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1; - List<String> tooltip = null; - for (int i = 0; i < 9; i++) { - if (items[i] != null) { - int slotIndex = (int) (10 + 9 * Math.floor(i / 3f) + (i % 3)); - Slot slot = container.inventorySlots.get(slotIndex); - int x = slot.xDisplayPosition + gc.guiLeft; - int y = slot.yDisplayPosition + gc.guiTop; - if (!slot.getHasStack() || !manager.getInternalNameForItem(items[i]).equals(manager.getInternalNameForItem(slot.getStack())) || - slot.getStack().stackSize < items[i].stackSize) - Gui.drawRect(x, y, x + 16, y + 16, 0x64ff0000); - if (!slot.getHasStack()) - Utils.drawItemStack(items[i], x, y); - if (!slot.getHasStack() && mouseX >= x && mouseX < x + 16 && mouseY >= y && mouseY < y + 16) - tooltip = items[i].getTooltip(Minecraft.getMinecraft().thePlayer, false); - } - } - if (text != null) - ft.drawStringWithShadow(text, - Utils.peekGuiScale().getScaledWidth() / 2f - ft.getStringWidth(text) / 2f, - gc.guiTop - 15f, 0x808080); - if (tooltip != null) - Utils.drawHoveringText(tooltip, mouseX, mouseY, width, height, -1, ft); - } - } - - public static void keyInput() { - if (!Keyboard.getEventKeyState() || Keyboard.getEventKey() != Keyboard.KEY_U && Keyboard.getEventKey() != Keyboard.KEY_R) - return; - int width = Utils.peekGuiScale().getScaledWidth(); - int height = Utils.peekGuiScale().getScaledHeight(); - int mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth; - int mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1; - ContainerChest container = (ContainerChest) Minecraft.getMinecraft().thePlayer.openContainer; - GuiChest gc = (GuiChest) Minecraft.getMinecraft().currentScreen; - for (int i = 0; i < 9; i++) { - if (items[i] != null) { - int slotIndex = (int) (10 + 9 * Math.floor(i / 3f) + (i % 3)); - Slot slot = container.inventorySlots.get(slotIndex); - int x = slot.xDisplayPosition + gc.guiLeft; - int y = slot.yDisplayPosition + gc.guiTop; - if (mouseX >= x && mouseX < x + 16 && mouseY >= y && mouseY < y + 16) { - if (!slot.getHasStack()) { - String internalName = manager.getInternalNameForItem(items[i]); - if (Keyboard.getEventKey() == Keyboard.KEY_U && internalName != null) { - manager.displayGuiItemUsages(internalName); - } else if (Keyboard.getEventKey() == Keyboard.KEY_R && internalName != null && manager.getItemInformation().containsKey(internalName)) { - JsonObject item = manager.getItemInformation().get(internalName); - manager.showRecipe(item); - } - } - break; - } - } - } - } - - public static void updateItem(CraftingRecipe recipe) { - for (int i = 0; i < 9; i++) { - Ingredient ingredient = recipe.getInputs()[i]; - if (ingredient == null) { - items[i] = null; - } else { - items[i] = ingredient.getItemStack(); - } - } - text = recipe.getCraftText(); - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/recipes/CraftingOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/recipes/CraftingOverlay.java new file mode 100644 index 00000000..21823792 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/recipes/CraftingOverlay.java @@ -0,0 +1,140 @@ +package io.github.moulberry.notenoughupdates.recipes; + +import io.github.moulberry.notenoughupdates.NEUManager; +import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.inventory.GuiChest; +import net.minecraft.inventory.ContainerChest; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import net.minecraftforge.client.event.GuiOpenEvent; +import net.minecraftforge.client.event.GuiScreenEvent; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import org.lwjgl.input.Keyboard; + +import java.util.function.BiConsumer; + +public class CraftingOverlay { + + private final NEUManager manager; + private CraftingRecipe currentRecipe = null; + + public CraftingOverlay(NEUManager manager) { + this.manager = manager; + MinecraftForge.EVENT_BUS.register(this); + } + + public void setShownRecipe(CraftingRecipe recipe) { + currentRecipe = recipe; + } + + private void forEachSlot(ContainerChest chest, BiConsumer<Ingredient, Slot> block) { + for (int i = 0; i < 9; i++) { + Ingredient recipeIngredient = currentRecipe.getInputs()[i]; + Slot slot = chest.inventorySlots.get(10 + 9 * (i / 3) + (i % 3)); + block.accept(recipeIngredient, slot); + } + } + + private void forEachHoveredSlot(GuiChest gui, ContainerChest chest, int mouseX, int mouseY, BiConsumer<Ingredient, Slot> block) { + forEachSlot(chest, (recipeIngredient, slot) -> { + if (Utils.isWithinRect( + mouseX, mouseY, + slot.xDisplayPosition + gui.guiLeft, + slot.yDisplayPosition + gui.guiTop, + 16, 16)) + block.accept(recipeIngredient, slot); + }); + } + + private void runIfCraftingOverlayIsPresent(Gui gui, BiConsumer<GuiChest, ContainerChest> block) { + if (currentRecipe == null) return; + if (!(gui instanceof GuiChest)) return; + GuiChest guiChest = (GuiChest) gui; + ContainerChest chest = (ContainerChest) guiChest.inventorySlots; + IInventory chestInventory = chest.getLowerChestInventory(); + if (!"Craft Item".equals(chestInventory.getDisplayName().getUnformattedText())) return; + block.accept(guiChest, chest); + } + + @SubscribeEvent + public void onGuiOpen(GuiOpenEvent event) { + currentRecipe = null; + } + + @SubscribeEvent + public void onRender(GuiScreenEvent.DrawScreenEvent.Post event) { + runIfCraftingOverlayIsPresent(event.gui, (guiChest, chest) -> { + renderSlots(guiChest, chest); + if (currentRecipe.getCraftText() != null) { + FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj; + fontRenderer.drawStringWithShadow( + currentRecipe.getCraftText(), + Utils.peekGuiScale().getScaledWidth() / 2f - fontRenderer.getStringWidth(currentRecipe.getCraftText()) / 2f, + guiChest.guiTop - 15f, 0x808080); + } + renderTooltip(guiChest, chest); + }); + } + + @SubscribeEvent + public void onKeyDown(GuiScreenEvent.KeyboardInputEvent.Pre event) { + if (!Keyboard.getEventKeyState() || (Keyboard.getEventKey() != Keyboard.KEY_U && Keyboard.getEventKey() != Keyboard.KEY_R)) + return; + runIfCraftingOverlayIsPresent(event.gui, (guiChest, chest) -> { + int mouseX = Utils.getMouseX(); + int mouseY = Utils.getMouseY(); + + forEachHoveredSlot(guiChest, chest, mouseX, mouseY, (recipeIngredient, slot) -> { + if (slot.getStack() == null && recipeIngredient != null) { + if (Keyboard.getEventKey() == Keyboard.KEY_R) + manager.showRecipe(recipeIngredient.getInternalItemId()); + if (Keyboard.getEventKey() == Keyboard.KEY_U) + manager.displayGuiItemRecipe(recipeIngredient.getInternalItemId(), null); + } + }); + }); + } + + private void renderTooltip(GuiChest guiChest, ContainerChest chest) { + int mouseX = Utils.getMouseX(); + int mouseY = Utils.getMouseY(); + forEachHoveredSlot(guiChest, chest, mouseX, mouseY, (recipeIngredient, slot) -> { + ItemStack actualItem = slot.getStack(); + if (actualItem == null && recipeIngredient != null) { + Utils.drawHoveringText( + recipeIngredient.getItemStack().getTooltip(Minecraft.getMinecraft().thePlayer, false), + mouseX, mouseY, + Utils.peekGuiScale().getScaledWidth(), Utils.peekGuiScale().getScaledHeight(), -1, + Minecraft.getMinecraft().fontRendererObj); + } + }); + } + + private void renderSlots(GuiChest guiChest, ContainerChest chest) { + forEachSlot(chest, (recipeIngredient, slot) -> { + ItemStack actualItem = slot.getStack(); + if (actualItem != null && (recipeIngredient == null || + !recipeIngredient.getInternalItemId().equals(manager.getInternalNameForItem(actualItem)) || + actualItem.stackSize < recipeIngredient.getCount())) { + drawItemStack(guiChest, slot, actualItem); + } + if (recipeIngredient != null && actualItem == null) { + drawItemStack(guiChest, slot, recipeIngredient.getItemStack()); + } + }); + } + + private void drawItemStack(GuiChest gui, Slot slot, ItemStack item) { + int slotX = slot.xDisplayPosition + gui.guiLeft; + int slotY = slot.yDisplayPosition + gui.guiTop; + Gui.drawRect(slotX, slotY, slotX + 16, slotY + 16, 0x64ff0000); + if (item != null) + Utils.drawItemStack(item, slotX, slotY); + } + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/recipes/Ingredient.java b/src/main/java/io/github/moulberry/notenoughupdates/recipes/Ingredient.java index d72c901f..2855c48e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/recipes/Ingredient.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/recipes/Ingredient.java @@ -6,7 +6,6 @@ import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; -import java.text.NumberFormat; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -71,7 +70,7 @@ public class Ingredient { public ItemStack getItemStack() { if (itemStack != null) return itemStack; - if(isCoins()) { + if (isCoins()) { itemStack = new ItemStack(Items.gold_nugget); itemStack.setStackDisplayName("\u00A7r\u00A76" + Utils.formatNumberWithDots(getCount()) + " Coins"); return itemStack; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java index 4a3e6400..3711f1e5 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java @@ -33,10 +33,11 @@ import net.minecraft.network.play.client.C0DPacketCloseWindow; import net.minecraft.util.*; import net.minecraftforge.fml.common.Loader; import org.lwjgl.BufferUtils; +import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL14; -import java.awt.*; +import java.awt.Color; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; @@ -46,7 +47,6 @@ import java.lang.reflect.Method; import java.nio.FloatBuffer; import java.nio.charset.StandardCharsets; import java.nio.file.Files; -import java.util.List; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -456,21 +456,21 @@ public class Utils { return str.substring(0, 1).toUpperCase() + str.substring(1).toLowerCase(); } - public static String[] rarityArr = new String[] { + public static String[] rarityArr = new String[]{ "COMMON", "UNCOMMON", "RARE", "EPIC", "LEGENDARY", "MYTHIC", "SPECIAL", "VERY SPECIAL", "SUPREME", "^^ THAT ONE IS DIVINE ^^"//, "DIVINE" }; - public static String[] rarityArrC = new String[] { - EnumChatFormatting.WHITE+EnumChatFormatting.BOLD.toString()+"COMMON", - EnumChatFormatting.GREEN+EnumChatFormatting.BOLD.toString()+"UNCOMMON", - EnumChatFormatting.BLUE+EnumChatFormatting.BOLD.toString()+"RARE", - EnumChatFormatting.DARK_PURPLE+EnumChatFormatting.BOLD.toString()+"EPIC", - EnumChatFormatting.GOLD+EnumChatFormatting.BOLD.toString()+"LEGENDARY", - EnumChatFormatting.LIGHT_PURPLE+EnumChatFormatting.BOLD.toString()+"MYTHIC", - EnumChatFormatting.RED+EnumChatFormatting.BOLD.toString()+"SPECIAL", - EnumChatFormatting.RED+EnumChatFormatting.BOLD.toString()+"VERY SPECIAL", - EnumChatFormatting.AQUA+EnumChatFormatting.BOLD.toString()+"DIVINE", - EnumChatFormatting.AQUA+EnumChatFormatting.BOLD.toString()+"DIVINE", + public static String[] rarityArrC = new String[]{ + EnumChatFormatting.WHITE + EnumChatFormatting.BOLD.toString() + "COMMON", + EnumChatFormatting.GREEN + EnumChatFormatting.BOLD.toString() + "UNCOMMON", + EnumChatFormatting.BLUE + EnumChatFormatting.BOLD.toString() + "RARE", + EnumChatFormatting.DARK_PURPLE + EnumChatFormatting.BOLD.toString() + "EPIC", + EnumChatFormatting.GOLD + EnumChatFormatting.BOLD.toString() + "LEGENDARY", + EnumChatFormatting.LIGHT_PURPLE + EnumChatFormatting.BOLD.toString() + "MYTHIC", + EnumChatFormatting.RED + EnumChatFormatting.BOLD.toString() + "SPECIAL", + EnumChatFormatting.RED + EnumChatFormatting.BOLD.toString() + "VERY SPECIAL", + EnumChatFormatting.AQUA + EnumChatFormatting.BOLD.toString() + "DIVINE", + EnumChatFormatting.AQUA + EnumChatFormatting.BOLD.toString() + "DIVINE", //EnumChatFormatting.AQUA+EnumChatFormatting.BOLD.toString()+"DIVINE", }; @@ -1363,6 +1363,7 @@ public class Utils { return endsIn; } + public static void drawLine(float sx, float sy, float ex, float ey, int width, int color) { float f = (float) (color >> 24 & 255) / 255.0F; float f1 = (float) (color >> 16 & 255) / 255.0F; @@ -1385,7 +1386,7 @@ public class Utils { GlStateManager.popMatrix(); } - public static void drawDottedLine(float sx, float sy, float ex, float ey, int width, int factor , int color) { + public static void drawDottedLine(float sx, float sy, float ex, float ey, int width, int factor, int color) { GlStateManager.pushMatrix(); GL11.glLineStipple(factor, (short) 0xAAAA); GL11.glEnable(GL11.GL_LINE_STIPPLE); @@ -1456,4 +1457,17 @@ public class Utils { return work; } + public static int getMouseY() { + int height = peekGuiScale().getScaledHeight(); + return height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1; + } + + public static int getMouseX() { + return Mouse.getX() * peekGuiScale().getScaledWidth() / Minecraft.getMinecraft().displayWidth; + } + + public static boolean isWithinRect(int x, int y, int left, int top, int width, int height) { + return left <= x && x <= left + width && + top <= y && y <= top + height; + } } |