Search in sources :

Example 46 with Color

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))));
    }
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) MutableComponent(net.minecraft.network.chat.MutableComponent) Color(net.silentchaos512.utils.Color) StatInstance(net.silentchaos512.gear.api.stats.StatInstance) MutableComponent(net.minecraft.network.chat.MutableComponent) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) Component(net.minecraft.network.chat.Component) TextComponent(net.minecraft.network.chat.TextComponent) ItemStat(net.silentchaos512.gear.api.stats.ItemStat)

Example 47 with Color

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();
}
Also used : MutableComponent(net.minecraft.network.chat.MutableComponent) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) Color(net.silentchaos512.utils.Color) StatInstance(net.silentchaos512.gear.api.stats.StatInstance)

Aggregations

Color (net.silentchaos512.lib.util.Color)12 Color (net.silentchaos512.utils.Color)9 LocalizationHelper (net.silentchaos512.lib.util.LocalizationHelper)8 EnumMaterialGrade (net.silentchaos512.gems.api.lib.EnumMaterialGrade)7 TextComponent (net.minecraft.network.chat.TextComponent)6 TextFormatting (net.minecraft.util.text.TextFormatting)6 MaterialLayer (net.silentchaos512.gear.api.material.MaterialLayer)6 ToolPart (net.silentchaos512.gems.api.tool.part.ToolPart)6 MutableComponent (net.minecraft.network.chat.MutableComponent)4 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)4 Random (java.util.Random)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 Item (net.minecraft.item.Item)3 IMaterialDisplay (net.silentchaos512.gear.api.material.IMaterialDisplay)3 IMaterialInstance (net.silentchaos512.gear.api.material.IMaterialInstance)3 StatInstance (net.silentchaos512.gear.api.stats.StatInstance)3 ItemGemBow (net.silentchaos512.gems.item.tool.ItemGemBow)3 UUID (java.util.UUID)2 Minecraft (net.minecraft.client.Minecraft)2 FontRenderer (net.minecraft.client.gui.FontRenderer)2