use of net.silentchaos512.gear.api.part.IPartData in project Silent-Gear by SilentChaos512.
the class GearHelper method getExamplePartsFromRecipe.
public static Collection<IPartData> getExamplePartsFromRecipe(GearType gearType, Iterable<Ingredient> ingredients) {
Map<PartType, IPartData> map = new LinkedHashMap<>();
PartType.MAIN.makeCompoundPart(gearType, Const.Materials.EXAMPLE).ifPresent(p -> map.put(PartType.MAIN, p));
for (Ingredient ingredient : ingredients) {
if (ingredient instanceof IGearIngredient) {
PartType type = ((IGearIngredient) ingredient).getPartType();
type.makeCompoundPart(gearType, Const.Materials.EXAMPLE).ifPresent(p -> map.put(type, p));
}
}
return map.values();
}
use of net.silentchaos512.gear.api.part.IPartData in project Silent-Gear by SilentChaos512.
the class GearHelper method createSampleItem.
private static ItemStack createSampleItem(ICoreItem item, int tier) {
ItemStack result = GearGenerator.create(item, tier);
if (result.isEmpty()) {
Collection<IPartData> parts = new ArrayList<>();
for (PartType partType : item.getRequiredParts()) {
partType.makeCompoundPart(item.getGearType(), Const.Materials.EXAMPLE).ifPresent(parts::add);
}
result = item.construct(parts);
}
GearData.setExampleTag(result, true);
return result;
}
use of net.silentchaos512.gear.api.part.IPartData in project Silent-Gear by SilentChaos512.
the class ConversionRecipe method getParts.
private Collection<? extends IPartData> getParts() {
PartDataList ret = PartDataList.of();
// noinspection OverlyLongLambda
this.resultMaterials.forEach((partType, list) -> {
partType.getCompoundPartItem(item.getGearType()).ifPresent(partItem -> {
PartData part = PartData.from(partItem.create(list));
if (part != null) {
ret.add(part);
}
});
});
return ret;
}
use of net.silentchaos512.gear.api.part.IPartData in project Silent-Gear by SilentChaos512.
the class ColorUtils method getBlendedColor.
public static int getBlendedColor(ICoreItem item, IPartData part, Collection<? extends IMaterialInstance> materials, int layer) {
int[] componentSums = new int[3];
int maxColorSum = 0;
int colorCount = 0;
int i = 0;
for (IMaterialInstance mat : materials) {
IMaterialDisplay model = mat.getDisplayProperties();
int color = model.getLayerColor(item.getGearType(), part, mat, layer);
int r = (color >> 16) & 0xFF;
int g = (color >> 8) & 0xFF;
int b = color & 0xFF;
int colorWeight = (materials.size() - i) * (materials.size() - i);
for (int j = 0; j < colorWeight; ++j) {
maxColorSum += Math.max(r, Math.max(g, b));
componentSums[0] += r;
componentSums[1] += g;
componentSums[2] += b;
++colorCount;
}
++i;
}
return blendColors(componentSums, maxColorSum, colorCount);
}
use of net.silentchaos512.gear.api.part.IPartData in project Silent-Gear by SilentChaos512.
the class ICoreItem method construct.
// region Item properties and construction
default ItemStack construct(Collection<? extends IPartData> parts) {
ItemStack result = new ItemStack(this);
GearData.writeConstructionParts(result, parts);
parts.forEach(p -> p.onAddToGear(result));
GearData.recalculateStats(result, null);
// Allow traits to make any needed changes (must be done after a recalculate)
TraitHelper.activateTraits(result, 0, (trait, level, nothing) -> {
trait.onGearCrafted(new TraitActionContext(null, level, result));
return 0;
});
return result;
}
Aggregations