Skip to content

Commit

Permalink
Enhance the accessories helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron committed Mar 30, 2024
1 parent b21515c commit fad85d1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
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;
Expand Down Expand Up @@ -60,7 +61,7 @@ public static void init() {
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));
Expand Down Expand Up @@ -109,8 +110,8 @@ private static void collectAccessories(List<Slot> slots) {
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());
Expand All @@ -120,7 +121,7 @@ static AccessoryReport calculateReport4Accessory(String accessoryId) {
.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()
Expand All @@ -129,7 +130,7 @@ static AccessoryReport calculateReport4Accessory(String accessoryId) {
.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)
Expand All @@ -142,32 +143,34 @@ static AccessoryReport calculateReport4Accessory(String accessoryId) {
.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
OptionalInt highestTierOfAllCollectedInFamily = collectedAccessoriesInTheSameFamily.stream()
.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) {
Expand Down Expand Up @@ -200,7 +203,7 @@ private static ProfileAccessoryData createDefault() {

/**
* @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(
Expand All @@ -209,6 +212,7 @@ private record Accessory(String id, Optional<String> family, int tier) {
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();
Expand All @@ -221,9 +225,9 @@ private boolean hasSameFamily(Accessory other) {

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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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;
Expand Down Expand Up @@ -241,16 +242,16 @@ public static void getTooltip(ItemStack stack, TooltipContext context, List<Text
}

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
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/assets/skyblocker/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@
"text.autoconfig.skyblocker.option.general.itemTooltip.enableAccessoriesHelper": "Enable Accessories Helper",
"text.autoconfig.skyblocker.option.general.itemTooltip.enableAccessoriesHelper.@Tooltip[0]": "When hovering over an accessory you are informed about whether you already have it or not, and whether it's worse than what you have already collected or better. List of Statuses:",
"text.autoconfig.skyblocker.option.general.itemTooltip.enableAccessoriesHelper.@Tooltip[1]": "You have the highest tier accessory from that family.",
"text.autoconfig.skyblocker.option.general.itemTooltip.enableAccessoriesHelper.@Tooltip[2]": "This accessory is an upgrade from the one in the same family that you already have.",
"text.autoconfig.skyblocker.option.general.itemTooltip.enableAccessoriesHelper.@Tooltip[3]": "This accessory can be upgraded.",
"text.autoconfig.skyblocker.option.general.itemTooltip.enableAccessoriesHelper.@Tooltip[4]": "You already own an accessory in the same family that is better than this one.",
"text.autoconfig.skyblocker.option.general.itemTooltip.enableAccessoriesHelper.@Tooltip[2]": "This accessory is an upgrade from the one in the same family that you already have. Also shows you what tier this accessory is in it's family.",
"text.autoconfig.skyblocker.option.general.itemTooltip.enableAccessoriesHelper.@Tooltip[3]": "This accessory can be upgraded. Also tells you what tier of accessory you have in that family.",
"text.autoconfig.skyblocker.option.general.itemTooltip.enableAccessoriesHelper.@Tooltip[4]": "You already own an accessory in the same family that is better than this one. Also tells you what tier of accessory you have in that family.",
"text.autoconfig.skyblocker.option.general.itemTooltip.enableAccessoriesHelper.@Tooltip[5]": "You don't own any accessory from this family.",
"text.autoconfig.skyblocker.option.general.dungeonQuality": "Dungeon Quality",
"text.autoconfig.skyblocker.option.general.dungeonQuality.@Tooltip": "Displays quality and tier of dungeon drops from mobs.\n\n\nReminder:\nTier 1-3 dropped from F1-F3\nTier 4-7 dropped from F4-F7 or M1-M4\nTier 8-10 are dropped only from M5-M7",
Expand Down

0 comments on commit fad85d1

Please sign in to comment.