Search in sources :

Example 1 with TextListBuilder

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

the class TooltipHandler method getPartStatLines.

private static void getPartStatLines(ItemTooltipEvent event, ItemStack stack, PartData part) {
    GearType gearType = getPartGearType(part);
    TextListBuilder builder = new TextListBuilder();
    List<ItemStat> relevantStats = new ArrayList<>(part.getGearType().getRelevantStats());
    if (part.getGearType().isArmor() && relevantStats.contains(ItemStats.DURABILITY)) {
        int index = relevantStats.indexOf(ItemStats.DURABILITY);
        relevantStats.remove(ItemStats.DURABILITY);
        relevantStats.add(index, ItemStats.ARMOR_DURABILITY);
    }
    for (ItemStat stat : relevantStats) {
        Collection<StatInstance> modifiers = new ArrayList<>();
        for (StatInstance mod : part.getStatModifiers(StatGearKey.of(stat, gearType), ItemStack.EMPTY)) {
            if (mod.getOp() == StatInstance.Operation.AVG) {
                float computed = stat.compute(Collections.singleton(mod));
                modifiers.add(StatInstance.of(computed, StatInstance.Operation.AVG, mod.getKey()));
            } else {
                modifiers.add(mod);
            }
        }
        getStatTooltipLine(event, part.getType(), stat, modifiers).ifPresent(builder::add);
    }
    event.getToolTip().addAll(builder.build());
}
Also used : TextListBuilder(net.silentchaos512.gear.client.util.TextListBuilder) GearType(net.silentchaos512.gear.api.item.GearType) StatInstance(net.silentchaos512.gear.api.stats.StatInstance) ItemStat(net.silentchaos512.gear.api.stats.ItemStat)

Example 2 with TextListBuilder

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

the class TooltipHandler method getMaterialTraitLines.

private static void getMaterialTraitLines(ItemTooltipEvent event, PartType partType, MaterialInstance material) {
    Collection<TraitInstance> traits = material.getTraits(partType);
    if (traits.isEmpty())
        return;
    MutableComponent header = TextUtil.misc("tooltip.traits").withStyle(ChatFormatting.GOLD);
    if (!KeyTracker.isDisplayTraitsDown()) {
        MutableComponent keyHint = TextUtil.withColor(TextUtil.keyBinding(KeyTracker.DISPLAY_TRAITS), Color.AQUAMARINE);
        header.append(" ").append(keyHint);
    }
    event.getToolTip().add(header);
    TextListBuilder builder = new TextListBuilder();
    for (TraitInstance trait : traits) {
        builder.add(trait.getDisplayName());
        // Trait description and conditions
        if (event.getFlags().isAdvanced() || KeyTracker.isDisplayTraitsDown()) {
            builder.indent();
            builder.add(trait.getTrait().getDescription(trait.getLevel()).withStyle(ChatFormatting.DARK_GRAY));
            if (!trait.getConditions().isEmpty()) {
                builder.add(TextUtil.withColor(trait.getConditionsText(), ChatFormatting.DARK_GRAY));
            }
            builder.unindent();
        }
    }
    event.getToolTip().addAll(builder.build());
}
Also used : TextListBuilder(net.silentchaos512.gear.client.util.TextListBuilder) MutableComponent(net.minecraft.network.chat.MutableComponent) TraitInstance(net.silentchaos512.gear.api.traits.TraitInstance)

Example 3 with TextListBuilder

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

the class GearBlueprintItem method appendSupportedTypesText.

private void appendSupportedTypesText(Collection<Component> list) {
    if (KeyTracker.isDisplayStatsDown()) {
        Optional<ICoreItem> itemOptional = this.gearType.getItem();
        if (itemOptional.isPresent()) {
            TextListBuilder builder = new TextListBuilder();
            ICoreItem item = itemOptional.get();
            ItemStack gear = new ItemStack(item);
            for (PartType type : PartType.getValues()) {
                if (type != PartType.MAIN) {
                    List<IGearPart> partsOfType = PartManager.getPartsOfType(type);
                    if (!partsOfType.isEmpty() && item.supportsPart(gear, PartData.of(partsOfType.get(0)))) {
                        builder.add(type.getDisplayName(0));
                    }
                }
            }
            List<Component> lines = builder.build();
            if (!lines.isEmpty()) {
                list.add(TextUtil.withColor(TextUtil.misc("supportedPartTypes"), Color.GOLD));
                list.addAll(lines);
            }
        }
    } else {
        list.add(TextUtil.withColor(TextUtil.misc("supportedPartTypes"), Color.GOLD).append(" ").append(TextUtil.withColor(TextUtil.keyBinding(KeyTracker.DISPLAY_STATS), ChatFormatting.GRAY)));
    }
}
Also used : TextListBuilder(net.silentchaos512.gear.client.util.TextListBuilder) PartType(net.silentchaos512.gear.api.part.PartType) IGearPart(net.silentchaos512.gear.api.part.IGearPart) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem) ItemStack(net.minecraft.world.item.ItemStack) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) Component(net.minecraft.network.chat.Component) TextComponent(net.minecraft.network.chat.TextComponent)

Example 4 with TextListBuilder

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

the class CompoundMaterialItem method appendHoverText.

@Override
public void appendHoverText(ItemStack stack, @Nullable Level worldIn, List<Component> tooltip, TooltipFlag flagIn) {
    if (Config.Client.showMaterialTooltips.get()) {
        Collection<IMaterialInstance> materials = getSubMaterials(stack);
        TextListBuilder statsBuilder = new TextListBuilder();
        for (IMaterialInstance material : materials) {
            int nameColor = material.getNameColor(PartType.MAIN, GearType.ALL);
            statsBuilder.add(TextUtil.withColor(material.getDisplayName(PartType.MAIN).copy(), nameColor));
        }
        tooltip.addAll(statsBuilder.build());
    }
}
Also used : TextListBuilder(net.silentchaos512.gear.client.util.TextListBuilder) IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance)

Example 5 with TextListBuilder

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

the class CompoundPartItem method appendHoverText.

@Override
public void appendHoverText(ItemStack stack, @Nullable Level worldIn, List<Component> tooltip, TooltipFlag flagIn) {
    PartData part = PartData.from(stack);
    if (part != null && Config.Client.showPartTooltips.get()) {
        float synergy = SynergyUtils.getSynergy(this.partType, getMaterials(stack), part.getTraits());
        tooltip.add(SynergyUtils.getDisplayText(synergy));
        TextListBuilder matsBuilder = new TextListBuilder();
        getMaterials(stack).forEach(material -> {
            int nameColor = material.getNameColor(part.getType(), this.getGearType());
            matsBuilder.add(TextUtil.withColor(material.getDisplayNameWithModifiers(part.getType(), ItemStack.EMPTY), nameColor));
        });
        tooltip.addAll(matsBuilder.build());
    }
}
Also used : TextListBuilder(net.silentchaos512.gear.client.util.TextListBuilder) PartData(net.silentchaos512.gear.gear.part.PartData)

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