Search in sources :

Example 11 with PartType

use of net.silentchaos512.gear.api.part.PartType in project Silent-Gear by SilentChaos512.

the class TooltipHandler method getStatTooltipLine.

private static Optional<MutableComponent> getStatTooltipLine(ItemTooltipEvent event, PartType partType, ItemStat stat, Collection<StatInstance> modifiers) {
    if (!modifiers.isEmpty()) {
        StatInstance inst = stat.computeForDisplay(0, GearType.ALL, modifiers);
        if (inst.shouldList(partType, stat, event.getFlags().isAdvanced())) {
            boolean isZero = inst.getValue() == 0;
            Color nameColor = isZero ? MC_DARK_GRAY : stat.getNameColor();
            Color statColor = isZero ? MC_DARK_GRAY : Color.WHITE;
            MutableComponent nameStr = TextUtil.withColor(stat.getDisplayName(), nameColor);
            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), statColor);
            // 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)

Example 12 with PartType

use of net.silentchaos512.gear.api.part.PartType in project Silent-Gear by SilentChaos512.

the class TooltipHandler method buildPartTypeHeader.

private static Component buildPartTypeHeader(Collection<PartType> types, PartType selectedType) {
    MutableComponent ret = new TextComponent("| ").withStyle(ChatFormatting.GRAY);
    for (PartType type : types) {
        Color color = type == selectedType ? Color.AQUAMARINE : MC_DARK_GRAY;
        Component text = TextUtil.withColor(type.getDisplayName(-1), color);
        ret.append(text).append(" | ");
    }
    Component keyHint = TextUtil.misc("tooltip.material.keyHint", TextUtil.withColor(TextUtil.keyBinding(KeyTracker.CYCLE_BACK), Color.AQUAMARINE), TextUtil.withColor(TextUtil.keyBinding(KeyTracker.CYCLE_NEXT), Color.AQUAMARINE));
    return ret.append(keyHint);
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) PartType(net.silentchaos512.gear.api.part.PartType) MutableComponent(net.minecraft.network.chat.MutableComponent) Color(net.silentchaos512.utils.Color) MutableComponent(net.minecraft.network.chat.MutableComponent) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) Component(net.minecraft.network.chat.Component) TextComponent(net.minecraft.network.chat.TextComponent)

Example 13 with PartType

use of net.silentchaos512.gear.api.part.PartType in project Silent-Gear by SilentChaos512.

the class TooltipHandler method addJeiSearchTerms.

private static void addJeiSearchTerms(ItemTooltipEvent event, MaterialInstance material) {
    // Add search terms to allow advanced filtering in JEI (requires the
    // `SearchAdvancedTooltips` JEI config to be set)
    StringBuilder b = new StringBuilder();
    for (IMaterialCategory category : material.getCategories()) {
        b.append(category.getName()).append(" ");
    }
    Collection<String> traits = new HashSet<>();
    for (PartType partType : material.getPartTypes()) {
        b.append(partType.getDisplayName(0).getString()).append(" ");
        for (TraitInstance trait : material.getTraits(partType)) {
            traits.add(trait.getTrait().getDisplayName(0).getString());
        }
    }
    for (String str : traits) {
        b.append(str).append(" ");
    }
    event.getToolTip().add(new TextComponent(b.toString().toLowerCase(Locale.ROOT)).withStyle(ChatFormatting.DARK_GRAY).withStyle(ChatFormatting.ITALIC));
}
Also used : PartType(net.silentchaos512.gear.api.part.PartType) TextComponent(net.minecraft.network.chat.TextComponent) IMaterialCategory(net.silentchaos512.gear.api.material.IMaterialCategory) TraitInstance(net.silentchaos512.gear.api.traits.TraitInstance)

Example 14 with PartType

use of net.silentchaos512.gear.api.part.PartType 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 15 with PartType

use of net.silentchaos512.gear.api.part.PartType in project Silent-Gear by SilentChaos512.

the class TooltipHandler method onMaterialTooltip.

private static void onMaterialTooltip(ItemTooltipEvent event, ItemStack stack, MaterialInstance material) {
    boolean keyHeld = KeyTracker.isDisplayStatsDown();
    if (event.getFlags().isAdvanced()) {
        event.getToolTip().add(new TextComponent("Material ID: " + material.getId()).withStyle(ChatFormatting.DARK_GRAY));
        event.getToolTip().add(new TextComponent("Material data pack: " + material.get().getPackName()).withStyle(ChatFormatting.DARK_GRAY));
    }
    if (!Config.Client.showMaterialTooltips.get()) {
        return;
    }
    if (keyHeld) {
        event.getToolTip().add(TextUtil.withColor(TextUtil.misc("tooltip.material"), Color.GOLD));
    } else {
        event.getToolTip().add(TextUtil.withColor(TextUtil.misc("tooltip.material"), Color.GOLD).append(new TextComponent(" ").append(TextUtil.withColor(TextUtil.keyBinding(KeyTracker.DISPLAY_STATS), ChatFormatting.GRAY))));
    }
    if (event.getFlags().isAdvanced()) {
        event.getToolTip().add(new TextComponent("Material ID: " + material.getId()).withStyle(ChatFormatting.DARK_GRAY));
        event.getToolTip().add(new TextComponent("Material data pack: " + material.get().getPackName()).withStyle(ChatFormatting.DARK_GRAY));
    }
    if (keyHeld) {
        getMaterialModifierLines(event, material);
        getMaterialCategoriesLine(material).ifPresent(t -> event.getToolTip().add(t));
        List<PartType> partTypes = new ArrayList<>(material.getPartTypes());
        if (!partTypes.isEmpty()) {
            int index = KeyTracker.getMaterialCycleIndex(partTypes.size());
            PartType partType = partTypes.get(index);
            event.getToolTip().add(buildPartTypeHeader(partTypes, partType));
            event.getToolTip().add(TextUtil.withColor(TextUtil.misc("tier", material.getTier(partType)), Color.DEEPSKYBLUE));
            getMaterialTraitLines(event, partType, material);
            event.getToolTip().add(new TranslatableComponent("misc.silentgear.tooltip.stats").withStyle(ChatFormatting.GOLD));
            getMaterialStatLines(event, partType, material);
        }
    } else {
        getMaterialModifierLines(event, material);
        if (event.getFlags().isAdvanced()) {
            addJeiSearchTerms(event, material);
        }
    }
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) PartType(net.silentchaos512.gear.api.part.PartType) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent)

Aggregations

PartType (net.silentchaos512.gear.api.part.PartType)37 ItemStack (net.minecraft.world.item.ItemStack)14 PartData (net.silentchaos512.gear.gear.part.PartData)14 StatInstance (net.silentchaos512.gear.api.stats.StatInstance)13 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)10 ICoreItem (net.silentchaos512.gear.api.item.ICoreItem)10 TextComponent (net.minecraft.network.chat.TextComponent)9 ResourceLocation (net.minecraft.resources.ResourceLocation)9 GearType (net.silentchaos512.gear.api.item.GearType)9 PartDataList (net.silentchaos512.gear.api.part.PartDataList)9 ItemStat (net.silentchaos512.gear.api.stats.ItemStat)9 Component (net.minecraft.network.chat.Component)8 IMaterialInstance (net.silentchaos512.gear.api.material.IMaterialInstance)8 IPartData (net.silentchaos512.gear.api.part.IPartData)8 MaterialInstance (net.silentchaos512.gear.gear.material.MaterialInstance)8 TraitInstance (net.silentchaos512.gear.api.traits.TraitInstance)7 StatGearKey (net.silentchaos512.gear.api.util.StatGearKey)7 ArrayList (java.util.ArrayList)5 Collectors (java.util.stream.Collectors)5 MutableComponent (net.minecraft.network.chat.MutableComponent)5