use of net.silentchaos512.utils.Color in project Silent-Gear by SilentChaos512.
the class GearClientHelper method addStatsInfo.
public static void addStatsInfo(ItemStack stack, List<Component> tooltip, GearTooltipFlag flag, ICoreItem item) {
if (KeyTracker.isDisplayStatsDown() && flag.showStats) {
tooltip.add(TextUtil.withColor(misc("tooltip.stats"), Color.GOLD));
tooltip.add(TextUtil.withColor(misc("tier", GearData.getTier(stack)), Color.DEEPSKYBLUE));
// Display only stats relevant to the item class
Collection<ItemStat> relevantStats = item.getRelevantStats(stack);
Collection<ItemStat> displayStats = flag.isAdvanced() && SilentGear.isDevBuild() ? ItemStats.allStatsOrdered() : relevantStats;
TextListBuilder builder = new TextListBuilder();
for (ItemStat stat : displayStats) {
if (stat == ItemStats.ENCHANTABILITY && !Config.Common.allowEnchanting.get()) {
// Enchanting not allowed, so hide the stat
continue;
}
float statValue = GearData.getStat(stack, stat);
StatInstance inst = StatInstance.of(statValue, StatInstance.Operation.AVG, StatInstance.DEFAULT_KEY);
Color nameColor = relevantStats.contains(stat) ? stat.getNameColor() : TooltipHandler.MC_DARK_GRAY;
Component textName = TextUtil.withColor(stat.getDisplayName(), nameColor);
MutableComponent textStat = inst.getFormattedText(stat, stat.isDisplayAsInt() ? 0 : 2, false);
// TODO: The stats should probably handle this instead
if (stat == ItemStats.DURABILITY) {
int durabilityLeft = stack.getMaxDamage() - stack.getDamageValue();
int durabilityMax = stack.getMaxDamage();
textStat = statText("durabilityFormat", durabilityLeft, durabilityMax);
} else if (stat == ItemStats.HARVEST_LEVEL) {
textStat = TooltipHandler.harvestLevelWithHint(textStat, statValue);
}
builder.add(statText("displayFormat", textName, textStat));
}
tooltip.addAll(builder.build());
} else if (flag.showStats) {
tooltip.add(TextUtil.withColor(TextUtil.misc("tooltip.stats"), Color.GOLD).append(new TextComponent(" ").append(TextUtil.withColor(TextUtil.keyBinding(KeyTracker.DISPLAY_STATS), ChatFormatting.GRAY))));
}
}
use of net.silentchaos512.utils.Color in project Silent-Gear by SilentChaos512.
the class TooltipHandler method getSubStatTooltipLine.
private static Optional<MutableComponent> getSubStatTooltipLine(ItemTooltipEvent event, PartType partType, ItemStat stat, GearType gearType, Collection<StatInstance> modifiers) {
if (!modifiers.isEmpty()) {
StatInstance inst = stat.computeForDisplay(0, gearType, modifiers);
if (inst.shouldList(partType, stat, event.getFlags().isAdvanced())) {
boolean isZero = inst.getValue() == 0;
Color color = isZero ? MC_DARK_GRAY : Color.WHITE;
MutableComponent nameStr = TextUtil.withColor(gearType.getDisplayName().copy(), color);
int decimalPlaces = stat.isDisplayAsInt() && inst.getOp() != StatInstance.Operation.MUL1 && inst.getOp() != StatInstance.Operation.MUL2 ? 0 : 2;
MutableComponent statListText = TextUtil.withColor(StatModifierMap.formatText(modifiers, stat, decimalPlaces), color);
// Harvest level hints
MutableComponent textWithAdditions = stat == ItemStats.HARVEST_LEVEL && modifiers.size() == 1 ? harvestLevelWithHint(statListText, inst.getValue()) : statListText;
return Optional.of(new TranslatableComponent("stat.silentgear.displayFormat", nameStr, textWithAdditions));
}
}
return Optional.empty();
}
Aggregations