aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io
diff options
context:
space:
mode:
authorDoKM <mcazzyman@gmail.com>2021-08-23 15:15:15 +0200
committerDoKM <mcazzyman@gmail.com>2021-08-23 15:15:15 +0200
commit752e77d7407bfa7a0355677cd15d205fccf8d8f1 (patch)
tree35ba288d48983e8742de28d0e0f44d351ee7cde4 /src/main/java/io
parentf85740988b8fe5ae8255a97eca2333e63937f96c (diff)
downloadNotEnoughUpdates-752e77d7407bfa7a0355677cd15d205fccf8d8f1.tar.gz
NotEnoughUpdates-752e77d7407bfa7a0355677cd15d205fccf8d8f1.tar.bz2
NotEnoughUpdates-752e77d7407bfa7a0355677cd15d205fccf8d8f1.zip
Fix some pet xp tooltip bugs
Diffstat (limited to 'src/main/java/io')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java120
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java7
2 files changed, 85 insertions, 42 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java
index 08fee4b2..29013ea5 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java
@@ -2286,6 +2286,19 @@ public class NEUEventListener {
index++;
}
+ for (int i = newTooltip.size()-1; i >=0; i--) {
+ String line = Utils.cleanColour(newTooltip.get(i));
+ for (int i1 = 0; i1 < Utils.rarityArr.length; i1++) {
+ if(line.equals(Utils.rarityArr[i1])){
+ if(i-2 <0){
+ break;
+ }
+ newTooltip.addAll(i-1, petToolTipXPExtend(event));
+ break;
+ }
+ }
+ }
+
pressedShiftLast = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT);
pressedArrowLast = Keyboard.isKeyDown(Keyboard.KEY_LEFT) || Keyboard.isKeyDown(Keyboard.KEY_RIGHT);
@@ -2306,7 +2319,7 @@ public class NEUEventListener {
ItemPriceInformation.addToTooltip(event.toolTip, internalname, event.itemStack);
}
- //petToolTipXPExtend(event, false);
+
@@ -2315,15 +2328,13 @@ public class NEUEventListener {
private Pattern xpLevelPattern = Pattern.compile("(.*) (\\xA7e(.*)\\xA76/\\xA7e(.*))");
private void onItemToolTipInternalNameNull(ItemTooltipEvent event){
- petToolTipXPExtend(event, true);
+ petToolTipXPExtendPetMenu(event);
}
- private void petToolTipXPExtend(ItemTooltipEvent event, boolean xpBarExists) {
-
+ private List<String> petToolTipXPExtend(ItemTooltipEvent event) {
+ List<String> tooltipText = new ArrayList();
if (NotEnoughUpdates.INSTANCE.config.tooltipTweaks.petExtendExp) {
-
-
//7 is just a random number i chose, prob no pets with less lines than 7
if (event.toolTip.size() > 7) {
@@ -2331,49 +2342,76 @@ public class NEUEventListener {
GuiProfileViewer.PetLevel petlevel = null;
- //This is in the pets menu
- if (xpBarExists) {
- PetInfoOverlay.Pet pet = PetInfoOverlay.getPetFromStack(event.itemStack.getDisplayName(), NotEnoughUpdates.INSTANCE.manager.getLoreFromNBT(event.itemStack.getTagCompound()));
- if(pet == null){
- return;
+ //this is the item itself
+ NBTTagCompound tag = event.itemStack.getTagCompound();
+ if (tag.hasKey("ExtraAttributes")) {
+ if (tag.getCompoundTag("ExtraAttributes").hasKey("petInfo")) {
+ JsonObject petInfo = NotEnoughUpdates.INSTANCE.manager.gson.fromJson(
+ tag.getCompoundTag("ExtraAttributes").getString("petInfo"), JsonObject.class);
+ if (petInfo.has("exp") && petInfo.get("exp").isJsonPrimitive()) {
+ JsonPrimitive exp = petInfo.getAsJsonPrimitive("exp");
+ int rarityOffset = Constants.PETS.get("pet_rarity_offset").getAsJsonObject().get(
+ Utils.getRarityFromInt(Utils.checkItemTypePet(event.toolTip))).getAsInt();
+ petlevel = GuiProfileViewer.getPetLevel(Constants.PETS.get("pet_levels").getAsJsonArray(), rarityOffset, exp.getAsLong());
+ }
}
- Matcher matcher = xpLevelPattern.matcher(event.toolTip.get(event.toolTip.size() - 3));
- if(matcher.matches()) {
- event.toolTip.set(event.toolTip.size() - 3, matcher.group(1));
+ }
+
+
+
+ if (petlevel != null) {
+ tooltipText.add("");
+ if(petlevel.totalXp > petlevel.maxXP) {
+ tooltipText.add(EnumChatFormatting.AQUA + "" + EnumChatFormatting.BOLD +"MAX LEVEL");
+ } else {
+ tooltipText.add(EnumChatFormatting.GRAY+"Progress to Level "+(int)Math.floor(petlevel.level+1)+": "+EnumChatFormatting.YELLOW+Utils.round(petlevel.levelPercentage*100, 1)+"%");
+ int levelpercentage = Math.round(petlevel.levelPercentage*20);
+ tooltipText.add(EnumChatFormatting.DARK_GREEN+String.join("", Collections.nCopies(levelpercentage, "-"))+EnumChatFormatting.WHITE+String.join("", Collections.nCopies(20-levelpercentage, "-")));
+ tooltipText.add(EnumChatFormatting.YELLOW + "" + myFormatter.format(petlevel.levelXp) + "/" + myFormatter.format(petlevel.currentLevelRequirement) + " EXP");
}
- petlevel = pet.petLevel;
- } else {
- //this is the item itself
- NBTTagCompound tag = event.itemStack.getTagCompound();
- if (tag.hasKey("ExtraAttributes")) {
- if (tag.getCompoundTag("ExtraAttributes").hasKey("petInfo")) {
- JsonObject petInfo = NotEnoughUpdates.INSTANCE.manager.gson.fromJson(
- tag.getCompoundTag("ExtraAttributes").getString("petInfo"), JsonObject.class);
- if (petInfo.has("exp") && petInfo.get("exp").isJsonPrimitive()) {
- JsonPrimitive exp = petInfo.getAsJsonPrimitive("exp");
- int rarityOffset = Constants.PETS.get("pet_rarity_offset").getAsJsonObject().get(
- Utils.getRarityFromInt(Utils.checkItemTypePet(event.toolTip))).getAsInt();
- petlevel = GuiProfileViewer.getPetLevel(Constants.PETS.get("pet_levels").getAsJsonArray(), rarityOffset, exp.getAsLong());
- }
- }
+ }
+ }
+ }
+ }
+ return tooltipText;
+ }
+
+
+ private void petToolTipXPExtendPetMenu(ItemTooltipEvent event) {
+
+ if (NotEnoughUpdates.INSTANCE.config.tooltipTweaks.petExtendExp) {
+ //7 is just a random number i chose, prob no pets with less lines than 7
+ if (event.toolTip.size() > 7) {
+ if (Utils.cleanColour(event.toolTip.get(1)).matches("((Farming)|(Combat)|(Fishing)|(Mining)|(Foraging)|(Enchanting)|(Alchemy)) ((Mount)|(Pet)).*")) {
+ GuiProfileViewer.PetLevel petlevel = null;
+
+ PetInfoOverlay.Pet pet = PetInfoOverlay.getPetFromStack(event.itemStack.getDisplayName(), NotEnoughUpdates.INSTANCE.manager.getLoreFromNBT(event.itemStack.getTagCompound()));
+ if (pet == null) {
+ return;
+ }
+ petlevel = pet.petLevel;
+
+ boolean maxLevel = false;
+ int xpLine = -1;
+ for (int i = event.toolTip.size() - 1; i >= 0; i--) {
+ Matcher matcher = xpLevelPattern.matcher(event.toolTip.get(i));
+ if (matcher.matches()) {
+ xpLine = i;
+ event.toolTip.set(xpLine, matcher.group(1));
+ break;
+ } else if (event.toolTip.get(i).matches("MAX LEVEL")) {
+ xpLine = i;
+ maxLevel = true;
}
}
- if (petlevel == null) {
+ if (petlevel == null||xpLine==-1) {
return;
}
- if(petlevel.totalXp > petlevel.maxXP && !xpBarExists) {
- event.toolTip.add(event.toolTip.size() - 2, EnumChatFormatting.AQUA + "" + EnumChatFormatting.BOLD +"MAX LEVEL");
- } else {
- if(!xpBarExists){
- int percentage = (int)Math.round(petlevel.levelPercentage*20);
- String bar = EnumChatFormatting.DARK_GREEN +String.join("", Collections.nCopies(percentage, "-"))+EnumChatFormatting.WHITE+String.join("", Collections.nCopies(20-percentage, "-"));
- event.toolTip.add(event.toolTip.size() - 2, bar);
- }
- if(!xpBarExists || (xpBarExists && !Utils.cleanColour(event.toolTip.get(event.toolTip.size() - 3)).matches("MAX LEVEL"))) {
- event.toolTip.add(event.toolTip.size() - 2, EnumChatFormatting.YELLOW + "" + myFormatter.format(petlevel.levelXp) + "/" + myFormatter.format(petlevel.currentLevelRequirement) + " EXP");
- }
+
+ if (!maxLevel) {
+ event.toolTip.add(event.toolTip.size() - 2, EnumChatFormatting.YELLOW + "" + myFormatter.format(petlevel.levelXp) + "/" + myFormatter.format(petlevel.currentLevelRequirement) + " EXP");
}
}
}
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 8f373460..3e84261c 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java
@@ -469,7 +469,7 @@ public class Utils {
return str.substring(0, 1).toUpperCase() + str.substring(1).toLowerCase();
}
- private static String[] rarityArr = new String[] {
+ public static String[] rarityArr = new String[] {
"COMMON", "UNCOMMON", "RARE", "EPIC", "LEGENDARY", "MYTHIC", "SPECIAL", "VERY SPECIAL",
};
@@ -547,6 +547,11 @@ public class Utils {
return -1;
}
+ public static float round (float value, int precision) {
+ int scale = (int) Math.pow(10, precision);
+ return (float) Math.round(value * scale) / scale;
+ }
+
public static void playPressSound() {