diff options
| author | UpFault <76474308+UpFault@users.noreply.github.com> | 2024-07-18 03:07:33 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-18 16:07:33 +0800 |
| commit | cceaa38e7c1783d0446a50dbb09e42b8287e38d1 (patch) | |
| tree | 5a4f94c94a8822bf262e5b465c384dd11686aac2 /src/main/java/de/hysky/skyblocker/skyblock/chocolatefactory | |
| parent | 50b7a167253683d1526ac16a46e36adf1f5300d5 (diff) | |
| download | Skyblocker-cceaa38e7c1783d0446a50dbb09e42b8287e38d1.tar.gz Skyblocker-cceaa38e7c1783d0446a50dbb09e42b8287e38d1.tar.bz2 Skyblocker-cceaa38e7c1783d0446a50dbb09e42b8287e38d1.zip | |
EssenceShopPrice feature (#737)
Added EssenceShopPrice Feature, moved concatenate methods from ChocolateFactorySolver to Utils as they most likely will be used many times
Co-authored-by: Rime <81419447+Emirlol@users.noreply.github.com>
Co-authored-by: Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com>
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/skyblock/chocolatefactory')
| -rw-r--r-- | src/main/java/de/hysky/skyblocker/skyblock/chocolatefactory/ChocolateFactorySolver.java | 38 |
1 files changed, 9 insertions, 29 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/chocolatefactory/ChocolateFactorySolver.java b/src/main/java/de/hysky/skyblocker/skyblock/chocolatefactory/ChocolateFactorySolver.java index db81382c..cd4db727 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/chocolatefactory/ChocolateFactorySolver.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/chocolatefactory/ChocolateFactorySolver.java @@ -93,7 +93,7 @@ public class ChocolateFactorySolver extends ContainerSolver { private static void onTick(MinecraftClient client) { if (ding != StraySound.NONE) { - dingTick = (++dingTick) % (ding == StraySound.NORMAL ? 5 : 3); + dingTick = (++dingTick) % (ding == StraySound.NORMAL ? 5 : 3); if (dingTick == 0) { client.getSoundManager().play(PositionedSoundInstance.master(ding == StraySound.NORMAL ? SoundEvents.BLOCK_NOTE_BLOCK_PLING.value() : SoundEvents.BLOCK_NOTE_BLOCK_HARP.value(), 1.f, 1.f)); } @@ -150,14 +150,14 @@ public class ChocolateFactorySolver extends ContainerSolver { RegexUtils.getLongFromMatcher(CHOCOLATE_PATTERN.matcher(slots.get(CHOCOLATE_SLOT).getName().getString())).ifPresent(l -> totalChocolate = l); //Cps item (cocoa bean) is in slot 45 - String cpsItemLore = getConcatenatedLore(slots.get(CPS_SLOT)); + String cpsItemLore = ItemUtils.getConcatenatedLore(slots.get(CPS_SLOT)); Matcher cpsMatcher = CPS_PATTERN.matcher(cpsItemLore); RegexUtils.getDoubleFromMatcher(cpsMatcher).ifPresent(d -> totalCps = d); Matcher multiplierMatcher = TOTAL_MULTIPLIER_PATTERN.matcher(cpsItemLore); RegexUtils.getDoubleFromMatcher(multiplierMatcher, cpsMatcher.hasMatch() ? cpsMatcher.end() : 0).ifPresent(d -> totalCpsMultiplier = d); //Prestige item is in slot 28 - String prestigeLore = getConcatenatedLore(slots.get(PRESTIGE_SLOT)); + String prestigeLore = ItemUtils.getConcatenatedLore(slots.get(PRESTIGE_SLOT)); Matcher prestigeMatcher = PRESTIGE_REQUIREMENT_PATTERN.matcher(prestigeLore); OptionalLong currentChocolate = RegexUtils.getLongFromMatcher(prestigeMatcher); if (currentChocolate.isPresent()) { @@ -178,7 +178,7 @@ public class ChocolateFactorySolver extends ContainerSolver { //Time Tower is in slot 39 isTimeTowerMaxed = StringUtils.substringAfterLast(slots.get(TIME_TOWER_SLOT).getName().getString(), ' ').equals("XV"); - String timeTowerLore = getConcatenatedLore(slots.get(TIME_TOWER_SLOT)); + String timeTowerLore = ItemUtils.getConcatenatedLore(slots.get(TIME_TOWER_SLOT)); Matcher timeTowerMultiplierMatcher = TIME_TOWER_MULTIPLIER_PATTERN.matcher(timeTowerLore); RegexUtils.getDoubleFromMatcher(timeTowerMultiplierMatcher).ifPresent(d -> timeTowerMultiplier = d); Matcher timeTowerStatusMatcher = TIME_TOWER_STATUS_PATTERN.matcher(timeTowerLore); @@ -190,29 +190,9 @@ public class ChocolateFactorySolver extends ContainerSolver { cpsIncreaseFactors.sort(Comparator.comparingDouble(rabbit -> rabbit.cost() / rabbit.cpsIncrease())); //Ascending order, lower = better } - /** - * Utility method. - */ - private static String getConcatenatedLore(ItemStack item) { - return concatenateLore(ItemUtils.getLore(item)); - } - - /** - * Concatenates the lore of an item into one string. - * This is useful in case some pattern we're looking for is split into multiple lines, which would make it harder to regex. - */ - private static String concatenateLore(List<Text> lore) { - StringBuilder stringBuilder = new StringBuilder(); - for (int i = 0; i < lore.size(); i++) { - stringBuilder.append(lore.get(i).getString()); - if (i != lore.size() - 1) stringBuilder.append(" "); - } - return stringBuilder.toString(); - } - private static Optional<Rabbit> getCoach(ItemStack coachItem) { if (!coachItem.isOf(Items.PLAYER_HEAD)) return Optional.empty(); - String coachLore = getConcatenatedLore(coachItem); + String coachLore = ItemUtils.getConcatenatedLore(coachItem); if (totalCps < 0 || totalCpsMultiplier < 0) return Optional.empty(); //We need these 2 to calculate the increase in cps. @@ -234,7 +214,7 @@ public class ChocolateFactorySolver extends ContainerSolver { } private static Optional<Rabbit> getRabbit(ItemStack item, int slot) { - String lore = getConcatenatedLore(item); + String lore = ItemUtils.getConcatenatedLore(item); Matcher cpsMatcher = CPS_INCREASE_PATTERN.matcher(lore); OptionalInt currentCps = RegexUtils.getIntFromMatcher(cpsMatcher); if (currentCps.isEmpty()) return Optional.empty(); @@ -247,7 +227,7 @@ public class ChocolateFactorySolver extends ContainerSolver { Matcher costMatcher = COST_PATTERN.matcher(lore); OptionalLong cost = RegexUtils.getLongFromMatcher(costMatcher, cpsMatcher.hasMatch() ? cpsMatcher.end() : 0); //Cost comes after the cps line if (cost.isEmpty()) return Optional.empty(); - return Optional.of(new Rabbit((nextCps.getAsInt() - currentCps.getAsInt())*(totalCpsMultiplier < 0 ? 1 : totalCpsMultiplier), cost.getAsLong(), slot)); + return Optional.of(new Rabbit((nextCps.getAsInt() - currentCps.getAsInt()) * (totalCpsMultiplier < 0 ? 1 : totalCpsMultiplier), cost.getAsLong(), slot)); } private static Optional<ColorHighlight> getPrestigeHighlight() { @@ -271,7 +251,7 @@ public class ChocolateFactorySolver extends ContainerSolver { return highlights; } - private record Rabbit(double cpsIncrease, long cost, int slot) { } + private record Rabbit(double cpsIncrease, long cost, int slot) {} private enum StraySound { NONE, @@ -293,7 +273,7 @@ public class ChocolateFactorySolver extends ContainerSolver { //It should be set to true if there's any information added, false otherwise. boolean shouldAddLine = false; - String lore = concatenateLore(lines); + String lore = ItemUtils.concatenateLore(lines); Matcher costMatcher = COST_PATTERN.matcher(lore); OptionalLong cost = RegexUtils.getLongFromMatcher(costMatcher); //Available on all items with a chocolate cost |
