use of net.silentchaos512.gear.gear.material.MaterialInstance in project Silent-Gear by SilentChaos512.
the class CompoundPart method getRandomMaterials.
private List<MaterialInstance> getRandomMaterials(GearType gearType, int count, int tier) {
// Excludes children, will select a random child material (if appropriate) below
List<IMaterial> matsOfTier = MaterialManager.getValues(tier == 0).stream().map(MaterialInstance::of).filter(m -> tier < 0 || tier == m.getTier(this.partType)).filter(m -> m.allowedInPart(this.partType) && m.isCraftingAllowed(this.partType, gearType)).map(MaterialInstance::get).collect(Collectors.toList());
if (!matsOfTier.isEmpty()) {
List<MaterialInstance> ret = new ArrayList<>();
for (int i = 0; i < count; ++i) {
IMaterial material = matsOfTier.get(SilentGear.RANDOM.nextInt(matsOfTier.size()));
ret.add(getRandomChildMaterial(material));
}
return ret;
}
if (tier == -1) {
// Something went wrong...
return Collections.emptyList();
}
// No materials of tier? Select randoms of any tier.
return getRandomMaterials(gearType, count, -1);
}
use of net.silentchaos512.gear.gear.material.MaterialInstance in project Silent-Gear by SilentChaos512.
the class CompoundPart method randomizeData.
@Override
public PartData randomizeData(GearType gearType, int tier) {
for (ItemStack stack : this.getIngredient().getItems()) {
if (stack.getItem() instanceof CompoundPartItem) {
int materialCount = getRandomMaterialCount(partType);
List<MaterialInstance> materials = getRandomMaterials(gearType, materialCount, tier);
ItemStack craftingItem = ((CompoundPartItem) stack.getItem()).create(materials);
return PartData.of(this, craftingItem);
}
}
return super.randomizeData(gearType, tier);
}
use of net.silentchaos512.gear.gear.material.MaterialInstance in project Silent-Gear by SilentChaos512.
the class RepairHandler method onAnvilUpdate.
@SubscribeEvent
public static void onAnvilUpdate(AnvilUpdateEvent event) {
if (event.getLeft().getItem() instanceof ICoreItem) {
MaterialInstance material = MaterialInstance.from(event.getRight());
PartData part = PartData.from(event.getRight());
if (material != null) {
handleGearRepair(event, material);
} else if (part != null && part.get() instanceof UpgradePart) {
handleUpgradeApplication(event, part);
}
}
}
use of net.silentchaos512.gear.gear.material.MaterialInstance 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.gear.material.MaterialInstance in project Silent-Gear by SilentChaos512.
the class MaterialList method deserializeNbt.
public static MaterialList deserializeNbt(ListTag listNbt) {
MaterialList ret = new MaterialList();
for (int i = 0; i < listNbt.size(); ++i) {
CompoundTag compoundNbt = listNbt.getCompound(i);
MaterialInstance material = MaterialInstance.read(compoundNbt);
if (material != null) {
int count = compoundNbt.contains("Count") ? compoundNbt.getByte("Count") : 1;
for (int j = 0; j < count; ++j) {
ret.list.add(material);
}
}
}
return ret;
}
Aggregations