aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java136
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscgui/KatSitterOverlay.java6
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java136
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PetsPage.java22
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java2
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/XPInformation.java41
6 files changed, 95 insertions, 248 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java
index 486640a0..90300bbc 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java
@@ -22,7 +22,6 @@ package io.github.moulberry.notenoughupdates.miscfeatures;
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.JsonElement;
import com.google.gson.JsonNull;
import com.google.gson.JsonObject;
@@ -53,7 +52,6 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
-import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
@@ -442,7 +440,7 @@ public class PetInfoOverlay extends TextOverlay {
String etaStr = null;
String etaMaxStr = null;
- if (currentPet.petLevel.level < 100) {
+ if (currentPet.petLevel.level < currentPet.petLevel.maxLevel) {
float remaining = currentPet.petLevel.currentLevelRequirement - currentPet.petLevel.levelXp;
if (remaining > 0) {
if (xpGain < 1000) {
@@ -454,14 +452,14 @@ public class PetInfoOverlay extends TextOverlay {
}
}
- if (currentPet.petLevel.level < 99 || !NotEnoughUpdates.INSTANCE.config.petOverlay.petOverlayText.contains(6)) {
+ if (currentPet.petLevel.level < (currentPet.petLevel.maxLevel - 1) || !NotEnoughUpdates.INSTANCE.config.petOverlay.petOverlayText.contains(6)) {
float remainingMax = currentPet.petLevel.maxXP - currentPet.petLevel.totalXp;
if (remaining > 0) {
if (xpGain < 1000) {
- etaMaxStr = EnumChatFormatting.AQUA + "Until L100: " +
+ etaMaxStr = EnumChatFormatting.AQUA + "Until L" + currentPet.petLevel.maxLevel + ": " +
EnumChatFormatting.YELLOW + "N/A";
} else {
- etaMaxStr = EnumChatFormatting.AQUA + "Until L100: " +
+ etaMaxStr = EnumChatFormatting.AQUA + "Until L" + currentPet.petLevel.maxLevel + ": " +
EnumChatFormatting.YELLOW + Utils.prettyTime((long) (remainingMax) * 1000 * 60 * 60 / (long) xpGain);
}
}
@@ -546,75 +544,6 @@ public class PetInfoOverlay extends TextOverlay {
}
}
- private static float getMaxLevelXp(JsonArray levels, int offset, int maxLevel) {
- float xpTotal = 0;
-
- for (int i = offset; i < offset + maxLevel - 1; i++) {
- xpTotal += levels.get(i).getAsFloat();
- }
-
- return xpTotal;
- }
-
- private static GuiProfileViewer.PetLevel getLevel(
- String petType,
- int offset,
- float exp
- ) {
- int maxLevel = 100;
-
- JsonArray levels = new JsonArray();
- levels.addAll(Constants.PETS.get("pet_levels").getAsJsonArray());
- JsonElement customLevelingJson = Constants.PETS.get("custom_pet_leveling").getAsJsonObject().get(petType);
- if (customLevelingJson != null) {
- switch (Utils.getElementAsInt(Utils.getElement(customLevelingJson, "type"), 0)) {
- case 1:
- levels.addAll(customLevelingJson.getAsJsonObject().get("pet_levels").getAsJsonArray());
- break;
- case 2:
- levels = customLevelingJson.getAsJsonObject().get("pet_levels").getAsJsonArray();
- break;
- }
- maxLevel = Utils.getElementAsInt(Utils.getElement(customLevelingJson, "max_level"), 100);
- }
-
- float maxXP = getMaxLevelXp(levels, offset, maxLevel);
- boolean isMaxed = exp >= maxXP;
-
- int level = 1;
- float currentLevelRequirement = 0;
- float xpThisLevel = 0;
- float pct = 0;
-
- if (isMaxed) {
- level = maxLevel;
- currentLevelRequirement = levels.get(offset + level - 2).getAsFloat();
- xpThisLevel = currentLevelRequirement;
- } else {
- long totalExp = 0;
- for (int i = offset; i < levels.size(); i++) {
- currentLevelRequirement = levels.get(i).getAsLong();
- totalExp += currentLevelRequirement;
- if (totalExp >= exp) {
- xpThisLevel = currentLevelRequirement - (totalExp - exp);
- level = Math.min(i - offset + 1, maxLevel);
- break;
- }
- }
- pct = currentLevelRequirement != 0 ? xpThisLevel / currentLevelRequirement : 0;
- level += pct;
- }
-
- GuiProfileViewer.PetLevel levelObj = new GuiProfileViewer.PetLevel();
- levelObj.level = level;
- levelObj.currentLevelRequirement = currentLevelRequirement;
- levelObj.maxXP = maxXP;
- levelObj.levelPercentage = pct;
- levelObj.levelXp = xpThisLevel;
- levelObj.totalXp = exp;
- return levelObj;
- }
-
public static Pet getPetFromStack(NBTTagCompound tag) {
if (Constants.PETS == null || Constants.PETS.get("pet_levels") == null ||
Constants.PETS.get("pet_levels") instanceof JsonNull) {
@@ -634,11 +563,10 @@ public class PetInfoOverlay extends TextOverlay {
JsonObject petInfo = new JsonParser().parse(ea.getString("petInfo")).getAsJsonObject();
petType = petInfo.get("type").getAsString();
rarity = Rarity.valueOf(petInfo.get("tier").getAsString());
-
- level = getLevel(
- petType ,
- rarity.petOffset,
- petInfo.get("exp").getAsFloat()
+ level = GuiProfileViewer. getPetLevel(
+ petType,
+ rarity.name(),
+ Utils.getElementAsFloat(petInfo.get("exp"), 0) // Should only default if from item list and repo missing exp:0
);
if (petInfo.has("heldItem")) {
heldItem = petInfo.get("heldItem").getAsString();
@@ -786,7 +714,7 @@ public class PetInfoOverlay extends TextOverlay {
float petXp = petInfoObject.get("exp").getAsFloat();
- double petLevel = XPInformation.getInstance().getPetLevel(name, petXp, rarityString);
+ double petLevel = GuiProfileViewer.getPetLevel(name, rarityString, petXp).level;
int index = getClosestPetIndex(name, rarity, "", (float) petLevel);
if (index != config.selectedPet) {
clearPet();
@@ -976,7 +904,7 @@ public class PetInfoOverlay extends TextOverlay {
}
public static float getXpGain(Pet pet, float xp, String xpType) {
- if (pet.petLevel.level >= 100) return 0;
+ if (pet.petLevel.level >= pet.petLevel.maxLevel) return 0;
if (validXpTypes == null)
validXpTypes = Lists.newArrayList("mining", "foraging", "enchanting", "farming", "combat", "fishing", "alchemy");
@@ -1066,7 +994,7 @@ public class PetInfoOverlay extends TextOverlay {
JsonObject petsJson = Constants.PETS;
if (currentPet != null && petsJson != null) {
currentPet.petLevel = GuiProfileViewer.getPetLevel(
- currentPet.petItem,
+ currentPet.petType,
currentPet.rarity.name(),
currentPet.petLevel.totalXp
);
@@ -1097,48 +1025,6 @@ public class PetInfoOverlay extends TextOverlay {
private int lastLevelHovered = 0;
- private static HashMap<String, String> itemMap = null;
-
- @SubscribeEvent(priority = EventPriority.HIGHEST, receiveCanceled = true)
- public void onTooltip(ItemTooltipEvent event) {
- for (String line : event.toolTip) {
- String lastItemHovered = null;
- if (line.startsWith("\u00a7o\u00a77[Lvl ")) {
- lastItemHovered = null;
-
- String after = line.substring("\u00a7o\u00a77[Lvl ".length());
- if (after.contains("]")) {
- String levelStr = after.split("]")[0];
-
- try {
- lastLevelHovered = Integer.parseInt(levelStr.trim());
- } catch (Exception ignored) {
- }
- }
- } else if (line.startsWith("\u00a75\u00a7o\u00a76Held Item: ")) {
- String after = line.substring("\u00a75\u00a7o\u00a76Held Item: ".length());
-
- if (itemMap == null) {
- itemMap = new HashMap<>();
-
- for (Map.Entry<String, JsonObject> entry : NotEnoughUpdates.INSTANCE.manager
- .getItemInformation()
- .entrySet()) {
- if (entry.getKey().equals("ALL_SKILLS_SUPER_BOOST") ||
- XP_BOOST_PATTERN.matcher(entry.getKey()).matches()) {
- ItemStack stack = NotEnoughUpdates.INSTANCE.manager.jsonToStack(entry.getValue());
- itemMap.put(stack.getDisplayName(), entry.getKey());
- }
- }
- }
-
- if (itemMap.containsKey(after)) {
- lastItemHovered = itemMap.get(after);
- }
- }
- }
- }
-
private static final Pattern AUTOPET_EQUIP = Pattern.compile(
"\u00a7cAutopet \u00a7eequipped your \u00a77\\[Lvl (\\d+)] \u00a7(.{2,})\u00a7e! \u00a7a\u00a7lVIEW RULE\u00a7r");
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/KatSitterOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/KatSitterOverlay.java
index b22ff11f..62aba35b 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/KatSitterOverlay.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/KatSitterOverlay.java
@@ -22,8 +22,8 @@ package io.github.moulberry.notenoughupdates.miscgui;
import com.google.gson.JsonObject;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer;
+import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer;
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;
@@ -69,8 +69,8 @@ public class KatSitterOverlay {
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,
+ (int) GuiProfileViewer.getPetLevel(petId, rarity, (float) xp).level,
+ nextRarityPresent ? (int) GuiProfileViewer.getPetLevel(petId, upgradedRarity, (float) xp).level : null,
gui
);
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java
index 5093b036..09eed1cf 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java
@@ -19,12 +19,14 @@
package io.github.moulberry.notenoughupdates.profileviewer;
+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.cosmetics.ShaderManager;
import io.github.moulberry.notenoughupdates.itemeditor.GuiElementTextField;
+import io.github.moulberry.notenoughupdates.miscfeatures.PetInfoOverlay;
import io.github.moulberry.notenoughupdates.profileviewer.bestiary.BestiaryPage;
import io.github.moulberry.notenoughupdates.profileviewer.trophy.TrophyFishPage;
import io.github.moulberry.notenoughupdates.util.Constants;
@@ -194,102 +196,79 @@ public class GuiProfileViewer extends GuiScreen {
pages.put(ProfileViewerPage.BESTIARY, new BestiaryPage(this));
}
- private static JsonObject getPetInfo(String pet_name, String rarity) {
- JsonObject petInfo = new JsonObject();
+ private static float getMaxLevelXp(JsonArray levels, int offset, int maxLevel) {
+ float xpTotal = 0;
- if (Constants.PETS == null) {
- Utils.showOutdatedRepoNotification();
- return null;
+ for (int i = offset; i < offset + maxLevel - 1; i++) {
+ xpTotal += levels.get(i).getAsFloat();
}
- if (Constants.PETS.has("custom_pet_leveling") && Constants.PETS.getAsJsonObject("custom_pet_leveling").has(pet_name)) {
- JsonObject pet = Constants.PETS.getAsJsonObject("custom_pet_leveling").getAsJsonObject(pet_name);
- if (pet.has("type") && pet.has("pet_levels")) {
- int type = pet.get("type").getAsInt();
- switch (type) {
- case 1:
- JsonArray defaultLevels = Constants.PETS.getAsJsonArray("pet_levels");
- defaultLevels.addAll(pet.getAsJsonArray("pet_levels"));
- petInfo.add("pet_levels", Constants.PETS.getAsJsonArray("pet_levels"));
- break;
- case 2:
- petInfo.add("pet_levels", pet.getAsJsonArray("pet_levels"));
- break;
- default:
- petInfo.add("pet_levels", Constants.PETS.getAsJsonArray("pet_levels"));
- break;
- }
- } else {
- petInfo.add("pet_levels", Constants.PETS.getAsJsonArray("pet_levels"));
- }
- if (pet.has("max_level")) {
- petInfo.add("max_level", pet.get("max_level"));
- } else {
- petInfo.add("max_level", new JsonPrimitive(100));
- }
+ return xpTotal;
+ }
- if (pet.has("pet_rarity_offset")) {
- petInfo.add("offset", pet.get("pet_rarity_offset"));
- } else {
- petInfo.add("offset", Constants.PETS.getAsJsonObject("pet_rarity_offset").get(rarity));
+ public static PetLevel getPetLevel(
+ String petType,
+ String rarity,
+ float exp
+ ) {
+ int offset = PetInfoOverlay.Rarity.valueOf(rarity).petOffset;
+ int maxLevel = 100;
+
+ JsonArray levels = new JsonArray();
+ levels.addAll(Constants.PETS.get("pet_levels").getAsJsonArray());
+ JsonElement customLevelingJson = Constants.PETS.get("custom_pet_leveling").getAsJsonObject().get(petType);
+ if (customLevelingJson != null) {
+ switch (Utils.getElementAsInt(Utils.getElement(customLevelingJson, "type"), 0)) {
+ case 1:
+ levels.addAll(customLevelingJson.getAsJsonObject().get("pet_levels").getAsJsonArray());
+ break;
+ case 2:
+ levels = customLevelingJson.getAsJsonObject().get("pet_levels").getAsJsonArray();
+ break;
}
- } else {
- //System.out.println("Default Path");
- petInfo.add("offset", Constants.PETS.getAsJsonObject("pet_rarity_offset").get(rarity));
- petInfo.add("max_level", new JsonPrimitive(100));
- petInfo.add("pet_levels", Constants.PETS.getAsJsonArray("pet_levels"));
+ maxLevel = Utils.getElementAsInt(Utils.getElement(customLevelingJson, "max_level"), 100);
}
- return petInfo;
- }
-
- public static PetLevel getPetLevel(String pet_name, String rarity, float exp) {
- JsonObject petInfo = getPetInfo(pet_name, rarity);
- if (petInfo == null) {
- return null;
- }
- int offset = petInfo.get("offset").getAsInt();
- int maxPetLevel = petInfo.get("max_level").getAsInt();
- JsonArray levels = petInfo.getAsJsonArray("pet_levels");
+ float maxXP = getMaxLevelXp(levels, offset, maxLevel);
+ boolean isMaxed = exp >= maxXP;
- float xpTotal = 0;
- float level = 1;
+ int level = 1;
float currentLevelRequirement = 0;
- float currentLevelProgress = 0;
-
- boolean addLevel = true;
-
- for (int i = offset; i < offset + maxPetLevel - 1; i++) {
- if (addLevel) {
- currentLevelRequirement = levels.get(i).getAsFloat();
- xpTotal += currentLevelRequirement;
- if (xpTotal > exp) {
- currentLevelProgress = (exp - (xpTotal - currentLevelRequirement));
- addLevel = false;
- } else {
- level += 1;
+ float xpThisLevel = 0;
+ float pct = 0;
+
+ if (isMaxed) {
+ level = maxLevel;
+ currentLevelRequirement = levels.get(offset + level - 2).getAsFloat();
+ xpThisLevel = currentLevelRequirement;
+ pct = 1;
+ } else {
+ long totalExp = 0;
+ for (int i = offset; i < levels.size(); i++) {
+ currentLevelRequirement = levels.get(i).getAsLong();
+ totalExp += currentLevelRequirement;
+ if (totalExp >= exp) {
+ xpThisLevel = currentLevelRequirement - (totalExp - exp);
+ level = Math.min(i - offset + 1, maxLevel);
+ break;
}
- } else {
- xpTotal += levels.get(i).getAsFloat();
}
+ pct = currentLevelRequirement != 0 ? xpThisLevel / currentLevelRequirement : 0;
+ level += pct;
}
- level += currentLevelProgress / currentLevelRequirement;
- if (level <= 0) {
- level = 1;
- } else if (level > maxPetLevel) {
- level = maxPetLevel;
- }
- PetLevel levelObj = new PetLevel();
+ GuiProfileViewer.PetLevel levelObj = new GuiProfileViewer.PetLevel();
levelObj.level = level;
+ levelObj.maxLevel = maxLevel;
levelObj.currentLevelRequirement = currentLevelRequirement;
- levelObj.maxXP = xpTotal;
- levelObj.levelPercentage = currentLevelProgress / currentLevelRequirement;
- levelObj.levelXp = currentLevelProgress;
+ levelObj.maxXP = maxXP;
+ levelObj.levelPercentage = pct;
+ levelObj.levelXp = xpThisLevel;
levelObj.totalXp = exp;
return levelObj;
}
+
public static String shortNumberFormat(double n, int iteration) {
if (n < 1000) {
if (n % 1 == 0) {
@@ -1269,6 +1248,7 @@ public class GuiProfileViewer extends GuiScreen {
public static class PetLevel {
public float level;
+ public float maxLevel;
public float currentLevelRequirement;
public float maxXP;
public float levelPercentage;
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PetsPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PetsPage.java
index e9d7bbd3..4214371c 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PetsPage.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PetsPage.java
@@ -22,6 +22,7 @@ package io.github.moulberry.notenoughupdates.profileviewer;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
import io.github.moulberry.notenoughupdates.util.Constants;
import io.github.moulberry.notenoughupdates.util.SBInfo;
@@ -291,6 +292,27 @@ public class PetsPage extends GuiProfileViewerPage {
}
tag.setTag("display", display);
}
+
+ // Adds the missing pet fields to the tag
+ NBTTagCompound extraAttributes = new NBTTagCompound();
+ JsonObject petInfo = new JsonObject();
+ if(tag.hasKey("ExtraAttributes", 10)) {
+ extraAttributes = tag.getCompoundTag("ExtraAttributes");
+ if (extraAttributes.hasKey("petInfo", 8)) {
+ petInfo = new JsonParser().parse(extraAttributes.getString("petInfo")).getAsJsonObject();
+ }
+ }
+ petInfo.addProperty("exp", exp);
+ petInfo.addProperty("tier", tier);
+ petInfo.addProperty("type", petname);
+ if (heldItem != null) {
+ petInfo.addProperty("heldItem", heldItem);
+ }
+ if (skin != null) {
+ petInfo.addProperty("skin", skin);
+ }
+ extraAttributes.setString("petInfo", petInfo.toString());
+ tag.setTag("ExtraAttributes", extraAttributes);
stack.setTagCompound(tag);
}
sortedPetsStack.add(stack);
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 911b74f8..bcec7526 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java
@@ -1276,7 +1276,7 @@ public class ProfileViewer {
JsonArray pets = petsElement.getAsJsonArray();
for (int i = 0; i < pets.size(); i++) {
JsonObject pet = pets.get(i).getAsJsonObject();
- if (pet.has("active") && pet.get("active").getAsJsonPrimitive().getAsBoolean()) {
+ if (pet.has("active") && pet.get("active").getAsBoolean()) {
activePet = pet;
break;
}
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 f9f1663e..58794e07 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/util/XPInformation.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/util/XPInformation.java
@@ -21,7 +21,6 @@ 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;
@@ -34,9 +33,6 @@ import java.util.List;
import java.util.Map;
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();
@@ -249,41 +245,4 @@ public class XPInformation {
skillInfoMap.put(skill.toLowerCase(), info);
}
}
-
- public double getPetLevel(String petId, double exp, String rarity) {
- if (Constants.PETS == null || !Constants.PETS.has("pet_levels")) {
- Utils.showOutdatedRepoNotification();
- return 0;
- }
- Stream<JsonElement> pet_levels =
- StreamSupport.stream(Constants.PETS.get("pet_levels").getAsJsonArray().spliterator(), false);
- if (!Constants.PETS.has("pet_rarity_offset")) {
- Utils.showOutdatedRepoNotification();
- return 0;
- }
- int pet_rarity_offset = Constants.PETS.getAsJsonObject("pet_rarity_offset").get(rarity).getAsInt();
- if (!Constants.PETS.has("custom_pet_leveling")) {
- Utils.showOutdatedRepoNotification();
- return 0;
- }
- 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();
- }
-
}