Search in sources :

Example 11 with StatInstance

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

the class StatModifierMap method formatText.

public static MutableComponent formatText(Collection<StatInstance> mods, ItemStat stat, int maxDecimalPlaces, boolean addModColors) {
    if (mods.size() == 1) {
        StatInstance inst = mods.iterator().next();
        int decimalPlaces = inst.getPreferredDecimalPlaces(stat, maxDecimalPlaces);
        return inst.getFormattedText(stat, decimalPlaces, addModColors);
    }
    // Sort modifiers by operation
    MutableComponent result = new TextComponent("");
    List<StatInstance> toSort = new ArrayList<>(mods);
    toSort.sort(Comparator.comparing(inst -> inst.getOp().ordinal()));
    for (StatInstance inst : toSort) {
        if (!result.getSiblings().isEmpty()) {
            result.append(", ");
        }
        result.append(inst.getFormattedText(stat, inst.getPreferredDecimalPlaces(stat, maxDecimalPlaces), addModColors));
    }
    return result;
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) JsonParseException(com.google.gson.JsonParseException) JsonObject(com.google.gson.JsonObject) java.util(java.util) StatGearKey(net.silentchaos512.gear.api.util.StatGearKey) MultimapBuilder(com.google.common.collect.MultimapBuilder) Multiset(com.google.common.collect.Multiset) Multimap(com.google.common.collect.Multimap) FriendlyByteBuf(net.minecraft.network.FriendlyByteBuf) MutableComponent(net.minecraft.network.chat.MutableComponent) JsonElement(com.google.gson.JsonElement) GearType(net.silentchaos512.gear.api.item.GearType) JsonArray(com.google.gson.JsonArray) TextComponent(net.minecraft.network.chat.TextComponent) GsonHelper(net.minecraft.util.GsonHelper) Entry(java.util.Map.Entry) IGearPart(net.silentchaos512.gear.api.part.IGearPart) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) MutableComponent(net.minecraft.network.chat.MutableComponent)

Example 12 with StatInstance

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

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

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

the class IStatModProvider method getStatUnclamped.

default float getStatUnclamped(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(stat.getBaseValue(), false, key.getGearType(), mods);
}
Also used : StatInstance(net.silentchaos512.gear.api.stats.StatInstance) ItemStat(net.silentchaos512.gear.api.stats.ItemStat)

Example 15 with StatInstance

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

the class GearData method getStatModifiers.

public static StatModifierMap getStatModifiers(ItemStack stack, ICoreItem item, PartDataList parts) {
    GearType gearType = item.getGearType();
    StatModifierMap stats = new StatModifierMap();
    for (ItemStat stat : ItemStats.allStatsOrderedExcluding(item.getExcludedStats(stack))) {
        StatGearKey itemKey = StatGearKey.of(stat, gearType);
        for (PartData part : parts) {
            for (StatInstance mod : part.getStatModifiers(itemKey, stack)) {
                StatInstance modCopy = StatInstance.of(mod.getValue(), mod.getOp(), itemKey);
                stats.put(modCopy.getKey(), modCopy);
            }
        }
    }
    return stats;
}
Also used : GearType(net.silentchaos512.gear.api.item.GearType) PartData(net.silentchaos512.gear.gear.part.PartData) IPartData(net.silentchaos512.gear.api.part.IPartData) StatGearKey(net.silentchaos512.gear.api.util.StatGearKey)

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