diff options
| author | BuildTools <james.jenour@protonmail.com> | 2021-03-27 07:40:53 +0800 |
|---|---|---|
| committer | BuildTools <james.jenour@protonmail.com> | 2021-03-27 07:40:53 +0800 |
| commit | 03b9a8dbcc1ebd5f8c39e4733a741a4092ab0a1d (patch) | |
| tree | b8ddc6757fc06f4a325121e7d972c0ddf152b401 /src/main/java/io | |
| parent | 06c3c7fcfd8f65e2a30f81626457f4180ea52a36 (diff) | |
| download | NotEnoughUpdates-03b9a8dbcc1ebd5f8c39e4733a741a4092ab0a1d.tar.gz NotEnoughUpdates-03b9a8dbcc1ebd5f8c39e4733a741a4092ab0a1d.tar.bz2 NotEnoughUpdates-03b9a8dbcc1ebd5f8c39e4733a741a4092ab0a1d.zip | |
PRE26
Diffstat (limited to 'src/main/java/io')
31 files changed, 2557 insertions, 632 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/ItemPriceInformation.java b/src/main/java/io/github/moulberry/notenoughupdates/ItemPriceInformation.java index 58efa371..ff618f10 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/ItemPriceInformation.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/ItemPriceInformation.java @@ -3,6 +3,7 @@ package io.github.moulberry.notenoughupdates; import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.auction.APIManager; import io.github.moulberry.notenoughupdates.util.Constants; +import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumChatFormatting; @@ -15,6 +16,10 @@ import java.util.Locale; public class ItemPriceInformation { public static boolean addToTooltip(List<String> tooltip, String internalname, ItemStack stack) { + return addToTooltip(tooltip, internalname, stack, true); + } + + public static boolean addToTooltip(List<String> tooltip, String internalname, ItemStack stack, boolean useStackSize) { JsonObject auctionInfo = NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAuctionInfo(internalname); JsonObject bazaarInfo = NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo(internalname); float lowestBinAvg = NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAvgBin(internalname); @@ -35,7 +40,7 @@ public class ItemPriceInformation { boolean shiftPressed = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT); int stackMultiplier = 1; - int shiftStackMultiplier = 64; + int shiftStackMultiplier = useStackSize && stack.stackSize > 1 ? stack.stackSize : 64; if(shiftPressed) { stackMultiplier = shiftStackMultiplier; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java index 838f0b0a..8219c903 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java @@ -1,5 +1,6 @@ package io.github.moulberry.notenoughupdates; +import com.google.common.collect.Lists; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -16,6 +17,8 @@ import io.github.moulberry.notenoughupdates.dungeons.DungeonWin; import io.github.moulberry.notenoughupdates.gamemodes.SBGamemodes; import io.github.moulberry.notenoughupdates.miscfeatures.*; import io.github.moulberry.notenoughupdates.miscgui.*; +import io.github.moulberry.notenoughupdates.mixins.GuiContainerAccessor; +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.util.*; @@ -27,6 +30,7 @@ import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.gui.inventory.GuiChest; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.gui.inventory.GuiEditSign; +import net.minecraft.client.gui.inventory.GuiInventory; import net.minecraft.client.network.NetworkPlayerInfo; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.entity.player.EntityPlayer; @@ -41,6 +45,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTUtil; import net.minecraft.util.*; +import net.minecraftforge.client.ClientCommandHandler; import net.minecraftforge.client.event.*; import net.minecraftforge.event.entity.player.EntityInteractEvent; import net.minecraftforge.event.entity.player.ItemTooltipEvent; @@ -204,7 +209,6 @@ public class NEUEventListener { CrystalOverlay.tick(); DwarvenMinesTextures.tick(); FairySouls.tick(); - MiningStuff.tick(); XPInformation.getInstance().tick(); ProfileApiSyncer.getInstance().tick(); DamageCommas.tick(); @@ -734,6 +738,8 @@ public class NEUEventListener { } } + public static boolean drawingGuiScreen = false; + /** * Sets hoverInv and focusInv variables, representing whether the NEUOverlay should render behind the inventory when * (hoverInv == true) and whether mouse/kbd inputs shouldn't be sent to NEUOverlay (focusInv == true). @@ -756,10 +762,10 @@ public class NEUEventListener { if(event.gui instanceof GuiContainer) { try { - int xSize = (int) Utils.getField(GuiContainer.class, event.gui, "xSize", "field_146999_f"); - int ySize = (int) Utils.getField(GuiContainer.class, event.gui, "ySize", "field_147000_g"); - int guiLeft = (int) Utils.getField(GuiContainer.class, event.gui, "guiLeft", "field_147003_i"); - int guiTop = (int) Utils.getField(GuiContainer.class, event.gui, "guiTop", "field_147009_r"); + int xSize = ((GuiContainerAccessor)event.gui).getXSize(); + int ySize = ((GuiContainerAccessor)event.gui).getYSize(); + int guiLeft = ((GuiContainerAccessor)event.gui).getGuiLeft(); + int guiTop = ((GuiContainerAccessor)event.gui).getGuiTop(); hoverInv = event.getMouseX() > guiLeft && event.getMouseX() < guiLeft + xSize && event.getMouseY() > guiTop && event.getMouseY() < guiTop + ySize; @@ -797,10 +803,16 @@ public class NEUEventListener { } } } + + drawingGuiScreen = true; } + private boolean doInventoryButtons = false; + @SubscribeEvent public void onGuiScreenDrawPre(GuiScreenEvent.DrawScreenEvent.Pre event) { + doInventoryButtons = false; + if(AuctionSearchOverlay.shouldReplace()) { AuctionSearchOverlay.render(); event.setCanceled(true); @@ -839,6 +851,49 @@ public class NEUEventListener { } } } + + if(CalendarOverlay.isEnabled() || event.isCanceled()) return; + if(NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard() && shouldRenderOverlay(event.gui) + && event.gui instanceof GuiContainer) { + doInventoryButtons = true; + + int zOffset = 50; + + GlStateManager.translate(0, 0, zOffset); + + int xSize = ((GuiContainerAccessor)event.gui).getXSize(); + int ySize = ((GuiContainerAccessor)event.gui).getYSize(); + int guiLeft = ((GuiContainerAccessor)event.gui).getGuiLeft(); + int guiTop = ((GuiContainerAccessor)event.gui).getGuiTop(); + + 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; + } + + 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.translate(0, 0, -zOffset); + } } private static boolean shouldRenderOverlay(Gui gui) { @@ -854,6 +909,11 @@ public class NEUEventListener { return validGui; } + private static final ResourceLocation EDITOR = new ResourceLocation("notenoughupdates:invbuttons/editor.png"); + private NEUConfig.InventoryButton buttonHovered = null; + private long buttonHoveredMillis = 0; + public static boolean disableCraftingText = false; + /** * Will draw the NEUOverlay over the inventory if focusInv == false. (z-translation of 300 is so that NEUOverlay * will draw over Items in the inventory (which render at a z value of about 250)) @@ -861,6 +921,9 @@ public class NEUEventListener { */ @SubscribeEvent public void onGuiScreenDrawPost(GuiScreenEvent.DrawScreenEvent.Post event) { + drawingGuiScreen = false; + disableCraftingText = false; + if(!(TradeWindow.tradeWindowActive() || event.gui instanceof CustomAHGui || neu.manager.auctionManager.customAH.isRenderOverAuctionView())) { if(shouldRenderOverlay(event.gui) && neu.isOnSkyblock()) { @@ -870,7 +933,6 @@ public class NEUEventListener { neu.overlay.render(hoverInv && focusInv); GL11.glTranslatef(0, 0, -300); } - neu.overlay.renderOverlay(); GlStateManager.popMatrix(); } } @@ -881,6 +943,56 @@ public class NEUEventListener { AccessoryBagOverlay.renderOverlay(); } } + + boolean hoveringButton = false; + if(!doInventoryButtons) return; + if(NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard() && shouldRenderOverlay(event.gui) && + event.gui instanceof GuiContainer) { + int xSize = ((GuiContainerAccessor)event.gui).getXSize(); + int ySize = ((GuiContainerAccessor)event.gui).getYSize(); + int guiLeft = ((GuiContainerAccessor)event.gui).getGuiLeft(); + int guiTop = ((GuiContainerAccessor)event.gui).getGuiTop(); + + 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(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(buttonHovered != button) { + buttonHoveredMillis = currentTime; + buttonHovered = button; + } + + 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); + } + } + } + } + if(!hoveringButton) buttonHovered = null; } private void renderDungeonChestOverlay(GuiScreen gui) { @@ -888,10 +1000,10 @@ public class NEUEventListener { if(gui instanceof GuiChest && neu.config.dungeons.profitDisplayLoc != 2) { try { - int xSize = (int) Utils.getField(GuiContainer.class, gui, "xSize", "field_146999_f"); - int ySize = (int) Utils.getField(GuiContainer.class, gui, "ySize", "field_147000_g"); - int guiLeft = (int) Utils.getField(GuiContainer.class, gui, "guiLeft", "field_147003_i"); - int guiTop = (int) Utils.getField(GuiContainer.class, gui, "guiTop", "field_147009_r"); + int xSize = ((GuiContainerAccessor)gui).getXSize(); + int ySize = ((GuiContainerAccessor)gui).getYSize(); + int guiLeft = ((GuiContainerAccessor)gui).getGuiLeft(); + int guiTop = ((GuiContainerAccessor)gui).getGuiTop(); GuiChest eventGui = (GuiChest) gui; ContainerChest cc = (ContainerChest) eventGui.inventorySlots; @@ -1083,7 +1195,7 @@ public class NEUEventListener { * Will also cancel the event if if NEUOverlay#mouseInput returns true. * @param event */ - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.LOW) public void onGuiScreenMouse(GuiScreenEvent.MouseInputEvent.Pre event) { if(!event.isCanceled()) { Utils.scrollTooltip(Mouse.getEventDWheel()); @@ -1121,6 +1233,53 @@ public class NEUEventListener { } } } + if(event.isCanceled()) return; + if(!doInventoryButtons) return; + if(NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard() && shouldRenderOverlay(event.gui) && Mouse.getEventButton() >= 0 + && event.gui instanceof GuiContainer) { + int xSize = ((GuiContainerAccessor)event.gui).getXSize(); + int ySize = ((GuiContainerAccessor)event.gui).getYSize(); + int guiLeft = ((GuiContainerAccessor)event.gui).getGuiLeft(); + int guiTop = ((GuiContainerAccessor)event.gui).getGuiTop(); + + final ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); + final int scaledWidth = scaledresolution.getScaledWidth(); + final int scaledHeight = scaledresolution.getScaledHeight(); + int mouseX = Mouse.getX() * scaledWidth / Minecraft.getMinecraft().displayWidth; + int mouseY = scaledHeight - Mouse.getY() * scaledHeight / Minecraft.getMinecraft().displayHeight - 1; + + 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(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; + } + } + } } ScheduledExecutorService ses = Executors.newScheduledThreadPool(1); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java index 061d6774..4f392ae8 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java @@ -17,6 +17,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.*; import net.minecraft.network.play.client.C0DPacketCloseWindow; import net.minecraft.util.ResourceLocation; +import org.apache.commons.io.FileUtils; import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.Display; @@ -26,6 +27,8 @@ import java.net.URL; import java.net.URLConnection; import java.nio.charset.StandardCharsets; import java.util.*; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -57,10 +60,10 @@ public class NEUManager { private String currentProfileBackup = ""; public final HypixelApi hypixelApi = new HypixelApi(); - private ResourceLocation wkZip = new ResourceLocation("notenoughupdates:wkhtmltox.zip"); private Map<String, ItemStack> itemstackCache = new HashMap<>(); - //private static final String AUCTIONS_PRICE_URL = "https://moulberry.github.io/files/auc_avg_jsons/average_3day.json.gz"; + private ExecutorService repoLoaderES = Executors.newSingleThreadExecutor(); + private static final String GIT_COMMITS_URL = "https://api.github.com/repos/Moulberry/NotEnoughUpdates-REPO/commits/master"; private HashMap<String, Set<String>> usagesMap = new HashMap<>(); @@ -88,15 +91,6 @@ public class NEUManager { if(itemRenameJson == null) { itemRenameJson = new JsonObject(); } - - File wkShell = new File(configLocation, "wkhtmltox/bin/wkhtmltoimage"); - if(!wkShell.exists()) { - try { - InputStream is = Minecraft.getMinecraft().getResourceManager().getResource(wkZip).getInputStream(); - unzip(is, configLocation); - } catch (IOException e) { - } - } } public void setCurrentProfile(String currentProfile) { @@ -163,7 +157,7 @@ public class NEUManager { }*/ - Thread thread = new Thread(() -> { + repoLoaderES.submit(() -> { JDialog dialog = null; try { if(NotEnoughUpdates.INSTANCE.config.hidden.autoupdate) { @@ -211,12 +205,23 @@ public class NEUManager { } catch (IOException e) { return; } + + URL url = new URL(dlUrl); URLConnection urlConnection = url.openConnection(); urlConnection.setConnectTimeout(15000); - urlConnection.setReadTimeout(20000); - try (BufferedInputStream inStream = new BufferedInputStream(urlConnection.getInputStream()); - FileOutputStream fileOutputStream = new FileOutputStream(itemsZip)) { + urlConnection.setReadTimeout(30000); + + try(InputStream is = urlConnection.getInputStream()) { + FileUtils.copyInputStreamToFile(is, itemsZip); + } catch (IOException e) { + dialog.dispose(); + e.printStackTrace(); + System.err.println("Failed to download NEU Repo! Please report this issue to the mod creator"); + return; + } + /*try (BufferedInputStream inStream = new BufferedInputStream(urlConnection.getInputStream()); + FileOutputStream fileOutputStream = new FileOutputStream(itemsZip)) { byte dataBuffer[] = new byte[1024]; int bytesRead; while ((bytesRead = inStream.read(dataBuffer, 0, 1024)) != -1) { @@ -225,7 +230,7 @@ public class NEUManager { } catch (IOException e) { dialog.dispose(); return; - } + }*/ pane.setMessage("Unzipping NEU Master Archive."); dialog.pack(); @@ -242,6 +247,8 @@ public class NEUManager { } catch (IOException e) { } } + + Constants.reload(); } } catch(Exception e) { e.printStackTrace(); @@ -249,31 +256,40 @@ public class NEUManager { if(dialog != null) dialog.dispose(); } + System.err.println("First load"); + File items = new File(repoLocation, "items"); if(items.exists()) { File[] itemFiles = new File(repoLocation, "items").listFiles(); if(itemFiles != null) { for(File f : itemFiles) { String internalname = f.getName().substring(0, f.getName().length()-5); - if(!getItemInformation().keySet().contains(internalname)) { - loadItem(internalname); + synchronized(itemMap) { + if(!itemMap.keySet().contains(internalname)) { + loadItem(internalname); + } } } } } }); + System.err.println("Second load"); + File items = new File(repoLocation, "items"); if(items.exists()) { File[] itemFiles = new File(repoLocation, "items").listFiles(); if(itemFiles != null) { for(File f : itemFiles) { String internalname = f.getName().substring(0, f.getName().length()-5); - loadItem(internalname); + synchronized(itemMap) { + if(!itemMap.keySet().contains(internalname)) { + loadItem(internalname); + } + } } } } - thread.start(); } /** @@ -301,56 +317,69 @@ public class NEUManager { itemMap.put(internalName, json); if(json.has("recipe")) { - JsonObject recipe = json.get("recipe").getAsJsonObject(); - - String[] x = {"1","2","3"}; - String[] y = {"A","B","C"}; - for(int i=0; i<9; i++) { - String name = y[i/3]+x[i%3]; - String itemS = recipe.get(name).getAsString(); - if(itemS != null && itemS.split(":").length == 2) { - itemS = itemS.split(":")[0]; - } + synchronized(usagesMap) { + JsonObject recipe = json.get("recipe").getAsJsonObject(); + + String[] x = {"1","2","3"}; + String[] y = {"A","B","C"}; + for(int i=0; i<9; i++) { + String name = y[i/3]+x[i%3]; + String itemS = recipe.get(name).getAsString(); + if(itemS != null && itemS.split(":").length == 2) { + itemS = itemS.split(":")[0]; + } - if(!usagesMap.containsKey(itemS)) { - |
