aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/xmrvizzy/skyblocker
diff options
context:
space:
mode:
authorKevinthegreat <92656833+kevinthegreat1@users.noreply.github.com>2023-10-07 11:17:13 -0400
committerKevinthegreat <92656833+kevinthegreat1@users.noreply.github.com>2023-10-07 11:31:43 -0400
commit238ed9ac50ecd4be790b0f30d54e962177fbb8d5 (patch)
tree44d96cb9fa9dca3d79a023caaa91c3b73dbe8906 /src/main/java/me/xmrvizzy/skyblocker
parent05d86bf32ef2d46a695c376609d4633011de029a (diff)
downloadSkyblocker-238ed9ac50ecd4be790b0f30d54e962177fbb8d5.tar.gz
Skyblocker-238ed9ac50ecd4be790b0f30d54e962177fbb8d5.tar.bz2
Skyblocker-238ed9ac50ecd4be790b0f30d54e962177fbb8d5.zip
Refactor ItemRarityBackgrounds
Diffstat (limited to 'src/main/java/me/xmrvizzy/skyblocker')
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/item/ItemRarityBackgrounds.java27
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/item/SkyblockItemRarity.java7
2 files changed, 17 insertions, 17 deletions
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/ItemRarityBackgrounds.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/ItemRarityBackgrounds.java
index 87dac046..18a88539 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/ItemRarityBackgrounds.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/ItemRarityBackgrounds.java
@@ -26,7 +26,6 @@ import net.minecraft.util.Identifier;
public class ItemRarityBackgrounds {
private static final Identifier RARITY_BG_TEX = new Identifier(SkyblockerMod.NAMESPACE, "item_rarity_background");
private static final Supplier<Sprite> SPRITE = () -> MinecraftClient.getInstance().getGuiAtlasManager().getSprite(RARITY_BG_TEX);
- private static final String EMPTY = "";
private static final ImmutableMap<String, SkyblockItemRarity> LORE_RARITIES = ImmutableMap.ofEntries(
Map.entry("ADMIN", SkyblockItemRarity.ADMIN),
Map.entry("SPECIAL", SkyblockItemRarity.SPECIAL), //Very special is the same color so this will cover it
@@ -37,13 +36,13 @@ public class ItemRarityBackgrounds {
Map.entry("EPIC", SkyblockItemRarity.EPIC),
Map.entry("RARE", SkyblockItemRarity.RARE),
Map.entry("UNCOMMON", SkyblockItemRarity.UNCOMMON),
- Map.entry("COMMON", SkyblockItemRarity.COMMON));
-
+ 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);
+ 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) -> {
@@ -64,7 +63,7 @@ public class ItemRarityBackgrounds {
if (itemRarity != null) draw(context, x, y, itemRarity);
}
}
-
+
private static SkyblockItemRarity getItemRarity(ItemStack stack, ClientPlayerEntity player) {
if (stack == null || stack.isEmpty()) return null;
@@ -73,23 +72,23 @@ public class ItemRarityBackgrounds {
if (nbt != null && nbt.contains("ExtraAttributes")) {
NbtCompound extraAttributes = nbt.getCompound("ExtraAttributes");
- String itemUuid = extraAttributes.contains("uuid") ? extraAttributes.getString("uuid") : EMPTY;
+ String itemUuid = extraAttributes.getString("uuid");
- //If the item has a uuid, then use the hash code of the uuid otherwise use the identity hash code of the stack
- hashCode = (itemUuid != EMPTY) ? itemUuid.hashCode() : System.identityHashCode(stack);
+ //If the item has an uuid, then use the hash code of the uuid otherwise use the identity hash code of the stack
+ 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 rarity : LORE_RARITIES.keySet()) {
- if (Arrays.stream(stringifiedTooltip).anyMatch(line -> line.contains(rarity))) {
- SkyblockItemRarity foundRarity = LORE_RARITIES.get(rarity);
+ for (String rarityString : LORE_RARITIES.keySet()) {
+ if (Arrays.stream(stringifiedTooltip).anyMatch(line -> line.contains(rarityString))) {
+ SkyblockItemRarity rarity = LORE_RARITIES.get(rarityString);
- CACHE.put(hashCode, foundRarity);
- return LORE_RARITIES.get(rarity);
+ CACHE.put(hashCode, rarity);
+ return rarity;
}
}
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/SkyblockItemRarity.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/SkyblockItemRarity.java
index da722196..f7ff1fb9 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/SkyblockItemRarity.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/SkyblockItemRarity.java
@@ -17,10 +17,11 @@ public enum SkyblockItemRarity {
public final float r;
public final float g;
public final float b;
-
- private SkyblockItemRarity(Formatting formatting) {
+
+ SkyblockItemRarity(Formatting formatting) {
+ @SuppressWarnings("DataFlowIssue")
int rgb = formatting.getColorValue();
-
+
this.r = ((rgb >> 16) & 0xFF) / 255f;
this.g = ((rgb >> 8) & 0xFF) / 255f;
this.b = (rgb & 0xFF) / 255f;