use of net.silentchaos512.gear.api.stats.StatInstance in project Silent-Gear by SilentChaos512.
the class CompoundMaterial method getStatModifiers.
@SuppressWarnings("OverlyComplexMethod")
@Override
public Collection<StatInstance> getStatModifiers(IMaterialInstance material, PartType partType, StatGearKey key, ItemStack gear) {
// Get the materials and all the stat modifiers they provide for this stat
Collection<IMaterialInstance> materials = getMaterials(material);
List<StatInstance> statMods = materials.stream().map(AbstractMaterial::removeEnhancements).flatMap(m -> m.getStatModifiers(partType, key).stream()).collect(Collectors.toList());
ItemStat stat = key.getStat() instanceof ItemStat ? (ItemStat) key.getStat() : null;
if (stat == null || statMods.isEmpty()) {
// No modifiers for this stat, so doing anything else is pointless
return statMods;
}
MaterialInstance matInst = material instanceof MaterialInstance ? (MaterialInstance) material : null;
GetMaterialStatsEvent event = null;
if (matInst != null) {
// FIXME: Potentially bad cast, need to rework event
event = new GetMaterialStatsEvent(matInst, stat, partType, 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 != null ? event.getModifiers() : Collections.emptyList());
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 (stat.doesSynergyApply() && matInst != null) {
final float synergy = SynergyUtils.getSynergy(partType, new ArrayList<>(materials), getTraits(matInst, PartGearKey.ofAll(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;
}
use of net.silentchaos512.gear.api.stats.StatInstance in project Silent-Gear by SilentChaos512.
the class CraftedMaterial method getStatModifiers.
@Override
public Collection<StatInstance> getStatModifiers(IMaterialInstance material, PartType partType, StatGearKey key, ItemStack gear) {
Collection<StatInstance> ret = super.getStatModifiers(material, partType, key, gear);
IMaterialInstance base = getBaseMaterial(material);
ret.addAll(base.getStatModifiers(partType, key, gear));
return ret;
}
use of net.silentchaos512.gear.api.stats.StatInstance 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);
}
use of net.silentchaos512.gear.api.stats.StatInstance in project Silent-Gear by SilentChaos512.
the class StatModifierMap method read.
public static StatModifierMap read(FriendlyByteBuf buffer) {
StatModifierMap map = new StatModifierMap();
int count = buffer.readVarInt();
for (int i = 0; i < count; ++i) {
StatGearKey key = StatGearKey.read(buffer);
StatInstance instance = StatInstance.read(key, buffer);
map.put(key, instance);
}
return map;
}
use of net.silentchaos512.gear.api.stats.StatInstance in project Silent-Gear by SilentChaos512.
the class StatModifierMap method serialize.
public JsonObject serialize() {
JsonObject json = new JsonObject();
for (StatGearKey key : this.keySet()) {
Collection<StatInstance> mods = this.get(key);
if (mods.size() > 1) {
JsonArray array = new JsonArray();
mods.forEach(mod -> array.add(mod.serialize()));
json.add(key.toString(), array);
} else if (mods.size() == 1) {
json.add(key.toString(), mods.iterator().next().serialize());
}
}
return json;
}
Aggregations