aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2022-07-20 13:24:57 +0200
committerGitHub <noreply@github.com>2022-07-20 13:24:57 +0200
commit8209ae8cc7dc6476a96547534efe991049e8b49b (patch)
tree729c6f7de3f92046d0e24d4fad5f62e0e9cdb0d5 /src/main/java
parente91d0907148e08352f3679324dc3e6460de1be38 (diff)
downloadNotEnoughUpdates-8209ae8cc7dc6476a96547534efe991049e8b49b.tar.gz
NotEnoughUpdates-8209ae8cc7dc6476a96547534efe991049e8b49b.tar.bz2
NotEnoughUpdates-8209ae8cc7dc6476a96547534efe991049e8b49b.zip
Added trophy reward overlay (#192)
* added trophy reward overlay * (hopefully) fixed infer "no crash" ~ jani * fix efe code Co-authored-by: Lorenz <ESs95s3P5z8Pheb> Co-authored-by: nopo <noahogno@gmail.com>
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java2
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java19
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionProfit.java7
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscgui/TrophyRewardOverlay.java276
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Fishing.java25
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/Constants.java2
6 files changed, 328 insertions, 3 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java
index 76387844..8c23aa60 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java
@@ -58,6 +58,7 @@ import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.Dwarve
import io.github.moulberry.notenoughupdates.miscgui.CalendarOverlay;
import io.github.moulberry.notenoughupdates.miscgui.InventoryStorageSelector;
import io.github.moulberry.notenoughupdates.miscgui.SignCalculator;
+import io.github.moulberry.notenoughupdates.miscgui.TrophyRewardOverlay;
import io.github.moulberry.notenoughupdates.mixins.AccessorMinecraft;
import io.github.moulberry.notenoughupdates.options.NEUConfig;
import io.github.moulberry.notenoughupdates.overlays.FuelBar;
@@ -285,6 +286,7 @@ public class NotEnoughUpdates {
MinecraftForge.EVENT_BUS.register(new RenderListener(this));
MinecraftForge.EVENT_BUS.register(new OldAnimationChecker());
MinecraftForge.EVENT_BUS.register(new SignCalculator());
+ MinecraftForge.EVENT_BUS.register(TrophyRewardOverlay.getInstance());
MinecraftForge.EVENT_BUS.register(navigation);
if (Minecraft.getMinecraft().getResourceManager() instanceof IReloadableResourceManager) {
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 459a7231..794282f1 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java
@@ -46,6 +46,7 @@ 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.miscgui.TrophyRewardOverlay;
import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer;
import io.github.moulberry.notenoughupdates.options.NEUConfig;
import io.github.moulberry.notenoughupdates.overlays.AuctionSearchOverlay;
@@ -502,6 +503,12 @@ public class RenderListener {
x += 80 + 28;
}
}
+ if (TrophyRewardOverlay.inTrophyFishingInventory()) {
+ int diffX = 162;
+ if (x > guiLeft + xSize && x < guiLeft + xSize + diffX + 5 && y > guiTop - 18 && y < guiTop + 120) {
+ x += diffX;
+ }
+ }
if (AuctionProfit.inAuctionPage()) {
if (x + 18 > guiLeft + xSize && x + 18 < guiLeft + xSize + 4 + 28 + 20 && y > guiTop - 180 && y < guiTop + 56) {
x -= 68 - 200;
@@ -614,6 +621,12 @@ public class RenderListener {
x += 80 + 28;
}
}
+ if (TrophyRewardOverlay.inTrophyFishingInventory()) {
+ int diffX = 162;
+ if (x > guiLeft + xSize && x < guiLeft + xSize + diffX + 5 && y > guiTop - 18 && y < guiTop + 120) {
+ x += diffX;
+ }
+ }
if (AuctionProfit.inAuctionPage()) {
if (x + 18 > guiLeft + xSize && x + 18 < guiLeft + xSize + 4 + 28 + 20 && y > guiTop - 180 && y < guiTop + 56) {
x -= 68 - 200;
@@ -1016,6 +1029,12 @@ public class RenderListener {
x += 80 + 28;
}
}
+ if (TrophyRewardOverlay.inTrophyFishingInventory()) {
+ int diffX = 162;
+ if (x > guiLeft + xSize && x < guiLeft + xSize + diffX + 5 && y > guiTop - 18 && y < guiTop + 120) {
+ x += diffX;
+ }
+ }
if (AuctionProfit.inAuctionPage()) {
if (x + 18 > guiLeft + xSize && x + 18 < guiLeft + xSize + 4 + 28 + 20 && y > guiTop - 180 && y < guiTop + 56) {
x -= 68 - 200;
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionProfit.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionProfit.java
index 03f19bd8..e1024eab 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionProfit.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionProfit.java
@@ -20,13 +20,13 @@
package io.github.moulberry.notenoughupdates.miscfeatures;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
-import io.github.moulberry.notenoughupdates.miscfeatures.entityviewer.InvisibleModifier;
import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer;
import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer;
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.client.renderer.GlStateManager;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ContainerChest;
@@ -46,11 +46,12 @@ public class AuctionProfit {
@SubscribeEvent
public void onDrawBackground(GuiScreenEvent.BackgroundDrawnEvent event) {
- if(!inAuctionPage()) return;
+ if (!inAuctionPage()) return;
Minecraft minecraft = Minecraft.getMinecraft();
Container inventoryContainer = minecraft.thePlayer.openContainer;
+ if (!(Minecraft.getMinecraft().currentScreen instanceof GuiChest)) return;
Gui gui = event.gui;
int xSize = ((AccessorGuiContainer) gui).getXSize();
int guiLeft = ((AccessorGuiContainer) gui).getGuiLeft();
@@ -172,6 +173,6 @@ public class AuctionProfit {
if (!(inventoryContainer instanceof ContainerChest)) return false;
ContainerChest containerChest = (ContainerChest) inventoryContainer;
return containerChest.getLowerChestInventory().getDisplayName()
- .getUnformattedText().equalsIgnoreCase("Manage Auctions");
+ .getUnformattedText().equalsIgnoreCase("Manage Auctions");
}
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/TrophyRewardOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/TrophyRewardOverlay.java
new file mode 100644
index 00000000..df635d5c
--- /dev/null
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/TrophyRewardOverlay.java
@@ -0,0 +1,276 @@
+/*
+ * Copyright (C) 2022 NotEnoughUpdates contributors
+ *
+ * This file is part of NotEnoughUpdates.
+ *
+ * NotEnoughUpdates is free software: you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * NotEnoughUpdates is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package io.github.moulberry.notenoughupdates.miscgui;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
+import io.github.moulberry.notenoughupdates.events.RepositoryReloadEvent;
+import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer;
+import io.github.moulberry.notenoughupdates.util.Constants;
+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.GuiScreen;
+import net.minecraft.client.gui.inventory.GuiChest;
+import net.minecraft.client.gui.inventory.GuiContainer;
+import net.minecraft.client.renderer.GlStateManager;
+import net.minecraft.inventory.Container;
+import net.minecraft.inventory.ContainerChest;
+import net.minecraft.inventory.Slot;
+import net.minecraft.item.ItemStack;
+import net.minecraft.util.ResourceLocation;
+import net.minecraftforge.client.event.GuiScreenEvent;
+import net.minecraftforge.event.entity.player.ItemTooltipEvent;
+import net.minecraftforge.fml.common.eventhandler.EventPriority;
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
+import org.lwjgl.opengl.GL11;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+public class TrophyRewardOverlay {
+ private static TrophyRewardOverlay instance = null;
+
+ private final Map<String, Integer> data = new HashMap<>();
+ private boolean reloadNeeded = true;
+
+ public static final ResourceLocation trophyProfitImage =
+ new ResourceLocation("notenoughupdates:trophy_profit.png");
+
+ public static TrophyRewardOverlay getInstance() {
+ if (instance == null) {
+ instance = new TrophyRewardOverlay();
+ }
+ return instance;
+ }
+
+ /**
+ * This adds support for the /neureloadrepo command
+ */
+ @SubscribeEvent(priority = EventPriority.LOWEST)
+ public void reload(RepositoryReloadEvent event) {
+ reloadNeeded = true;
+ }
+
+ @SubscribeEvent(priority = EventPriority.LOW)
+ public void onItemTooltipLow(ItemTooltipEvent event) {
+ if (!inTrophyFishingInventory()) return;
+ if (!NotEnoughUpdates.INSTANCE.config.fishing.trophyRewardTooltips) return;
+
+ ItemStack itemStack = event.itemStack;
+ if (itemStack == null) return;
+ if (!"§aFillet Trophy Fish".equals(itemStack.getDisplayName())) return;
+
+ event.toolTip.add(4, getToolTip());
+ event.toolTip.add(4, "");
+ }
+
+ private String getToolTip() {
+ List<String> line = createText();
+ if (line.size() == 1) {
+ return line.get(0);
+ }
+
+ return line.get(1);
+ }
+
+ @SubscribeEvent(priority = EventPriority.LOWEST)
+ public void onDrawBackground(GuiScreenEvent.BackgroundDrawnEvent event) {
+ if (!inTrophyFishingInventory()) return;
+ if (!NotEnoughUpdates.INSTANCE.config.fishing.trophyRewardOverlay) return;
+
+ GuiScreen screen = Minecraft.getMinecraft().currentScreen;
+ if (!(screen instanceof GuiChest)) return;
+ Gui gui = event.gui;
+ int xSize = ((AccessorGuiContainer) gui).getXSize();
+ int guiLeft = ((AccessorGuiContainer) gui).getGuiLeft();
+ int guiTop = ((AccessorGuiContainer) gui).getGuiTop();
+
+ List<String> list = createText();
+ int removed = 0;
+ if (list.size() > 11) {
+ while (list.size() > 10) {
+ removed++;
+ list.remove(9);
+ }
+ list.add("§8And " + removed + " more..");
+ }
+ renderBasicOverlay(event, guiLeft + xSize + 3, guiTop, list);
+ }
+
+ private void load() {
+ data.clear();
+
+ JsonObject jsonObject = Constants.TROPHYFISH;
+ if (jsonObject == null) {
+ return;
+ }
+
+ String[] tiers = new String[]{"_BRONZE", "_SILVER", "_GOLD", "_DIAMOND"};
+
+ for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) {
+ String name = entry.getKey();
+
+ int i = 0;
+ for (JsonElement element : entry.getValue().getAsJsonArray()) {
+ int price = element.getAsInt();
+ data.put(name + tiers[i], price);
+ i++;
+ }
+ }
+ }
+
+ private List<String> createText() {
+ if (reloadNeeded) {
+ load();
+ reloadNeeded = false;
+ }
+
+ List<String> texts = new ArrayList<>();
+ if (data.isEmpty()) {
+ texts.add("§cNo data in Repo found!");
+ return texts;
+ }
+
+ Map<String, Integer> totalAmount = new HashMap<>();
+ Map<String, Integer> totalExchange = new HashMap<>();
+ readInventory(totalAmount, totalExchange);
+
+ int total = totalExchange.values().stream().mapToInt(value -> value).sum();
+ texts.add("Trophy Fish Exchange");
+ texts.add("Magma Fish: §e" + total);
+
+ for (Map.Entry<String, Integer> entry : sortByValue(totalExchange).entrySet()) {
+ String name = entry.getKey();
+ int amount = totalAmount.get(name);
+ String[] split = name.split(" ");
+ String rarity = split[split.length - 1];
+ name = name.substring(0, name.length() - rarity.length() - 1);
+
+ if (name.length() > 20) {
+ name = name.substring(0, 18) + "..";
+ }
+
+ String rarityColor = rarity.replace("§l", "").substring(0, 2);
+ texts.add(String.format("%s%dx §r%s§f: §e%d", rarityColor, amount, name, entry.getValue()));
+ }
+
+ return texts;
+ }
+
+ private void readInventory(Map<String, Integer> totalAmount, Map<String, Integer> totalExchange) {
+ if (Minecraft.getMinecraft().thePlayer.openContainer instanceof ContainerChest) {
+
+ for (Slot slot : Minecraft.getMinecraft().thePlayer.openContainer.inventorySlots) {
+ if (!slot.getHasStack()) continue;
+ ItemStack stack = slot.getStack();
+ if (stack != null) {
+ String internalId = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stack);
+ if (data.containsKey(internalId)) {
+ String displayName = stack.getDisplayName();
+ int stackSize = stack.stackSize;
+
+ int amount = totalAmount.getOrDefault(displayName, 0) + stackSize;
+ totalAmount.put(displayName, amount);
+
+ int exchangeRate = data.get(internalId);
+ int exchangeValue = totalExchange.getOrDefault(displayName, 0) + exchangeRate * stackSize;
+ totalExchange.put(displayName, exchangeValue);
+ }
+ }
+ }
+ }
+ }
+
+ //TODO move into utils class maybe?
+ public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue(Map<K, V> map) {
+ List<Map.Entry<K, V>> list = new ArrayList<>(map.entrySet());
+ list.sort(Map.Entry.comparingByValue());
+ Collections.reverse(list);
+
+ Map<K, V> result = new LinkedHashMap<>();
+ for (Map.Entry<K, V> entry : list) {
+ result.put(entry.getKey(), entry.getValue());
+ }
+
+ return result;
+ }
+
+ private void renderBasicOverlay(
+ GuiScreenEvent.BackgroundDrawnEvent event,
+ int x,
+ int y,
+ List<String> texts
+ ) {
+
+ Gui gui = event.gui;
+ int xSize = ((AccessorGuiContainer) gui).getXSize();
+ int guiLeft = ((AccessorGuiContainer) gui).getGuiLeft();
+ int guiTop = ((AccessorGuiContainer) gui).getGuiTop();
+ Minecraft minecraft = Minecraft.getMinecraft();
+ minecraft.getTextureManager().bindTexture(trophyProfitImage);
+ GL11.glColor4f(1, 1, 1, 1);
+ GlStateManager.disableLighting();
+
+ Utils.drawTexturedRect(guiLeft + xSize + 4, guiTop, 158, 128, 0, 1, 0, 1, GL11.GL_NEAREST);
+
+ int a = guiLeft + xSize + 4;
+ FontRenderer fontRendererObj = minecraft.fontRendererObj;
+
+ //Render first two header lines
+ int i = 0;
+ for (String text : texts) {
+ fontRendererObj.drawString("§8" + text, a + 10, guiTop + 6 + i, -1, false);
+ i += 10;
+ if (i == 20) break;
+ }
+
+ //Render all other lines
+ i = 25;
+ int index = 0;
+ for (String text : texts) {
+ if (index > 1) {
+ fontRendererObj.drawString(text, a + 10, guiTop + 6 + i, -1, false);
+ i += 10;
+ } else {
+ index++;
+ }
+ }
+ }
+
+ public static boolean inTrophyFishingInventory() {
+ if (!NotEnoughUpdates.INSTANCE.isOnSkyblock()) return false;
+
+ Minecraft minecraft = Minecraft.getMinecraft();
+ if (minecraft == null || minecraft.thePlayer == null) return false;
+
+ Container inventoryContainer = minecraft.thePlayer.openContainer;
+ if (!(inventoryContainer instanceof ContainerChest)) return false;
+ ContainerChest containerChest = (ContainerChest) inventoryContainer;
+ return containerChest.getLowerChestInventory().getDisplayName()
+ .getUnformattedText().equalsIgnoreCase("Trophy Fishing");
+ }
+}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Fishing.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Fishing.java
index 513474ca..b6075794 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Fishing.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Fishing.java
@@ -273,4 +273,29 @@ public class Fishing {
@ConfigAccordionId(id = 6)
public boolean fishingSound30Sec = true;
+ @ConfigOption(
+ name = "Trophy Reward",
+ desc = ""
+ )
+ @ConfigEditorAccordion(id = 7)
+ public boolean trophyReward = false;
+
+ @Expose
+ @ConfigOption(
+ name = "Trophy Reward Overlay",
+ desc = "Displays an overlay at Odger that shows information about your trophies"
+ )
+ @ConfigEditorBoolean
+ @ConfigAccordionId(id = 7)
+ public boolean trophyRewardOverlay = true;
+
+ @Expose
+ @ConfigOption(
+ name = "Trophy Reward Tooltips",
+ desc = "Displays the exchange of your trophies as a tooltip in the Odger Inventory"
+ )
+ @ConfigEditorBoolean
+ @ConfigAccordionId(id = 7)
+ public boolean trophyRewardTooltips = true;
+
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/Constants.java b/src/main/java/io/github/moulberry/notenoughupdates/util/Constants.java
index 3230714a..5279ed73 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/util/Constants.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Constants.java
@@ -69,6 +69,7 @@ public class Constants {
public static JsonObject ESSENCECOSTS;
public static JsonObject FAIRYSOULS;
public static JsonObject REFORGESTONES;
+ public static JsonObject TROPHYFISH;
private static final ReentrantLock lock = new ReentrantLock();
@@ -88,6 +89,7 @@ public class Constants {
ESSENCECOSTS = Utils.getConstant("essencecosts", gson);
FAIRYSOULS = Utils.getConstant("fairy_souls", gson);
REFORGESTONES = Utils.getConstant("reforgestones", gson);
+ TROPHYFISH = Utils.getConstant("trophyfish", gson);
} catch (Exception ex) {
ex.printStackTrace();
} finally {