Search in sources :

Example 11 with ItemStat

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

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

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

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

Example 15 with ItemStat

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

the class RecalculateStatsPacket method decode.

public static RecalculateStatsPacket decode(FriendlyByteBuf buffer) {
    int slot = buffer.readVarInt();
    ItemStat stat = ItemStats.byName(buffer.readResourceLocation());
    return new RecalculateStatsPacket(slot, Objects.requireNonNull(stat));
}
Also used : ItemStat(net.silentchaos512.gear.api.stats.ItemStat) IItemStat(net.silentchaos512.gear.api.stats.IItemStat)

Aggregations

ItemStat (net.silentchaos512.gear.api.stats.ItemStat)16 StatInstance (net.silentchaos512.gear.api.stats.StatInstance)13 GearType (net.silentchaos512.gear.api.item.GearType)9 Color (net.silentchaos512.utils.Color)9 StatGearKey (net.silentchaos512.gear.api.util.StatGearKey)8 TextComponent (net.minecraft.network.chat.TextComponent)7 Component (net.minecraft.network.chat.Component)5 MutableComponent (net.minecraft.network.chat.MutableComponent)5 Nullable (javax.annotation.Nullable)4 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)4 ItemStack (net.minecraft.world.item.ItemStack)4 IItemStat (net.silentchaos512.gear.api.stats.IItemStat)4 JsonObject (com.google.gson.JsonObject)3 JsonParseException (com.google.gson.JsonParseException)3 java.util (java.util)3 Collectors (java.util.stream.Collectors)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