use of net.silentchaos512.gear.api.part.IPartData 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();
}
use of net.silentchaos512.gear.api.part.IPartData 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;
}
use of net.silentchaos512.gear.api.part.IPartData in project Silent-Gear by SilentChaos512.
the class CompoundPart method getTraits.
@Override
public Collection<TraitInstance> getTraits(IPartData part, PartGearKey partKey, ItemStack gear) {
List<TraitInstance> ret = new ArrayList<>(super.getTraits(part, partKey, gear));
List<IMaterialInstance> materials = getMaterials(part);
for (TraitInstance inst : TraitHelper.getTraits(materials, partKey, gear)) {
if (inst.conditionsMatch(partKey, gear, materials)) {
ret.add(inst);
}
}
return ret;
}
use of net.silentchaos512.gear.api.part.IPartData in project Silent-Gear by SilentChaos512.
the class CompoundMaterialDisplay method getLayerColor.
@Override
public int getLayerColor(GearType gearType, IPartData part, IMaterialInstance materialIn, int layer) {
List<MaterialLayer> layers = getLayerList(gearType, part, materialIn).getLayers();
if (layer < layers.size()) {
ItemStack stack = materialIn.getItem();
if (stack.getItem() instanceof CompoundMaterialItem) {
List<IMaterialInstance> subMaterials = CompoundMaterialItem.getSubMaterials(stack);
int color = ColorUtils.getBlendedColor((CompoundMaterialItem) stack.getItem(), subMaterials, layer);
// return layers.get(layer).getColor();
return color;
}
}
return Color.VALUE_WHITE;
}
use of net.silentchaos512.gear.api.part.IPartData in project Silent-Gear by SilentChaos512.
the class GearData method writeConstructionParts.
public static void writeConstructionParts(ItemStack gear, Collection<? extends IPartData> parts) {
if (checkNonGearItem(gear, "writeConstructionParts"))
return;
CompoundTag tags = getData(gear, NBT_ROOT_CONSTRUCTION);
ListTag tagList = new ListTag();
// Mains must be first in the list!
parts.stream().filter(p -> p.getType() == PartType.MAIN).map(p -> p.write(new CompoundTag())).forEach(tagList::add);
// Write everything else in any order
parts.stream().filter(p -> p.getType() != PartType.MAIN).map(p -> p.write(new CompoundTag())).forEach(tagList::add);
tags.put(NBT_CONSTRUCTION_PARTS, tagList);
}
Aggregations