Search in sources :

Example 11 with StatGearKey

use of net.silentchaos512.gear.api.util.StatGearKey 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 12 with StatGearKey

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

use of net.silentchaos512.gear.api.util.StatGearKey in project Silent-Gear by SilentChaos512.

the class MaterialBuilder method stat.

public MaterialBuilder stat(PartType partType, IItemStat stat, GearType gearType, float value, StatInstance.Operation operation) {
    StatGearKey key = StatGearKey.of(stat, gearType);
    StatInstance mod = StatInstance.of(value, operation, key);
    StatModifierMap map = stats.computeIfAbsent(partType, pt -> new StatModifierMap());
    map.put(stat, gearType, mod);
    return this;
}
Also used : StatGearKey(net.silentchaos512.gear.api.util.StatGearKey)

Example 14 with StatGearKey

use of net.silentchaos512.gear.api.util.StatGearKey in project Silent-Gear by SilentChaos512.

the class StatInstance method getWeightedAverageMod.

public static StatInstance getWeightedAverageMod(Collection<StatInstance> modifiers, Operation op) {
    float value = ItemStat.getWeightedAverage(modifiers, op);
    StatGearKey key = getMostSpecificKey(modifiers);
    return new StatInstance(value, op, key);
}
Also used : StatGearKey(net.silentchaos512.gear.api.util.StatGearKey)

Example 15 with StatGearKey

use of net.silentchaos512.gear.api.util.StatGearKey in project Silent-Gear by SilentChaos512.

the class StatInstance method getMostSpecificKey.

private static StatGearKey getMostSpecificKey(Collection<StatInstance> modifiers) {
    // Gets the key furthest down the gear type hierarchy (key with most parents)
    Set<StatGearKey> found = new HashSet<>();
    for (StatInstance mod : modifiers) {
        found.add(mod.key);
    }
    StatGearKey ret = null;
    int best = 0;
    for (StatGearKey key : found) {
        int parents = 0;
        StatGearKey parent = key.getParent();
        while (parent != null) {
            parent = parent.getParent();
            ++parents;
        }
        if (parents > best || ret == null) {
            best = parents;
            ret = key;
        }
    }
    return ret != null ? ret : DEFAULT_KEY;
}
Also used : StatGearKey(net.silentchaos512.gear.api.util.StatGearKey)

Aggregations

StatGearKey (net.silentchaos512.gear.api.util.StatGearKey)16 StatInstance (net.silentchaos512.gear.api.stats.StatInstance)12 ItemStat (net.silentchaos512.gear.api.stats.ItemStat)8 GearType (net.silentchaos512.gear.api.item.GearType)6 Component (net.minecraft.network.chat.Component)4 ItemStack (net.minecraft.world.item.ItemStack)4 JsonObject (com.google.gson.JsonObject)3 JsonParseException (com.google.gson.JsonParseException)3 ArrayList (java.util.ArrayList)3 Collectors (java.util.stream.Collectors)3 Nullable (javax.annotation.Nullable)3 ResourceLocation (net.minecraft.resources.ResourceLocation)3 ICoreItem (net.silentchaos512.gear.api.item.ICoreItem)3 IMaterialInstance (net.silentchaos512.gear.api.material.IMaterialInstance)3 PartType (net.silentchaos512.gear.api.part.PartType)3 TraitInstance (net.silentchaos512.gear.api.traits.TraitInstance)3 java.util (java.util)2 FriendlyByteBuf (net.minecraft.network.FriendlyByteBuf)2 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)2 GsonHelper (net.minecraft.util.GsonHelper)2