Search in sources :

Example 1 with TraitInstance

use of net.silentchaos512.gear.api.traits.TraitInstance in project Silent-Gear by SilentChaos512.

the class CompoundPart method getTraits.

@Override
public Collection<TraitInstance> getTraits(IPartData part, PartGearKey partKey, ItemStack gear) {
    List<TraitInstance> ret = new ArrayList<>(super.getTraits(part, partKey, gear));
    List<IMaterialInstance> materials = getMaterials(part);
    for (TraitInstance inst : TraitHelper.getTraits(materials, partKey, gear)) {
        if (inst.conditionsMatch(partKey, gear, materials)) {
            ret.add(inst);
        }
    }
    return ret;
}
Also used : IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) TraitInstance(net.silentchaos512.gear.api.traits.TraitInstance) ArrayList(java.util.ArrayList)

Example 2 with TraitInstance

use of net.silentchaos512.gear.api.traits.TraitInstance 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 3 with TraitInstance

use of net.silentchaos512.gear.api.traits.TraitInstance 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 4 with TraitInstance

use of net.silentchaos512.gear.api.traits.TraitInstance in project Silent-Gear by SilentChaos512.

the class TooltipHandler method onPartTooltip.

private static void onPartTooltip(ItemTooltipEvent event, ItemStack stack, PartData part) {
    if (event.getFlags().isAdvanced() && KeyTracker.isControlDown()) {
        event.getToolTip().add(new TextComponent("* Part ID: " + part.getId()).withStyle(ChatFormatting.DARK_GRAY));
        event.getToolTip().add(new TextComponent("* Part data pack: " + part.get().getPackName()).withStyle(ChatFormatting.DARK_GRAY));
    }
    if (!Config.Client.showPartTooltips.get()) {
        return;
    }
    // Type, tier
    event.getToolTip().add(TextUtil.withColor(part.getType().getDisplayName(part.getTier()), Color.AQUAMARINE));
    // Traits
    List<TraitInstance> traits = new ArrayList<>();
    for (TraitInstance traitInstance : part.getTraits()) {
        if (traitInstance.getTrait().showInTooltip(event.getFlags())) {
            traits.add(traitInstance);
        }
    }
    int numTraits = traits.size();
    int traitIndex = getTraitDisplayIndex(numTraits);
    int i = 0;
    for (TraitInstance inst : traits) {
        if (traitIndex < 0 || traitIndex == i) {
            inst.addInformation(event.getToolTip(), event.getFlags());
        }
        ++i;
    }
    // Stats
    if (KeyTracker.isControlDown()) {
        event.getToolTip().add(new TranslatableComponent("misc.silentgear.tooltip.stats").withStyle(ChatFormatting.GOLD).append(new TextComponent(" (Silent Gear)").withStyle(ChatFormatting.RESET).withStyle(ChatFormatting.ITALIC)));
        getPartStatLines(event, stack, part);
    } else {
        event.getToolTip().add(new TranslatableComponent("misc.silentgear.tooltip.ctrlForStats").withStyle(ChatFormatting.GOLD));
    }
    // Gear type blacklist?
    if (part.get() instanceof AbstractGearPart) {
        List<GearType> blacklist = ((AbstractGearPart) part.get()).getBlacklistedGearTypes();
        if (!blacklist.isEmpty()) {
            int index = (ClientTicks.ticksInGame() / 20) % blacklist.size();
            GearType gearType = blacklist.get(index);
            Component blacklistedType = gearType.getDisplayName();
            event.getToolTip().add(new TranslatableComponent("misc.silentgear.tooltip.blacklist", blacklistedType).withStyle(ChatFormatting.RED));
        }
    }
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) AbstractGearPart(net.silentchaos512.gear.gear.part.AbstractGearPart) GearType(net.silentchaos512.gear.api.item.GearType) TraitInstance(net.silentchaos512.gear.api.traits.TraitInstance) 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 5 with TraitInstance

use of net.silentchaos512.gear.api.traits.TraitInstance in project Silent-Gear by SilentChaos512.

the class SynergyUtils method getSynergy.

public static float getSynergy(PartType partType, List<? extends IMaterialInstance> materials, Collection<TraitInstance> traits) {
    if (materials.isEmpty()) {
        return 1;
    }
    // First, we add a bonus for the number of unique materials
    double synergy = getBaseSynergy(materials);
    // Second, reduce synergy for differences in certain properties
    IMaterialInstance primary = materials.get(0);
    final double primaryRarity = primary.getStat(partType, ItemStats.RARITY);
    final double maxRarity = materials.stream().mapToDouble(m -> m.getStat(partType, ItemStats.RARITY)).max().orElse(0);
    final int maxTier = materials.stream().mapToInt(m -> m.getTier(partType)).max().orElse(0);
    for (IMaterialInstance material : getUniques(materials)) {
        if (maxRarity > 0) {
            float rarity = material.getStat(partType, ItemStats.RARITY);
            synergy -= 0.005 * Math.abs(primaryRarity - rarity);
        }
        if (maxTier > 0) {
            int tier = material.getTier(partType);
            synergy -= 0.08 * Math.abs(maxTier - tier);
        }
    }
    // Synergy traits
    for (TraitInstance trait : traits) {
        if (trait.getTrait() instanceof SynergyTrait) {
            synergy = ((SynergyTrait) trait.getTrait()).apply(synergy, trait.getLevel());
        }
    }
    return (float) Mth.clamp(synergy, MIN_VALUE, MAX_VALUE);
}
Also used : SynergyTrait(net.silentchaos512.gear.gear.trait.SynergyTrait) IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) TraitInstance(net.silentchaos512.gear.api.traits.TraitInstance)

Aggregations

TraitInstance (net.silentchaos512.gear.api.traits.TraitInstance)12 TextComponent (net.minecraft.network.chat.TextComponent)3 IMaterialInstance (net.silentchaos512.gear.api.material.IMaterialInstance)3 ITrait (net.silentchaos512.gear.api.traits.ITrait)3 PartData (net.silentchaos512.gear.gear.part.PartData)3 Component (net.minecraft.network.chat.Component)2 MutableComponent (net.minecraft.network.chat.MutableComponent)2 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)2 IGearPart (net.silentchaos512.gear.api.part.IGearPart)2 PartType (net.silentchaos512.gear.api.part.PartType)2 CommandDispatcher (com.mojang.brigadier.CommandDispatcher)1 CommandContext (com.mojang.brigadier.context.CommandContext)1 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)1 SuggestionProvider (com.mojang.brigadier.suggestion.SuggestionProvider)1 java.io (java.io)1 StandardCharsets (java.nio.charset.StandardCharsets)1 LocalDateTime (java.time.LocalDateTime)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1