aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java
diff options
context:
space:
mode:
authorDoKM <mcazzyman@gmail.com>2021-08-23 15:49:31 +0200
committerDoKM <mcazzyman@gmail.com>2021-08-23 15:49:31 +0200
commitec182b6c75b00dc8fc265ae48ae3eef4d6e58e33 (patch)
tree254e495bacb68c7fc79318ceec04fba829b6a61c /src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java
parent97b19369c6cc26705c71e0c7697a1133f5246681 (diff)
parentc8a7dfb175a667ba2a3aef5bfa1cafeb5df9ae8d (diff)
downloadnotenoughupdates-ec182b6c75b00dc8fc265ae48ae3eef4d6e58e33.tar.gz
notenoughupdates-ec182b6c75b00dc8fc265ae48ae3eef4d6e58e33.tar.bz2
notenoughupdates-ec182b6c75b00dc8fc265ae48ae3eef4d6e58e33.zip
Merge branch 'BetterPetXP'
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java88
1 files changed, 73 insertions, 15 deletions
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 5ca9b316..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,26 +469,77 @@ 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",
};
+
+ public static String getRarityFromInt(int rarity){
+ if(rarity < 0|| rarity >= rarityArr.length){ return rarityArr[0]; }
+ return rarityArr[rarity];
+ }
+
+ public static int checkItemTypePet(List<String> lore){
+ for(int i=lore.size()-1; i>=0; i--){
+ String line = Utils.cleanColour(lore.get(i));
+ for (int i1 = 0; i1 < rarityArr.length; i1++) {
+ if(line.equals(rarityArr[i1])){
+ return i1;
+ }
+ }
+ }
+ return -1;
+ }
+
public static int checkItemType(JsonArray lore, boolean contains, String... typeMatches) {
for(int i=lore.size()-1; i>=0; i--) {
String line = lore.get(i).getAsString();
- for(String rarity : rarityArr) {
- for(int j=0; j<typeMatches.length; j++) {
- if(contains) {
- if(line.trim().contains(rarity + " " + typeMatches[j])) {
- return j;
- } else if(line.trim().contains(rarity + " DUNGEON " + typeMatches[j])) {
- return j;
- }
- } else {
- if(line.trim().endsWith(rarity + " " + typeMatches[j])) {
- return j;
- } else if(line.trim().endsWith(rarity + " DUNGEON " + typeMatches[j])) {
- return j;
- }
+
+ int returnType = checkItemType(line, contains, typeMatches);
+ if(returnType != -1){
+ return returnType;
+ }
+ }
+ return -1;
+ }
+
+ public static int checkItemType(String[] lore, boolean contains, String... typeMatches) {
+ for(int i=lore.length-1; i>=0; i--) {
+ String line = lore[i];
+
+ int returnType = checkItemType(line, contains, typeMatches);
+ if(returnType != -1){
+ return returnType;
+ }
+ }
+ return -1;
+ }
+
+ public static int checkItemType(List<String> lore, boolean contains, String... typeMatches) {
+ for(int i=lore.size()-1; i>=0; i--) {
+ String line = lore.get(i);
+
+ int returnType = checkItemType(line, contains, typeMatches);
+ if(returnType != -1){
+ return returnType;
+ }
+ }
+ return -1;
+ }
+
+ private static int checkItemType(String line, boolean contains, String... typeMatches) {
+ for (String rarity : rarityArr) {
+ for (int j = 0; j < typeMatches.length; j++) {
+ if (contains) {
+ if (line.trim().contains(rarity + " " + typeMatches[j])) {
+ return j;
+ } else if (line.trim().contains(rarity + " DUNGEON " + typeMatches[j])) {
+ return j;
+ }
+ } else {
+ if (line.trim().endsWith(rarity + " " + typeMatches[j])) {
+ return j;
+ } else if (line.trim().endsWith(rarity + " DUNGEON " + typeMatches[j])) {
+ return j;
}
}
}
@@ -496,6 +547,13 @@ 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() {
playSound(new ResourceLocation("gui.button.press"), true);
}