Search in sources :

Example 6 with TextListBuilder

use of net.silentchaos512.gear.client.util.TextListBuilder 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 7 with TextListBuilder

use of net.silentchaos512.gear.client.util.TextListBuilder in project Silent-Gear by SilentChaos512.

the class GearClientHelper method tooltipListParts.

public static void tooltipListParts(ItemStack gear, List<Component> tooltip, Collection<PartData> parts, GearTooltipFlag flag) {
    TextListBuilder builder = new TextListBuilder();
    for (PartData part : parts) {
        if (part.get().isVisible()) {
            int partNameColor = Color.blend(part.getColor(gear), Color.VALUE_WHITE, 0.25f) & 0xFFFFFF;
            MutableComponent partNameText = TextUtil.withColor(part.getDisplayName(gear).copy(), partNameColor);
            builder.add(flag.isAdvanced() ? partNameText.append(TextUtil.misc("spaceBrackets", part.getType().getName()).withStyle(ChatFormatting.DARK_GRAY)) : partNameText);
            // List materials for compound parts
            if (part.get() instanceof CompoundPart) {
                builder.indent();
                for (IMaterialInstance material : CompoundPartItem.getMaterials(part.getItem())) {
                    int nameColor = material.getNameColor(part.getType(), GearType.ALL);
                    builder.add(TextUtil.withColor(material.getDisplayNameWithModifiers(part.getType(), ItemStack.EMPTY), nameColor));
                }
                builder.unindent();
            }
        }
    }
    tooltip.addAll(builder.build());
}
Also used : MutableComponent(net.minecraft.network.chat.MutableComponent) IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) PartData(net.silentchaos512.gear.gear.part.PartData) CompoundPart(net.silentchaos512.gear.gear.part.CompoundPart)

Example 8 with TextListBuilder

use of net.silentchaos512.gear.client.util.TextListBuilder in project Silent-Gear by SilentChaos512.

the class TooltipHandler method getMaterialStatLines.

private static void getMaterialStatLines(ItemTooltipEvent event, PartType partType, MaterialInstance material) {
    TextListBuilder builder = new TextListBuilder();
    for (ItemStat stat : ItemStats.allStatsOrdered()) {
        if (stat.isVisible()) {
            getMaterialStatModLines(event, partType, material, builder, stat);
        }
    }
    event.getToolTip().addAll(builder.build());
}
Also used : TextListBuilder(net.silentchaos512.gear.client.util.TextListBuilder) ItemStat(net.silentchaos512.gear.api.stats.ItemStat)

Example 9 with TextListBuilder

use of net.silentchaos512.gear.client.util.TextListBuilder in project Silent-Gear by SilentChaos512.

the class TooltipHandler method getMaterialStatModLines.

private static void getMaterialStatModLines(ItemTooltipEvent event, PartType partType, MaterialInstance material, TextListBuilder builder, ItemStat stat) {
    Collection<StatInstance> modsAll = material.getStatModifiers(partType, StatGearKey.of(stat, GearType.ALL));
    Optional<MutableComponent> head = getStatTooltipLine(event, partType, stat, modsAll);
    builder.add(head.orElseGet(() -> TextUtil.withColor(stat.getDisplayName(), stat.getNameColor())));
    builder.indent();
    int subCount = 0;
    List<StatGearKey> keysForStat = material.get().getStatKeys(material, partType).stream().filter(key -> key.getStat().equals(stat)).collect(Collectors.toList());
    for (StatGearKey key : keysForStat) {
        if (key.getGearType() != GearType.ALL) {
            ItemStat stat1 = ItemStats.get(key.getStat());
            if (stat1 != null) {
                Collection<StatInstance> mods = material.getStatModifiers(partType, key);
                Optional<MutableComponent> line = getSubStatTooltipLine(event, partType, stat1, key.getGearType(), mods);
                if (line.isPresent()) {
                    builder.add(line.get());
                    ++subCount;
                }
            }
        }
    }
    if (subCount == 0 && !head.isPresent()) {
        builder.removeLast();
    }
    builder.unindent();
}
Also used : GraderTileEntity(net.silentchaos512.gear.block.grader.GraderTileEntity) java.util(java.util) ChargerTileEntity(net.silentchaos512.gear.block.charger.ChargerTileEntity) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance) StatModifierMap(net.silentchaos512.gear.api.stats.StatModifierMap) IMaterialModifier(net.silentchaos512.gear.api.material.modifier.IMaterialModifier) MutableComponent(net.minecraft.network.chat.MutableComponent) PartData(net.silentchaos512.gear.gear.part.PartData) I18n(net.minecraft.client.resources.language.I18n) AbstractGearPart(net.silentchaos512.gear.gear.part.AbstractGearPart) Config(net.silentchaos512.gear.config.Config) ChatFormatting(net.minecraft.ChatFormatting) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) IMaterialCategory(net.silentchaos512.gear.api.material.IMaterialCategory) StatInstance(net.silentchaos512.gear.api.stats.StatInstance) KeyTracker(net.silentchaos512.gear.client.KeyTracker) ItemStat(net.silentchaos512.gear.api.stats.ItemStat) TextUtil(net.silentchaos512.gear.util.TextUtil) ItemStats(net.silentchaos512.gear.api.stats.ItemStats) Component(net.minecraft.network.chat.Component) StatGearKey(net.silentchaos512.gear.api.util.StatGearKey) ModTags(net.silentchaos512.gear.init.ModTags) Collectors(java.util.stream.Collectors) PartType(net.silentchaos512.gear.api.part.PartType) GearType(net.silentchaos512.gear.api.item.GearType) TextComponent(net.minecraft.network.chat.TextComponent) Color(net.silentchaos512.utils.Color) ItemTooltipEvent(net.minecraftforge.event.entity.player.ItemTooltipEvent) TraitInstance(net.silentchaos512.gear.api.traits.TraitInstance) ItemStack(net.minecraft.world.item.ItemStack) ClientTicks(net.silentchaos512.lib.event.ClientTicks) TagUtils(net.silentchaos512.lib.util.TagUtils) TextListBuilder(net.silentchaos512.gear.client.util.TextListBuilder) CompoundPartItem(net.silentchaos512.gear.item.CompoundPartItem) MutableComponent(net.minecraft.network.chat.MutableComponent) StatInstance(net.silentchaos512.gear.api.stats.StatInstance) ItemStat(net.silentchaos512.gear.api.stats.ItemStat) StatGearKey(net.silentchaos512.gear.api.util.StatGearKey)

Aggregations

TextListBuilder (net.silentchaos512.gear.client.util.TextListBuilder)7 MutableComponent (net.minecraft.network.chat.MutableComponent)4 ItemStat (net.silentchaos512.gear.api.stats.ItemStat)4 Component (net.minecraft.network.chat.Component)3 TextComponent (net.minecraft.network.chat.TextComponent)3 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)3 StatInstance (net.silentchaos512.gear.api.stats.StatInstance)3 PartData (net.silentchaos512.gear.gear.part.PartData)3 ItemStack (net.minecraft.world.item.ItemStack)2 GearType (net.silentchaos512.gear.api.item.GearType)2 IMaterialInstance (net.silentchaos512.gear.api.material.IMaterialInstance)2 PartType (net.silentchaos512.gear.api.part.PartType)2 TraitInstance (net.silentchaos512.gear.api.traits.TraitInstance)2 Color (net.silentchaos512.utils.Color)2 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 ChatFormatting (net.minecraft.ChatFormatting)1 I18n (net.minecraft.client.resources.language.I18n)1 ItemTooltipEvent (net.minecraftforge.event.entity.player.ItemTooltipEvent)1 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)1