diff options
author | Anthony Hilyard <anthony.hilyard@gmail.com> | 2022-01-13 15:12:20 -0800 |
---|---|---|
committer | Anthony Hilyard <anthony.hilyard@gmail.com> | 2022-01-13 15:12:20 -0800 |
commit | bd85cc8ebd856605b458555a967647987b09945e (patch) | |
tree | 99b1fca1c4793404b08c8347c653e568414996a7 /src | |
parent | 650b77cff32dd45585fb363c3daa6d21e8e601b9 (diff) | |
download | Iceberg-bd85cc8ebd856605b458555a967647987b09945e.tar.gz Iceberg-bd85cc8ebd856605b458555a967647987b09945e.tar.bz2 Iceberg-bd85cc8ebd856605b458555a967647987b09945e.zip |
Ported changes through 1.0.38.
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/com/anthonyhilyard/iceberg/util/ItemColor.java | 17 |
1 files changed, 17 insertions, 0 deletions
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) { |