diff options
author | Aaron <51387595+AzureAaron@users.noreply.github.com> | 2023-11-03 15:21:50 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-03 15:21:50 -0400 |
commit | bcec59766be7a211e09d9f65025c914d7ce9e55d (patch) | |
tree | b92a4e16dac7418f27e6e3f7b703ad5813e36f3c /src/main/java/de/hysky/skyblocker/skyblock/item/ItemRarityBackgrounds.java | |
parent | 5bb91104d3275283d7479f0b35c1b18be470d632 (diff) | |
parent | 1c2d6508bfaeafa116fe3720507aa03831123c4a (diff) | |
download | Skyblocker-bcec59766be7a211e09d9f65025c914d7ce9e55d.tar.gz Skyblocker-bcec59766be7a211e09d9f65025c914d7ce9e55d.tar.bz2 Skyblocker-bcec59766be7a211e09d9f65025c914d7ce9e55d.zip |
Merge pull request #396 from msg-programs/cleanup-2
More cleanup
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/skyblock/item/ItemRarityBackgrounds.java')
-rw-r--r-- | src/main/java/de/hysky/skyblocker/skyblock/item/ItemRarityBackgrounds.java | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/ItemRarityBackgrounds.java b/src/main/java/de/hysky/skyblocker/skyblock/item/ItemRarityBackgrounds.java index 9e1df2bb..da357738 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/ItemRarityBackgrounds.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/ItemRarityBackgrounds.java @@ -39,27 +39,27 @@ public class ItemRarityBackgrounds { Map.entry("COMMON", SkyblockItemRarity.COMMON) ); private static final Int2ReferenceOpenHashMap<SkyblockItemRarity> CACHE = new Int2ReferenceOpenHashMap<>(); - + public static void init() { //Clear the cache every 5 minutes, ints are very compact! Scheduler.INSTANCE.scheduleCyclic(CACHE::clear, 4800); - + //Clear cache after a screen where items can be upgraded in rarity closes ScreenEvents.BEFORE_INIT.register((client, screen, scaledWidth, scaledHeight) -> { String title = screen.getTitle().getString(); - + if (Utils.isOnSkyblock() && (title.equals("The Hex") || title.equals("Craft Item") || title.equals("Anvil") || title.equals("Reforge Anvil"))) { ScreenEvents.remove(screen).register(screen1 -> CACHE.clear()); } }); } - + public static void tryDraw(ItemStack stack, DrawContext context, int x, int y) { MinecraftClient client = MinecraftClient.getInstance(); - + if (client.player != null) { SkyblockItemRarity itemRarity = getItemRarity(stack, client.player); - + if (itemRarity != null) draw(context, x, y, itemRarity); } } @@ -73,30 +73,30 @@ public class ItemRarityBackgrounds { int hashCode = itemUuid.isEmpty() ? System.identityHashCode(stack) : itemUuid.hashCode(); if (CACHE.containsKey(hashCode)) return CACHE.get(hashCode); - + List<Text> tooltip = stack.getTooltip(player, TooltipContext.BASIC); String[] stringifiedTooltip = tooltip.stream().map(Text::getString).toArray(String[]::new); - + for (String rarityString : LORE_RARITIES.keySet()) { if (Arrays.stream(stringifiedTooltip).anyMatch(line -> line.contains(rarityString))) { SkyblockItemRarity rarity = LORE_RARITIES.get(rarityString); - + CACHE.put(hashCode, rarity); return rarity; } } - + CACHE.put(hashCode, null); return null; } - + private static void draw(DrawContext context, int x, int y, SkyblockItemRarity rarity) { //Enable blending to handle HUD translucency RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); context.drawSprite(x, y, 0, 16, 16, SPRITE.get(), rarity.r, rarity.g, rarity.b, SkyblockerConfigManager.get().general.itemInfoDisplay.itemRarityBackgroundsOpacity); - + RenderSystem.disableBlend(); } } |