diff options
author | Lulonaut <67191924+Lulonaut@users.noreply.github.com> | 2022-04-13 07:53:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-13 05:53:52 +0000 |
commit | 6ca951d739913486e9a345be47ab467bad8e97c3 (patch) | |
tree | 64cc968deddbef07bfbe396cb2174ac544655f1a /src/main/java/io | |
parent | 0f7fb90f9a757117584daf37b6eba8b37add1518 (diff) | |
download | NotEnoughUpdates-6ca951d739913486e9a345be47ab467bad8e97c3.tar.gz NotEnoughUpdates-6ca951d739913486e9a345be47ab467bad8e97c3.tar.bz2 NotEnoughUpdates-6ca951d739913486e9a345be47ab467bad8e97c3.zip |
Crimson Essence support (#110)
* jani1
* update bingo more often
* crimson support
* move method to Utils
* remove debug prints
* fix single items
* gray items
* improvements
better variable names
fix behavior from 10 to 15 stars
use EnumChatFormatting instead of the color code directly
* fix dungeonize cost
* remove master stars check
Diffstat (limited to 'src/main/java/io')
5 files changed, 267 insertions, 38 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/ItemPriceInformation.java b/src/main/java/io/github/moulberry/notenoughupdates/ItemPriceInformation.java index 7dac5eb2..38b59ef3 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/ItemPriceInformation.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/ItemPriceInformation.java @@ -1,17 +1,24 @@ package io.github.moulberry.notenoughupdates; import com.google.gson.Gson; +import com.google.gson.JsonElement; import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.auction.APIManager; import io.github.moulberry.notenoughupdates.core.config.KeybindHelper; 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; import org.lwjgl.input.Keyboard; -import java.io.*; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; import java.nio.charset.StandardCharsets; import java.text.NumberFormat; import java.util.HashSet; @@ -79,8 +86,9 @@ public class ItemPriceInformation { int lowestBin = NotEnoughUpdates.INSTANCE.manager.auctionManager.getLowestBin(internalname); APIManager.CraftInfo craftCost = NotEnoughUpdates.INSTANCE.manager.auctionManager.getCraftCost(internalname); + boolean bazaarItem = bazaarInfo != null; - boolean auctionItem = lowestBin > 0 || lowestBinAvg > 0; + boolean auctionItem = !bazaarItem; boolean auctionInfoErrored = auctionInfo == null; if (auctionItem) { long currentTime = System.currentTimeMillis(); @@ -92,7 +100,6 @@ public class ItemPriceInformation { } } - boolean bazaarItem = bazaarInfo != null; NumberFormat format = NumberFormat.getInstance(Locale.US); boolean shortNumber = NotEnoughUpdates.INSTANCE.config.tooltipTweaks.shortNumberFormatPrices; @@ -302,34 +309,49 @@ public class ItemPriceInformation { } JsonObject itemCosts = essenceCosts.get(internalname).getAsJsonObject(); String essenceType = itemCosts.get("type").getAsString(); + boolean requiresItems = false; + JsonObject itemsObject = null; + if (itemCosts.has("items")) { + requiresItems = true; + itemsObject = itemCosts.get("items").getAsJsonObject(); + } - int dungeonItemLevel = -1; - if (stack != null && stack.hasTagCompound() && - stack.getTagCompound().hasKey("ExtraAttributes", 10)) { - NBTTagCompound ea = stack.getTagCompound().getCompoundTag("ExtraAttributes"); + int dungeonItemLevel = Utils.getNumberOfStars(stack); - if (ea.hasKey("dungeon_item_level", 99)) { - dungeonItemLevel = ea.getInteger("dungeon_item_level"); - } - } if (dungeonItemLevel == -1) { int dungeonizeCost = 0; if (itemCosts.has("dungeonize")) { dungeonizeCost = itemCosts.get("dungeonize").getAsInt(); } - tooltip.add(EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.BOLD + "Dungeonize Cost: " + - EnumChatFormatting.GOLD + EnumChatFormatting.BOLD + dungeonizeCost + " " + essenceType); - } else if (dungeonItemLevel >= 0 && dungeonItemLevel <= 4) { - String costType = (dungeonItemLevel + 1) + ""; - int upgradeCost = itemCosts.get(costType).getAsInt(); - StringBuilder star = new StringBuilder(); - for (int i = 0; i <= dungeonItemLevel; i++) { - star.append('\u272A'); + if (dungeonizeCost > 0) { + tooltip.add(EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.BOLD + "Dungeonize Cost: " + + EnumChatFormatting.GOLD + EnumChatFormatting.BOLD + dungeonizeCost + " " + essenceType); + } + } else if (dungeonItemLevel >= 0) { + String nextStarLevelString = (dungeonItemLevel + 1) + ""; + int nextStarLevelInt = Integer.parseInt(nextStarLevelString); + + if (itemCosts.has(nextStarLevelString)) { + int upgradeCost = itemCosts.get(nextStarLevelString).getAsInt(); + String starString = Utils.getStarsString(nextStarLevelInt); + tooltip.add(EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.BOLD + "Upgrade to " + + starString + EnumChatFormatting.YELLOW + EnumChatFormatting.BOLD + ": " + + EnumChatFormatting.GOLD + EnumChatFormatting.BOLD + upgradeCost + " " + essenceType); + if (requiresItems && itemsObject.has(nextStarLevelString)) { + boolean shouldShow = Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || + NotEnoughUpdates.INSTANCE.config.tooltipTweaks.alwaysShowRequiredItems; + + if (shouldShow) { + tooltip.add(EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.BOLD + "Required Items:"); + for (JsonElement item : itemsObject.get(nextStarLevelString).getAsJsonArray()) { + tooltip.add(" - " + item.getAsString()); + } + } else { + tooltip.add(EnumChatFormatting.DARK_GRAY + "[CTRL to show required items]"); + } + } } - tooltip.add(EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.BOLD + "Upgrade to " + - EnumChatFormatting.GOLD + star + EnumChatFormatting.YELLOW + EnumChatFormatting.BOLD + ": " + - EnumChatFormatting.GOLD + EnumChatFormatting.BOLD + upgradeCost + " " + essenceType); } break; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java index 9c12e732..54154955 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java @@ -1,7 +1,12 @@ package io.github.moulberry.notenoughupdates.listener; import com.google.common.collect.Lists; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.google.gson.JsonPrimitive; import io.github.moulberry.notenoughupdates.NEUApi; import io.github.moulberry.notenoughupdates.NEUOverlay; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; @@ -13,7 +18,13 @@ import io.github.moulberry.notenoughupdates.miscfeatures.AuctionBINWarning; import io.github.moulberry.notenoughupdates.miscfeatures.BetterContainers; import io.github.moulberry.notenoughupdates.miscfeatures.CrystalMetalDetectorSolver; import io.github.moulberry.notenoughupdates.miscfeatures.StorageManager; -import io.github.moulberry.notenoughupdates.miscgui.*; +import io.github.moulberry.notenoughupdates.miscgui.AccessoryBagOverlay; +import io.github.moulberry.notenoughupdates.miscgui.CalendarOverlay; +import io.github.moulberry.notenoughupdates.miscgui.GuiCustomEnchant; +import io.github.moulberry.notenoughupdates.miscgui.GuiInvButtonEditor; +import io.github.moulberry.notenoughupdates.miscgui.GuiItemRecipe; +import io.github.moulberry.notenoughupdates.miscgui.StorageOverlay; +import io.github.moulberry.notenoughupdates.miscgui.TradeWindow; import io.github.moulberry.notenoughupdates.options.NEUConfig; import io.github.moulberry.notenoughupdates.overlays.AuctionSearchOverlay; import io.github.moulberry.notenoughupdates.overlays.OverlayManager; @@ -32,9 +43,12 @@ import net.minecraft.client.gui.inventory.GuiEditSign; import net.minecraft.client.gui.inventory.GuiInventory; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; import net.minecraft.inventory.ContainerChest; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; @@ -42,7 +56,11 @@ import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.ClientCommandHandler; -import net.minecraftforge.client.event.*; +import net.minecraftforge.client.event.GuiOpenEvent; +import net.minecraftforge.client.event.GuiScreenEvent; +import net.minecraftforge.client.event.RenderGameOverlayEvent; +import net.minecraftforge.client.event.RenderLivingEvent; +import net.minecraftforge.client.event.RenderWorldLastEvent; import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; @@ -52,7 +70,15 @@ import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; import javax.swing.*; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.nio.charset.StandardCharsets; import java.text.NumberFormat; import java.util.ConcurrentModificationException; import java.util.HashMap; @@ -61,6 +87,7 @@ import java.util.Map; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; import static io.github.moulberry.notenoughupdates.util.GuiTextures.dungeon_chest_worth; @@ -984,6 +1011,109 @@ public class RenderListener { */ @SubscribeEvent public void onGuiScreenKeyboard(GuiScreenEvent.KeyboardInputEvent.Pre event) { + if (Keyboard.isKeyDown(Keyboard.KEY_B) && NotEnoughUpdates.INSTANCE.config.hidden.dev) { + if (Minecraft.getMinecraft().currentScreen instanceof GuiChest) { + GuiChest eventGui = (GuiChest) Minecraft.getMinecraft().currentScreen; + ContainerChest cc = (ContainerChest) eventGui.inventorySlots; + IInventory lower = cc.getLowerChestInventory(); + + try { + File file = new File( + Minecraft.getMinecraft().mcDataDir.getAbsolutePath(), + "config/notenoughupdates/repo/constants/essencecosts.json" + ); + String fileContent; + fileContent = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8)) + .lines() + .collect(Collectors.joining(System.lineSeparator())); + String id = null; + JsonObject jsonObject = new JsonParser().parse(fileContent).getAsJsonObject(); + JsonObject newEntry = new JsonObject(); + for (int i = 0; i < 54; i++) { + ItemStack stack = lower.getStackInSlot(i); + if (!stack.getDisplayName().isEmpty() && stack.getItem() != Item.getItemFromBlock(Blocks.barrier) && + stack.getItem() != Items.arrow) { + if (stack.getTagCompound().getCompoundTag("display").hasKey("Lore", 9)) { + int stars = Utils.getNumberOfStars(stack); + if (stars == 0) continue; + + NBTTagList lore = stack.getTagCompound().getCompoundTag("display").getTagList("Lore", 8); + int costIndex = 10000; + id = NotEnoughUpdates.INSTANCE.manager.getInternalnameFromNBT(stack.getTagCompound()); + if (jsonObject.has(id)) { + jsonObject.remove(id); + } + for (int j = 0; j < lore.tagCount(); j++) { + String entry = lore.getStringTagAt(j); + if (entry.equals("§7Cost")) { + costIndex = j; + } + if (j > costIndex) { + entry = entry.trim(); + int index = entry.lastIndexOf('x'); + String item, amountString; + if (index < 0) { + item = entry.trim() + " x1"; + amountString = "x1"; + } else { + amountString = entry.substring(index); + item = entry.substring(0, index).trim(); + } + item = item.substring(0, item.length() - 3); + int amount = Integer.parseInt(amountString.trim().replace("x", "").replace(",", "")); + if (item.endsWith("Essence")) { + int index2 = entry.indexOf("Essence"); + String type = item.substring(0, index2).trim().substring(2); + newEntry.add("type", new JsonPrimitive(type)); + newEntry.add(String.valueOf(stars), new JsonPrimitive(amount)); + } else { + String itemString = item + " §8x" + amount; + if (!newEntry.has("items")) { + newEntry.add("items", new JsonObject()); + } + if (!newEntry.get("items").getAsJsonObject().has(String.valueOf(stars))) { + newEntry.get("items").getAsJsonObject().add(String.valueOf(stars), new JsonArray()); + } + newEntry + .get("items") + .getAsJsonObject() + .get(String.valueOf(stars)) + .getAsJsonArray() + .add(new JsonPrimitive(itemString)); + } + } + } + jsonObject.add(id, newEntry); + } + } + } + JsonObject itemsObj = jsonObject.get(id).getAsJsonObject().get("items").getAsJsonObject(); + jsonObject.get(id).getAsJsonObject().remove("items"); + jsonObject.get(id).getAsJsonObject().add("items", itemsObj); + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + try { + try ( + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter( + new FileOutputStream(file), + StandardCharsets.UTF_8 + )) + ) { + writer.write(gson.toJson(jsonObject)); + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( + EnumChatFormatting.AQUA + "Parsed and saved: " + EnumChatFormatting.WHITE + id)); + } + } catch (IOException ignored) { + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( + EnumChatFormatting.RED + "Error while writing file.")); + } + } catch (Exception e) { + e.printStackTrace(); + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( + EnumChatFormatting.RED + "Error while parsing inventory. Try again or check logs for details.")); + } + } + } + if (AuctionBINWarning.getInstance().shouldShow()) { AuctionBINWarning.getInstance().keyboardInput(); event.setCanceled(true); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/TooltipTweaks.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/TooltipTweaks.java index b35c6795..79a107b7 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/TooltipTweaks.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/TooltipTweaks.java @@ -1,7 +1,13 @@ package io.github.moulberry.notenoughupdates.options.seperateSections; import com.google.gson.annotations.Expose; -import io.github.moulberry.notenoughupdates.core.config.annotations.*; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigAccordionId; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorAccordion; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorBoolean; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorDraggableList; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorKeybind; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorSlider; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigOption; import org.lwjgl.input.Keyboard; import java.util.ArrayList; @@ -90,6 +96,14 @@ public class TooltipTweaks { @Expose @ConfigOption( + name = "Always show required dungeon items", + desc = "Always show the required items to upgrade to the next star if more than just Essence is needed" + ) + @ConfigEditorBoolean + public boolean alwaysShowRequiredItems = false; + + @Expose + @ConfigOption( name = "Show reforge stats", desc = "Show statistics a reforge stone will apply." ) @@ -139,4 +153,4 @@ public class TooltipTweaks { minStep = 1f ) public int tooltipBorderOpacity = 200; -}
\ No newline at end of file +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java index b8f8554e..22656b1a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java @@ -20,7 +20,13 @@ import net.minecraft.util.EnumChatFormatting; import javax.annotation.Nullable; import java.io.ByteArrayInputStream; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.Base64; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Consumer; import java.util.regex.Matcher; @@ -477,12 +483,13 @@ public class ProfileViewer { } public JsonObject getBingoInformation() { - if (bingoInformation != null) return bingoInformation; - if (updatingBingoInfo.get()) return null; - long currentTime = System.currentTimeMillis(); - if (currentTime - lastBingoInfoState < 15 * 1000) return null; + if (bingoInformation != null && currentTime - lastBingoInfoState < 15 * 1000) return bingoInformation; + if (updatingBingoInfo.get() && bingoInformation != null) return bingoInformation; + if (updatingBingoInfo.get() && bingoInformation == null) return null; + lastBingoInfoState = currentTime; + updatingBingoInfo.set(true); HashMap<String, String> args = new HashMap<>(); args.put("uuid", "" + uuid); @@ -492,15 +499,15 @@ public class ProfileViewer { args, jsonObject -> { if (jsonObject == null) return; - updatingBingoInfo.set(false); if (jsonObject.has("success") && jsonObject.get("success").getAsBoolean()) { bingoInformation = jsonObject; } else { bingoInformation = null; } + updatingBingoInfo.set(false); }, () -> updatingBingoInfo.set(false) ); - return null; + return bingoInformation != null ? bingoInformation : null; } public long getNetWorth(String profileId) { 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 dc88da2f..31499f7f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java @@ -2,7 +2,11 @@ package io.github.moulberry.notenoughupdates.util; import com.google.common.base.Splitter; import com.google.common.collect.Lists; -import com.google.gson.*; +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonPrimitive; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.miscfeatures.SlotLocking; import net.minecraft.client.Minecraft; @@ -30,14 +34,19 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagString; import net.minecraft.network.play.client.C0DPacketCloseWindow; -import net.minecraft.util.*; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.ChatStyle; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.Matrix4f; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.StatCollector; 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.Color; +import java.awt.*; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; @@ -47,7 +56,11 @@ import java.lang.reflect.Method; import java.nio.FloatBuffer; import java.nio.charset.StandardCharsets; import java.nio.file.Files; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -1798,4 +1811,47 @@ public class Utils { return left <= x && x <= left + width && top <= y && y <= top + height; } + + public static int getNumberOfStars(ItemStack stack) { + if (stack != null && stack.hasTagCompound()) { + NBTTagCompound tag = stack.getTagCompound(); + + if (tag.hasKey("ExtraAttributes", 10)) { + NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes"); + if (ea.hasKey("upgrade_level", 99)) { + return ea.getInteger("upgrade_level"); + } else if (ea.hasKey("dungeon_item_level")) { + return ea.getInteger("dungeon_item_level"); + } + } + } + return -1; + } + + public static String getStarsString(int stars) { + EnumChatFormatting colorCode = null; + EnumChatFormatting defaultColorCode = EnumChatFormatting.GOLD; + int amount = 0; + if (stars > 5 && stars < 11) { + colorCode = EnumChatFormatting.LIGHT_PURPLE; + amount = stars - 5; + stars = 5; + } + if (stars > 10) { + colorCode = EnumChatFormatting.AQUA; + defaultColorCode = EnumChatFormatting.LIGHT_PURPLE; + amount = stars - 10; + stars = 5; + } + + StringBuilder stringBuilder = new StringBuilder(); + for (int i = 0; i < stars; i++) { + if (i < amount) { + stringBuilder.append(colorCode).append('\u272A'); + } else { + stringBuilder.append(defaultColorCode).append('\u272A'); + } + } + return stringBuilder.toString(); + } } |