aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornea <romangraef@gmail.com>2022-02-15 19:30:11 +0100
committernea <romangraef@gmail.com>2022-02-15 19:30:11 +0100
commitc29016098c558fc87af15f5895f09f416d6e7f2a (patch)
tree3f5b1188882cd666cf5153589310f960020481cc
parent93a1cb847bda30d976057954a408c615e0b08119 (diff)
downloadNotEnoughUpdates-c29016098c558fc87af15f5895f09f416d6e7f2a.tar.gz
NotEnoughUpdates-c29016098c558fc87af15f5895f09f416d6e7f2a.tar.bz2
NotEnoughUpdates-c29016098c558fc87af15f5895f09f416d6e7f2a.zip
kat sitter overlay
-rw-r--r--Update Notes/2.1.md1
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java5
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscgui/KatSitterOverlay.java88
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/PetOverlay.java8
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java17
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/XPInformation.java24
6 files changed, 142 insertions, 1 deletions
diff --git a/Update Notes/2.1.md b/Update Notes/2.1.md
index 4dbf4587..338c898e 100644
--- a/Update Notes/2.1.md
+++ b/Update Notes/2.1.md
@@ -19,6 +19,7 @@
- Make cata xp in /pv be calculated on how many runs you have and shows master mode xp rates
- Hide mine waypoints when at location setting - Lulonaut
- Added some info panels to some settings in /neu
+- Added Kat Level After Upgrade Estimator - nea89
- Added /pv button in /neu
- Added pitch and coins/m as options in farming skill overlay
- Make it so tab completion in ah search GUI goes down the items - Lulonaut
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java
index bf3a0714..3aaad72c 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java
@@ -3,6 +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.miscgui.KatSitterOverlay;
import io.github.moulberry.notenoughupdates.recipes.CraftingOverlay;
import io.github.moulberry.notenoughupdates.recipes.CraftingRecipe;
import io.github.moulberry.notenoughupdates.recipes.Ingredient;
@@ -82,6 +83,8 @@ public class NEUManager {
public File configFile;
public HotmInformation hotm;
+ public KatSitterOverlay katSitterOverlay;
+
public CraftingOverlay craftingOverlay;
public NEUManager(NotEnoughUpdates neu, File configLocation) {
@@ -90,7 +93,7 @@ public class NEUManager {
this.auctionManager = new APIManager(this);
this.hotm = new HotmInformation(neu);
this.craftingOverlay = new CraftingOverlay(this);
-
+ this.katSitterOverlay = new KatSitterOverlay();
GIT_COMMITS_URL = neu.config.hidden.repoCommitsURL;
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/KatSitterOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/KatSitterOverlay.java
new file mode 100644
index 00000000..39d3a673
--- /dev/null
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/KatSitterOverlay.java
@@ -0,0 +1,88 @@
+package io.github.moulberry.notenoughupdates.miscgui;
+
+import com.google.gson.JsonObject;
+import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
+import io.github.moulberry.notenoughupdates.util.Utils;
+import io.github.moulberry.notenoughupdates.util.XPInformation;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.FontRenderer;
+import net.minecraft.client.gui.inventory.GuiChest;
+import net.minecraft.client.renderer.GlStateManager;
+import net.minecraft.init.Blocks;
+import net.minecraft.inventory.ContainerChest;
+import net.minecraft.inventory.Slot;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraftforge.client.event.GuiScreenEvent;
+import net.minecraftforge.common.MinecraftForge;
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
+
+public class KatSitterOverlay {
+ public KatSitterOverlay() {
+ MinecraftForge.EVENT_BUS.register(this);
+ }
+
+ @SubscribeEvent
+ public void onGuiDrawn(GuiScreenEvent.DrawScreenEvent.Post event) {
+ if (!(event.gui instanceof GuiChest)) return;
+ if (!NotEnoughUpdates.INSTANCE.config.petOverlay.showKatSitting) return;
+ GuiChest gui = (GuiChest) event.gui;
+ ContainerChest container = (ContainerChest) gui.inventorySlots;
+ if (!"Pet Sitter".equals(container.getLowerChestInventory().getDisplayName().getUnformattedText())) return;
+ Slot slot = container.getSlot(13);
+ if (slot == null || !slot.getHasStack() || slot.getStack() == null) return;
+ ItemStack item = slot.getStack();
+ NBTTagCompound tagCompound = item.getTagCompound();
+ if (tagCompound == null || !tagCompound.hasKey("ExtraAttributes", 10)) return;
+ NBTTagCompound extra = tagCompound.getCompoundTag("ExtraAttributes");
+ if (extra == null || !extra.hasKey("id", 8) ||
+ !"PET".equals(extra.getString("id")) || !extra.hasKey("petInfo", 8))
+ return;
+ JsonObject petInfo = NotEnoughUpdates.INSTANCE.manager.gson.fromJson(extra.getString("petInfo"), JsonObject.class);
+ if (petInfo == null || !petInfo.has("exp") || !petInfo.has("tier") || !petInfo.has("type")) return;
+ String petId = petInfo.get("type").getAsString();
+ double xp = petInfo.get("exp").getAsDouble();
+ String rarity = petInfo.get("tier").getAsString();
+ Slot katSlot = container.getSlot(22);
+ String upgradedRarity = nextRarity(rarity);
+ boolean nextRarityPresent = katSlot.getStack() != null && katSlot.getStack().getItem() != Item.getItemFromBlock(Blocks.barrier) && upgradedRarity != null;
+ renderPetInformation(
+ (int) XPInformation.getInstance().getPetLevel(petId, xp, rarity),
+ nextRarityPresent ? (int) XPInformation.getInstance().getPetLevel(petId, xp, upgradedRarity) : null,
+ gui
+ );
+ }
+
+
+ public void renderPetInformation(int currentLevel, Integer upgradedLevel, GuiChest gui) {
+ FontRenderer font = Minecraft.getMinecraft().fontRendererObj;
+ String currentText = "Current pet level: " + currentLevel;
+ int currentWidth = font.getStringWidth(currentText);
+ String upgradedText = "Upgraded pet level: " + upgradedLevel;
+ int upgradedWidth = font.getStringWidth(upgradedText);
+ int left = gui.guiLeft - 30 - (upgradedLevel == null ? Math.max(upgradedWidth, currentWidth) : currentWidth);
+ GlStateManager.disableLighting();
+ GlStateManager.color(1F, 1F, 1F, 1F);
+ Utils.drawStringScaled(currentText, font, left, gui.guiTop + 25, false, 0xFFD700, 1F);
+ if (upgradedLevel != null)
+ Utils.drawStringScaled(upgradedText, font, left, gui.guiTop + 45, false, 0xFFD700, 1F);
+ }
+
+ public String nextRarity(String currentRarity) {
+ switch (currentRarity.intern()) {
+ case "COMMON":
+ return "UNCOMMON";
+ case "UNCOMMON":
+ return "RARE";
+ case "RARE":
+ return "EPIC";
+ case "EPIC":
+ return "LEGENDARY";
+ case "LEGENDARY":
+ return "MYTHIC";
+ }
+ return null;
+ }
+
+}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/PetOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/PetOverlay.java
index a9adb4ad..7b0ed48c 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/PetOverlay.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/PetOverlay.java
@@ -105,4 +105,12 @@ public class PetOverlay {
)
@ConfigEditorBoolean
public boolean hidePetTooltip = false;
+
+ @Expose
+ @ConfigOption(
+ name = "Show upgraded Pet Level",
+ desc = "Show the estimated pet level after an upgrade at Kats"
+ )
+ @ConfigEditorBoolean
+ public boolean showKatSitting = true;
}
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 3711f1e5..00a6e5f4 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java
@@ -48,6 +48,8 @@ import java.nio.FloatBuffer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.*;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.BiFunction;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -830,6 +832,10 @@ public class Utils {
GlStateManager.scale(1 / factor, 1 / factor, 1);
}
+ public static void drawStringRightAligned(String str, FontRenderer fr, float x, float y , boolean shadow, int colour, float factor) {
+ drawStringScaled(str, fr, x - fr.getStringWidth(str) * factor, y, shadow, colour, factor);
+ }
+
public static void drawStringScaledMax(String str, FontRenderer fr, float x, float y, boolean shadow, int colour, float factor, int len) {
int strLen = fr.getStringWidth(str);
float f = len / (float) strLen;
@@ -1470,4 +1476,15 @@ public class Utils {
return left <= x && x <= left + width &&
top <= y && y <= top + height;
}
+
+ public static <T, U> List<U> runningReduce(Iterable<T> values, U initial, BiFunction<T, U, U> reducer) {
+ Spliterator<T> spliterator = values.spliterator();
+ long size = spliterator.estimateSize();
+ List<U> rets = new ArrayList<>(Math.toIntExact(size == Long.MAX_VALUE ? 0 : size));
+ AtomicReference<U> acc = new AtomicReference<>(initial);
+ spliterator.forEachRemaining(it -> {
+ acc.getAndUpdate(value -> reducer.apply(it, value));
+ });
+ return rets;
+ }
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/XPInformation.java b/src/main/java/io/github/moulberry/notenoughupdates/util/XPInformation.java
index cac4cf74..d1bed30e 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/util/XPInformation.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/util/XPInformation.java
@@ -2,6 +2,7 @@ package io.github.moulberry.notenoughupdates.util;
import com.google.common.base.Splitter;
import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import io.github.moulberry.notenoughupdates.core.util.StringUtils;
import io.github.moulberry.notenoughupdates.profileviewer.ProfileViewer;
@@ -13,6 +14,9 @@ import java.util.HashMap;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import java.util.stream.StreamSupport;
public class XPInformation {
private static final XPInformation INSTANCE = new XPInformation();
@@ -208,4 +212,24 @@ public class XPInformation {
skillInfoMap.put(skill.toLowerCase(), info);
}
}
+
+ public double getPetLevel(String petId, double exp, String rarity) {
+ Stream<JsonElement> pet_levels = StreamSupport.stream(Constants.PETS.get("pet_levels").getAsJsonArray().spliterator(), false);
+ int pet_rarity_offset = Constants.PETS.getAsJsonObject("pet_rarity_offset").get(rarity).getAsInt();
+ JsonObject custom_pet_leveling = Constants.PETS.getAsJsonObject("custom_pet_leveling").getAsJsonObject(petId);
+ List<Integer> xpLevelsRequired = pet_levels.skip(pet_rarity_offset).limit(100).map(JsonElement::getAsInt).collect(Collectors.toList());
+ if (custom_pet_leveling != null && custom_pet_leveling.get("type").getAsInt() == 1)
+ xpLevelsRequired.addAll(StreamSupport.stream(custom_pet_leveling.getAsJsonArray("pet_levels").spliterator(), false).map(JsonElement::getAsInt).collect(Collectors.toList()));
+ double remainingExp = exp;
+ for (int i = 0; i < xpLevelsRequired.size(); i++) {
+ int xpForCurrentLevel = xpLevelsRequired.get(i);
+ if (remainingExp >= xpForCurrentLevel) {
+ remainingExp -= xpForCurrentLevel;
+ } else {
+ return i + 1 + remainingExp / xpForCurrentLevel;
+ }
+ }
+ return xpLevelsRequired.size();
+ }
+
}