diff options
-rw-r--r-- | gradle.properties | 2 | ||||
-rw-r--r-- | src/main/java/com/anthonyhilyard/iceberg/util/ItemColor.java | 17 |
2 files changed, 18 insertions, 1 deletions
diff --git a/gradle.properties b/gradle.properties index 09e0729..0c29540 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,6 +6,6 @@ org.gradle.daemon=false name=${rootProject.name} group=com.anthonyhilyard.${name.toLowerCase()} author=anthonyhilyard -version=1.0.33 +version=1.0.38 mcVersion=1.18.1 forgeVersion=39.0.9 diff --git a/src/main/java/com/anthonyhilyard/iceberg/util/ItemColor.java b/src/main/java/com/anthonyhilyard/iceberg/util/ItemColor.java index 6b614c5..d5bcbfa 100644 --- a/src/main/java/com/anthonyhilyard/iceberg/util/ItemColor.java +++ b/src/main/java/com/anthonyhilyard/iceberg/util/ItemColor.java @@ -1,11 +1,16 @@ package com.anthonyhilyard.iceberg.util; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.TooltipFlag; import net.minecraft.util.FormattedCharSink; import net.minecraft.network.chat.TextColor; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Style; + +import java.util.List; + import net.minecraft.ChatFormatting; +import net.minecraft.client.Minecraft; public class ItemColor { @@ -97,6 +102,18 @@ public class ItemColor result = colorCollector.getColor(); } + // If we haven't found a color or we're still using the rarity color, check the actual tooltip. + // This is slow, so it better get cached externally! + if (result == null || result.equals(item.getDisplayName().getStyle().getColor())) + { + Minecraft mc = Minecraft.getInstance(); + List<Component> lines = item.getTooltipLines(mc.player, TooltipFlag.Default.ADVANCED); + if (!lines.isEmpty()) + { + result = lines.get(0).getStyle().getColor(); + } + } + // Fallback to the default TextColor if we somehow haven't found a single valid TextColor. if (result == null) { |