diff options
author | Aaron <51387595+AzureAaron@users.noreply.github.com> | 2024-03-29 21:44:37 -0400 |
---|---|---|
committer | Aaron <51387595+AzureAaron@users.noreply.github.com> | 2024-03-29 21:44:53 -0400 |
commit | fad85d138db8761ca2a3edfe08520b32e08ae3dc (patch) | |
tree | 7daa36546669a33a4133723b9eb7669af7043dfa /src/main/java | |
parent | b21515cfdcd6a4a14cc256131d5ae6bb6666792d (diff) | |
download | Skyblocker-fad85d138db8761ca2a3edfe08520b32e08ae3dc.tar.gz Skyblocker-fad85d138db8761ca2a3edfe08520b32e08ae3dc.tar.bz2 Skyblocker-fad85d138db8761ca2a3edfe08520b32e08ae3dc.zip |
Enhance the accessories helper
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/AccessoriesHelper.java | 36 | ||||
-rw-r--r-- | src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/ItemTooltip.java | 13 |
2 files changed, 27 insertions, 22 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/AccessoriesHelper.java b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/AccessoriesHelper.java index b5291af6..a3fc40d5 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/AccessoriesHelper.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/AccessoriesHelper.java @@ -30,6 +30,7 @@ import com.mojang.util.UndashedUuid; import de.hysky.skyblocker.SkyblockerMod; import de.hysky.skyblocker.utils.ItemUtils; import de.hysky.skyblocker.utils.Utils; +import it.unimi.dsi.fastutil.Pair; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import it.unimi.dsi.fastutil.objects.ObjectArrayList; @@ -60,7 +61,7 @@ public class AccessoriesHelper { ScreenEvents.BEFORE_INIT.register((_client, screen, _scaledWidth, _scaledHeight) -> { if (Utils.isOnSkyblock() && TooltipInfoType.ACCESSORIES.isTooltipEnabled() && !Utils.getProfileId().isEmpty() && screen instanceof GenericContainerScreen genericContainerScreen) { if (ACCESSORY_BAG_TITLE.matcher(genericContainerScreen.getTitle().getString()).matches()) { - ScreenEvents.afterRender(screen).register((_screen, _context, _mouseX, _mouseY, _delta) -> { + ScreenEvents.afterTick(screen).register(_screen -> { GenericContainerScreenHandler handler = genericContainerScreen.getScreenHandler(); collectAccessories(handler.slots.subList(0, handler.getRows() * 9)); @@ -109,8 +110,8 @@ public class AccessoriesHelper { profileData.accessoryIds().addAll(accessoryIds); } - static AccessoryReport calculateReport4Accessory(String accessoryId) { - if (!ACCESSORY_DATA.containsKey(accessoryId) || Utils.getProfileId().isEmpty()) return AccessoryReport.INELIGIBLE; + static Pair<AccessoryReport, String> calculateReport4Accessory(String accessoryId) { + if (!ACCESSORY_DATA.containsKey(accessoryId) || Utils.getProfileId().isEmpty()) return Pair.of(AccessoryReport.INELIGIBLE, null); Accessory accessory = ACCESSORY_DATA.get(accessoryId); String uuid = UndashedUuid.toString(MinecraftClient.getInstance().getSession().getUuidOrNull()); @@ -120,7 +121,7 @@ public class AccessoriesHelper { .collect(Collectors.toSet()); //If the player has this accessory and it doesn't belong to a family - if (collectedAccessories.contains(accessory) && accessory.family().isEmpty()) return AccessoryReport.HAS_HIGHEST_TIER; + if (collectedAccessories.contains(accessory) && accessory.family().isEmpty()) return Pair.of(AccessoryReport.HAS_HIGHEST_TIER, null); Predicate<Accessory> HAS_SAME_FAMILY = accessory::hasSameFamily; Set<Accessory> collectedAccessoriesInTheSameFamily = collectedAccessories.stream() @@ -129,7 +130,7 @@ public class AccessoriesHelper { .collect(Collectors.toSet()); //If the player doesn't have any collected accessories with same family - if (collectedAccessoriesInTheSameFamily.isEmpty()) return AccessoryReport.MISSING; + if (collectedAccessoriesInTheSameFamily.isEmpty()) return Pair.of(AccessoryReport.MISSING, null); Set<Accessory> accessoriesInTheSameFamily = ACCESSORY_DATA.values().stream() .filter(HAS_FAMILY) @@ -142,12 +143,12 @@ public class AccessoriesHelper { .max(Comparator.comparingInt(ACCESSORY_TIER)); if (highestTierOfFamily.isPresent()) { - Accessory highestTier = highestTierOfFamily.orElseThrow(); + Accessory highestTier = highestTierOfFamily.get(); - if (collectedAccessoriesInTheSameFamily.contains(highestTier)) return AccessoryReport.HAS_HIGHEST_TIER; + if (collectedAccessoriesInTheSameFamily.contains(highestTier)) return Pair.of(AccessoryReport.HAS_HIGHEST_TIER, null); //For when the highest tier is tied - if (highestTier.hasSameFamily(accessory) && collectedAccessoriesInTheSameFamily.stream().allMatch(ca -> ca.tier() == highestTier.tier())) return AccessoryReport.HAS_HIGHEST_TIER; + if (highestTier.hasSameFamily(accessory) && collectedAccessoriesInTheSameFamily.stream().allMatch(ca -> ca.tier() == highestTier.tier())) return Pair.of(AccessoryReport.HAS_HIGHEST_TIER, null); } //If this accessory is a higher tier than all of other collected accessories in the same family @@ -155,19 +156,21 @@ public class AccessoriesHelper { .mapToInt(ACCESSORY_TIER) .max(); - if (highestTierOfAllCollectedInFamily.isPresent() && accessory.tier() > highestTierOfAllCollectedInFamily.orElseThrow()) return AccessoryReport.IS_GREATER_TIER; + int maxTierInFamily = highestTierOfFamily.orElse(Accessory.EMPTY).tier(); + + if (highestTierOfAllCollectedInFamily.isPresent() && accessory.tier() > highestTierOfAllCollectedInFamily.getAsInt()) return Pair.of(AccessoryReport.IS_GREATER_TIER, String.format("(%d/%d)", accessory.tier(), maxTierInFamily)); //If this accessory is a lower tier than one already obtained from same family - if (highestTierOfAllCollectedInFamily.isPresent() && accessory.tier() < highestTierOfAllCollectedInFamily.orElseThrow()) return AccessoryReport.OWNS_BETTER_TIER; + if (highestTierOfAllCollectedInFamily.isPresent() && accessory.tier() < highestTierOfAllCollectedInFamily.getAsInt()) return Pair.of(AccessoryReport.OWNS_BETTER_TIER, String.format("(%d/%d)", highestTierOfAllCollectedInFamily.orElse(0), maxTierInFamily)); //If there is an accessory in the same family that has a higher tier //Take the accessories in the same family, then check if there is an accessory whose tier is greater than {@code accessory} boolean hasGreaterTierInFamily = accessoriesInTheSameFamily.stream() .anyMatch(ca -> ca.tier() > accessory.tier()); - if (hasGreaterTierInFamily) return AccessoryReport.HAS_GREATER_TIER; + if (hasGreaterTierInFamily) return Pair.of(AccessoryReport.HAS_GREATER_TIER, String.format("(%d/%d)", highestTierOfAllCollectedInFamily.orElse(0), maxTierInFamily)); - return AccessoryReport.MISSING; + return Pair.of(AccessoryReport.MISSING, null); } static void refreshData(JsonObject data) { @@ -200,7 +203,7 @@ public class AccessoriesHelper { /** * @author AzureAaron - * @implSpec <a href="https://github.com/AzureAaron/aaron-mod/blob/1.20/src/main/java/net/azureaaron/mod/commands/MagicalPowerCommand.java#L393">Aaron's Mod</a> + * @implSpec <a href="https://github.com/AzureAaron/aaron-mod/blob/1.20/src/main/java/net/azureaaron/mod/commands/MagicalPowerCommand.java#L475">Aaron's Mod</a> */ private record Accessory(String id, Optional<String> family, int tier) { private static final Codec<Accessory> CODEC = RecordCodecBuilder.create(instance -> instance.group( @@ -209,6 +212,7 @@ public class AccessoriesHelper { Codec.INT.optionalFieldOf("tier", 0).forGetter(Accessory::tier)) .apply(instance, Accessory::new)); private static final Codec<Map<String, Accessory>> MAP_CODEC = Codec.unboundedMap(Codec.STRING, CODEC); + private static final Accessory EMPTY = new Accessory("", Optional.empty(), 0); private boolean hasFamily() { return family.isPresent(); @@ -221,9 +225,9 @@ public class AccessoriesHelper { enum AccessoryReport { HAS_HIGHEST_TIER, //You've collected the highest tier - Collected - IS_GREATER_TIER, //This accessory is an upgrade from the one in the same family that you already have - Upgrade - HAS_GREATER_TIER, //This accessory has a higher tier upgrade - Upgradable - OWNS_BETTER_TIER, //You've collected an accessory in this family with a higher tier - Downgrade + IS_GREATER_TIER, //This accessory is an upgrade from the one in the same family that you already have - Upgrade -- Shows you what tier this accessory is in it's family + HAS_GREATER_TIER, //This accessory has a higher tier upgrade - Upgradable -- Shows you the highest tier accessory you've collected in that family + OWNS_BETTER_TIER, //You've collected an accessory in this family with a higher tier - Downgrade -- Shows you the highest tier accessory you've collected in that family MISSING, //You don't have any accessories in this family - Missing INELIGIBLE; } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/ItemTooltip.java b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/ItemTooltip.java index 8a11b9bd..637aea22 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/ItemTooltip.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/ItemTooltip.java @@ -10,6 +10,7 @@ import de.hysky.skyblocker.utils.Constants; import de.hysky.skyblocker.utils.ItemUtils; import de.hysky.skyblocker.utils.Utils; import de.hysky.skyblocker.utils.scheduler.Scheduler; +import it.unimi.dsi.fastutil.Pair; import net.minecraft.client.MinecraftClient; import net.minecraft.client.item.TooltipContext; import net.minecraft.item.DyeableItem; @@ -241,16 +242,16 @@ public class ItemTooltip { } if (TooltipInfoType.ACCESSORIES.isTooltipEnabledAndHasOrNullWarning(internalID)) { - AccessoryReport report = AccessoriesHelper.calculateReport4Accessory(internalID); + Pair<AccessoryReport, String> report = AccessoriesHelper.calculateReport4Accessory(internalID); - if (report != AccessoryReport.INELIGIBLE) { + if (report.left() != AccessoryReport.INELIGIBLE) { MutableText title = Text.literal(String.format("%-19s", "Accessory: ")).withColor(0xf57542); - Text stateText = switch (report) { + Text stateText = switch (report.left()) { case HAS_HIGHEST_TIER -> Text.literal("✔ Collected").formatted(Formatting.GREEN); - case IS_GREATER_TIER -> Text.literal("✦ Upgrade").withColor(0x218bff); - case HAS_GREATER_TIER -> Text.literal("↑ Upgradable").withColor(0xf8d048); - case OWNS_BETTER_TIER -> Text.literal("↓ Downgrade").formatted(Formatting.GRAY); + case IS_GREATER_TIER -> Text.literal("✦ Upgrade ").withColor(0x218bff).append(Text.literal(report.right()).withColor(0xf8f8ff)); + case HAS_GREATER_TIER -> Text.literal("↑ Upgradable ").withColor(0xf8d048).append(Text.literal(report.right()).withColor(0xf8f8ff)); + case OWNS_BETTER_TIER -> Text.literal("↓ Downgrade ").formatted(Formatting.GRAY).append(Text.literal(report.right()).withColor(0xf8f8ff)); case MISSING -> Text.literal("✖ Missing").formatted(Formatting.RED); //Should never be the case |