Search in sources :

Example 1 with StatInstance

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

the class MaterialInstance method getStatModifiers.

@Override
public Collection<StatInstance> getStatModifiers(PartType partType, StatGearKey key, ItemStack gear) {
    List<StatInstance> mods = new ArrayList<>(material.getStatModifiers(this, partType, key, gear));
    ItemStat stat = ItemStats.get(key.getStat());
    if (stat == null) {
        SilentGear.LOGGER.warn("Unknown item stat: {}", key.getStat().getStatId());
        SilentGear.LOGGER.catching(new NullPointerException());
        return mods;
    }
    // Material modifiers (grades, starcharged, etc.)
    for (IMaterialModifier materialModifier : getModifiers()) {
        mods = materialModifier.modifyStats(partType, key, mods);
    }
    GetMaterialStatsEvent event = new GetMaterialStatsEvent(this, stat, partType, mods);
    MinecraftForge.EVENT_BUS.post(event);
    return event.getModifiers();
}
Also used : StatInstance(net.silentchaos512.gear.api.stats.StatInstance) IMaterialModifier(net.silentchaos512.gear.api.material.modifier.IMaterialModifier) GetMaterialStatsEvent(net.silentchaos512.gear.api.event.GetMaterialStatsEvent) ItemStat(net.silentchaos512.gear.api.stats.ItemStat)

Example 2 with StatInstance

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

the class GradeMaterialModifier method modifyStats.

@Override
public List<StatInstance> modifyStats(PartType partType, StatGearKey key, List<StatInstance> statMods) {
    if (key.getStat().isAffectedByGrades() && grade != null) {
        float bonus = grade.bonusPercent / 100f;
        List<StatInstance> ret = new ArrayList<>();
        // Apply grade bonus to all modifiers. Makes it easier to see the effect on rods and such.
        for (StatInstance mod : statMods) {
            float value = mod.getValue();
            // Taking the abs of value times bonus makes negative mods become less negative
            ret.add(mod.copySetValue(value + Math.abs(value) * bonus));
        }
        return ret;
    }
    return statMods;
}
Also used : ArrayList(java.util.ArrayList) StatInstance(net.silentchaos512.gear.api.stats.StatInstance)

Example 3 with StatInstance

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

the class StarchargedMaterialModifier method modifyStats.

@Override
public List<StatInstance> modifyStats(PartType partType, StatGearKey key, List<StatInstance> statMods) {
    List<StatInstance> ret = new ArrayList<>();
    if (key.getStat() == ItemStats.CHARGEABILITY) {
        return ret;
    }
    for (StatInstance mod : statMods) {
        StatInstance newMod = modifyStat(key, mod, getChargedProperties());
        ret.add(newMod != null ? newMod : mod);
    }
    return ret;
}
Also used : ArrayList(java.util.ArrayList) StatInstance(net.silentchaos512.gear.api.stats.StatInstance)

Example 4 with StatInstance

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

the class AbstractGearPart method getStatModifiers.

@Override
public Collection<StatInstance> getStatModifiers(IPartData part, PartType partType, StatGearKey key, ItemStack gear) {
    List<StatInstance> mods = new ArrayList<>(this.stats.get(key));
    GetStatModifierEvent event = new GetStatModifierEvent((PartData) part, (ItemStat) key.getStat(), mods);
    MinecraftForge.EVENT_BUS.post(event);
    return event.getModifiers();
}
Also used : GetStatModifierEvent(net.silentchaos512.gear.api.event.GetStatModifierEvent)

Example 5 with StatInstance

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

the class CompoundPart method getStatModifiers.

@Override
public Collection<StatInstance> getStatModifiers(IPartData part, PartType partType, StatGearKey key, ItemStack gear) {
    // Get the materials and all the stat modifiers they provide for this stat
    List<IMaterialInstance> materials = getMaterials(part);
    List<StatInstance> statMods = materials.stream().flatMap(m -> m.getStatModifiers(partType, key).stream()).collect(Collectors.toList());
    // Get any base modifiers for this part (could be none)
    statMods.addAll(this.stats.get(key));
    if (statMods.isEmpty()) {
        // No modifiers for this stat, so doing anything else is pointless
        return statMods;
    }
    GetStatModifierEvent event = new GetStatModifierEvent((PartData) part, (ItemStat) key.getStat(), statMods);
    MinecraftForge.EVENT_BUS.post(event);
    // Average together all modifiers of the same op. This makes things like rods with varying
    // numbers of materials more "sane".
    List<StatInstance> ret = new ArrayList<>(event.getModifiers());
    for (StatInstance.Operation op : StatInstance.Operation.values()) {
        Collection<StatInstance> modsForOp = ret.stream().filter(s -> s.getOp() == op).collect(Collectors.toList());
        if (modsForOp.size() > 1) {
            StatInstance mod = compressModifiers(modsForOp, op, key);
            ret.removeIf(inst -> inst.getOp() == op);
            ret.add(mod);
        }
    }
    // Synergy
    if (key.getStat().doesSynergyApply()) {
        final float synergy = SynergyUtils.getSynergy(this.partType, materials, getTraits(part, PartGearKey.of(gearType, partType), gear));
        if (!MathUtils.floatsEqual(synergy, 1.0f)) {
            final float multi = synergy - 1f;
            for (int i = 0; i < ret.size(); ++i) {
                StatInstance oldMod = ret.get(i);
                float value = oldMod.getValue();
                // Taking the abs of value times multi makes negative mods become less negative
                StatInstance newMod = oldMod.copySetValue(value + Math.abs(value) * multi);
                ret.remove(i);
                ret.add(i, newMod);
            }
        }
    }
    return ret;
}
Also used : JsonParseException(com.google.gson.JsonParseException) ResourceLocation(net.minecraft.resources.ResourceLocation) SilentGear(net.silentchaos512.gear.SilentGear) JsonObject(com.google.gson.JsonObject) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance) GearHelper(net.silentchaos512.gear.util.GearHelper) MaterialManager(net.silentchaos512.gear.gear.material.MaterialManager) FriendlyByteBuf(net.minecraft.network.FriendlyByteBuf) PartGearKey(net.silentchaos512.gear.api.util.PartGearKey) Function(java.util.function.Function) ArrayList(java.util.ArrayList) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem) IPartData(net.silentchaos512.gear.api.part.IPartData) GsonHelper(net.minecraft.util.GsonHelper) ColorUtils(net.silentchaos512.gear.client.util.ColorUtils) Nullable(javax.annotation.Nullable) StatInstance(net.silentchaos512.gear.api.stats.StatInstance) ItemStat(net.silentchaos512.gear.api.stats.ItemStat) Component(net.minecraft.network.chat.Component) StatGearKey(net.silentchaos512.gear.api.util.StatGearKey) MathUtils(net.silentchaos512.utils.MathUtils) Collection(java.util.Collection) SynergyUtils(net.silentchaos512.gear.util.SynergyUtils) Collectors(java.util.stream.Collectors) PartType(net.silentchaos512.gear.api.part.PartType) GearType(net.silentchaos512.gear.api.item.GearType) IMaterial(net.silentchaos512.gear.api.material.IMaterial) MinecraftForge(net.minecraftforge.common.MinecraftForge) List(java.util.List) IPartSerializer(net.silentchaos512.gear.api.part.IPartSerializer) IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) MaterialList(net.silentchaos512.gear.api.material.MaterialList) TraitInstance(net.silentchaos512.gear.api.traits.TraitInstance) GetStatModifierEvent(net.silentchaos512.gear.api.event.GetStatModifierEvent) ItemStack(net.minecraft.world.item.ItemStack) TraitHelper(net.silentchaos512.gear.util.TraitHelper) CompoundPartItem(net.silentchaos512.gear.item.CompoundPartItem) Collections(java.util.Collections) GetStatModifierEvent(net.silentchaos512.gear.api.event.GetStatModifierEvent) IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) ArrayList(java.util.ArrayList) StatInstance(net.silentchaos512.gear.api.stats.StatInstance)

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