diff options
| author | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2021-08-24 15:24:41 +0200 |
|---|---|---|
| committer | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2021-08-24 15:24:41 +0200 |
| commit | 457d4cd1d409141ae991998238afa797eb1760e1 (patch) | |
| tree | 824979f39ef8d7fcd784561678b966e1c181e6dd /src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java | |
| parent | 10d64cd33c0c86be95952f94783950bfedd912ba (diff) | |
| parent | a48012a509a3733d908fc0a23ce07335ccb4493e (diff) | |
| download | notenoughupdates-457d4cd1d409141ae991998238afa797eb1760e1.tar.gz notenoughupdates-457d4cd1d409141ae991998238afa797eb1760e1.tar.bz2 notenoughupdates-457d4cd1d409141ae991998238afa797eb1760e1.zip | |
Merge remote-tracking branch 'dokm/master'
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.java | 88 |
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); } |
