Search in sources :

Example 26 with StatInstance

use of net.silentchaos512.gear.api.stats.StatInstance in project Silent-Gear by SilentChaos512.

the class MaterialsCommand method makeTsvLine.

private static String makeTsvLine(MaterialInstance material, PartType partType) {
    StringBuilder builder = new StringBuilder();
    appendTsv(builder, material.get().getPackName());
    appendTsv(builder, material.getDisplayName(partType).getString());
    int tier = material.getTier(partType);
    // appendTsv(builder, partType.getDisplayName(tier).getFormattedText());
    appendTsv(builder, partType.getDisplayName(0).getString());
    appendTsv(builder, material.getId().toString());
    appendTsv(builder, getParentId(material.get()));
    // Traits
    appendTsv(builder, material.getTraits(partType).stream().map(t -> t.getTrait().getDisplayName(t.getLevel()).getString()).collect(Collectors.joining(", ")));
    appendTsv(builder, tier);
    // Stats
    for (ItemStat stat : ItemStats.allStatsOrdered()) {
        Collection<StatInstance> statModifiers = material.getStatModifiers(partType, StatGearKey.of(stat, GearType.ALL));
        appendTsv(builder, FORMAT_CODES.matcher(StatModifierMap.formatText(statModifiers, stat, 5).getString()).replaceAll(""));
    }
    return builder.toString();
}
Also used : StatInstance(net.silentchaos512.gear.api.stats.StatInstance) ItemStat(net.silentchaos512.gear.api.stats.ItemStat)

Example 27 with StatInstance

use of net.silentchaos512.gear.api.stats.StatInstance in project Silent-Gear by SilentChaos512.

the class PartsCommand method partToTsvLine.

private static String partToTsvLine(IGearPart part) {
    StringBuilder builder = new StringBuilder();
    PartData partData = PartData.of(part);
    appendTsv(builder, part.getDisplayName(partData, ItemStack.EMPTY).getString());
    appendTsv(builder, part.getId().toString());
    appendTsv(builder, part.getType().getName());
    appendTsv(builder, partData.getTier());
    // Stats
    for (ItemStat stat : ItemStats.allStatsOrdered()) {
        Collection<StatInstance> statModifiers = partData.getStatModifiers(StatGearKey.of(stat, GearType.ALL), ItemStack.EMPTY);
        appendTsv(builder, FORMAT_CODES.matcher(StatModifierMap.formatText(statModifiers, stat, 5).getString()).replaceAll(""));
    }
    // Traits
    appendTsv(builder, partData.getTraits().stream().map(t -> t.getTrait().getDisplayName(t.getLevel()).getString()).collect(Collectors.joining(", ")));
    return builder.toString();
}
Also used : PartData(net.silentchaos512.gear.gear.part.PartData) StatInstance(net.silentchaos512.gear.api.stats.StatInstance) ItemStat(net.silentchaos512.gear.api.stats.ItemStat)

Example 28 with StatInstance

use of net.silentchaos512.gear.api.stats.StatInstance 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)

Example 29 with StatInstance

use of net.silentchaos512.gear.api.stats.StatInstance 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)

Example 30 with StatInstance

use of net.silentchaos512.gear.api.stats.StatInstance in project Silent-Gear by SilentChaos512.

the class IStatModProvider method getStat.

default float getStat(D instance, PartType partType, StatGearKey key, ItemStack gear) {
    ItemStat stat = ItemStats.get(key.getStat());
    if (stat == null)
        return key.getStat().getDefaultValue();
    Collection<StatInstance> mods = getStatModifiers(instance, partType, key, gear);
    return stat.compute(mods);
}
Also used : StatInstance(net.silentchaos512.gear.api.stats.StatInstance) ItemStat(net.silentchaos512.gear.api.stats.ItemStat)

Aggregations

StatInstance (net.silentchaos512.gear.api.stats.StatInstance)18 StatGearKey (net.silentchaos512.gear.api.util.StatGearKey)15 ItemStat (net.silentchaos512.gear.api.stats.ItemStat)11 GearType (net.silentchaos512.gear.api.item.GearType)7 Component (net.minecraft.network.chat.Component)5 MutableComponent (net.minecraft.network.chat.MutableComponent)5 Color (net.silentchaos512.utils.Color)5 JsonObject (com.google.gson.JsonObject)4 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)4 ItemStack (net.minecraft.world.item.ItemStack)4 JsonParseException (com.google.gson.JsonParseException)3 java.util (java.util)3 ArrayList (java.util.ArrayList)3 Collectors (java.util.stream.Collectors)3 Nullable (javax.annotation.Nullable)3 FriendlyByteBuf (net.minecraft.network.FriendlyByteBuf)3 ResourceLocation (net.minecraft.resources.ResourceLocation)3 GsonHelper (net.minecraft.util.GsonHelper)3 PartType (net.silentchaos512.gear.api.part.PartType)3 TraitInstance (net.silentchaos512.gear.api.traits.TraitInstance)3