Search in sources :

Example 1 with Operation

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

the class StatInstance method getMaterialWeightedAverageMod.

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

Example 2 with Operation

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

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

use of net.silentchaos512.gear.api.stats.StatInstance.Operation in project SilentGems by SilentChaos512.

the class ToolPartTip method getStatModifier.

@Override
public ItemStatModifier getStatModifier(ItemStat stat, EnumMaterialGrade grade) {
    float val = stats.getStat(stat);
    Operation op = ItemStatModifier.Operation.ADD;
    if (stat == CommonItemStats.ATTACK_SPEED)
        val -= 1f;
    else if (stat == CommonItemStats.HARVEST_LEVEL)
        op = ItemStatModifier.Operation.MAX;
    return new ItemStatModifier(getUnlocalizedName(), val, op);
}
Also used : ItemStatModifier(net.silentchaos512.gems.api.stats.ItemStatModifier) Operation(net.silentchaos512.gems.api.stats.ItemStatModifier.Operation)

Example 5 with Operation

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

the class ItemStat method computeForDisplay.

public StatInstance computeForDisplay(float baseValue, GearType gearType, Collection<StatInstance> modifiers) {
    if (modifiers.isEmpty()) {
        return StatInstance.of(baseValue, Operation.AVG, StatInstance.DEFAULT_KEY);
    }
    int add = 1;
    for (StatInstance inst : modifiers) {
        Operation op = inst.getOp();
        if (op == Operation.AVG || op == Operation.ADD || op == Operation.MAX) {
            add = 0;
            break;
        }
    }
    float value = compute(baseValue + add, false, gearType, modifiers) - add;
    Operation op = modifiers.iterator().next().getOp();
    return StatInstance.of(value, op, StatInstance.DEFAULT_KEY);
}
Also used : Operation(net.silentchaos512.gear.api.stats.StatInstance.Operation)

Aggregations

StatGearKey (net.silentchaos512.gear.api.util.StatGearKey)5 Multimap (com.google.common.collect.Multimap)1 MultimapBuilder (com.google.common.collect.MultimapBuilder)1 Multiset (com.google.common.collect.Multiset)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonParseException (com.google.gson.JsonParseException)1 java.util (java.util)1 Entry (java.util.Map.Entry)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 FriendlyByteBuf (net.minecraft.network.FriendlyByteBuf)1 MutableComponent (net.minecraft.network.chat.MutableComponent)1 TextComponent (net.minecraft.network.chat.TextComponent)1 GsonHelper (net.minecraft.util.GsonHelper)1 GearType (net.silentchaos512.gear.api.item.GearType)1 IGearPart (net.silentchaos512.gear.api.part.IGearPart)1 StatInstance (net.silentchaos512.gear.api.stats.StatInstance)1 Operation (net.silentchaos512.gear.api.stats.StatInstance.Operation)1