use of net.silentchaos512.gear.api.material.IMaterialInstance in project Silent-Gear by SilentChaos512.
the class ConversionRecipe method deserializeMaterials.
private static void deserializeMaterials(JsonObject json, ConversionRecipe recipe) {
JsonObject resultJson = json.getAsJsonObject("result");
for (Map.Entry<String, JsonElement> entry : resultJson.getAsJsonObject("materials").entrySet()) {
PartType partType = PartType.get(Objects.requireNonNull(SilentGear.getIdWithDefaultNamespace(entry.getKey())));
JsonElement element = entry.getValue();
if (element.isJsonArray()) {
List<IMaterialInstance> list = new ArrayList<>();
for (JsonElement e : element.getAsJsonArray()) {
list.add(LazyMaterialInstance.deserialize(e.getAsJsonObject()));
}
recipe.resultMaterials.put(partType, list);
} else {
recipe.resultMaterials.put(partType, Collections.singletonList(LazyMaterialInstance.deserialize(element.getAsJsonObject())));
}
}
}
use of net.silentchaos512.gear.api.material.IMaterialInstance in project Silent-Gear by SilentChaos512.
the class FillRepairKitRecipe method isRepairMaterial.
private static boolean isRepairMaterial(IMaterialInstance material) {
float durability = material.getStat(PartType.MAIN, ItemStats.DURABILITY);
float armorDurability = material.getStat(PartType.MAIN, ItemStats.ARMOR_DURABILITY);
IMaterial mat = material.get();
return mat != null && mat.allowedInPart(material, PartType.MAIN) && (durability > 0 || armorDurability > 0);
}
use of net.silentchaos512.gear.api.material.IMaterialInstance 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.material.IMaterialInstance in project Silent-Gear by SilentChaos512.
the class ColorUtils method getBlendedColor.
public static int getBlendedColor(CompoundMaterialItem item, 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();
List<MaterialLayer> layers = model.getLayerList(GearType.ALL, PartType.MAIN, mat).getLayers();
if (layers.size() > layer) {
int color = layers.get(layer).getColor();
int r = (color >> 16) & 0xFF;
int g = (color >> 8) & 0xFF;
int b = color & 0xFF;
int colorWeight = item.getColorWeight(i, materials.size());
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.material.IMaterialInstance in project Silent-Gear by SilentChaos512.
the class AbstractMaterial method isCraftingAllowed.
@Override
public boolean isCraftingAllowed(IMaterialInstance material, PartType partType, GearType gearType, @Nullable Container inventory) {
if (isGearTypeBlacklisted(gearType) || !allowedInPart(material, partType)) {
return false;
}
if (stats.containsKey(partType) || (getParent() != null && getParent().isCraftingAllowed(material, partType, gearType, inventory))) {
if (partType == PartType.MAIN) {
ItemStat stat = gearType.getDurabilityStat();
StatGearKey key = StatGearKey.of(stat, gearType);
return !getStatModifiers(material, partType, key).isEmpty() && getStatUnclamped(material, partType, key, ItemStack.EMPTY) > 0;
}
return true;
}
return false;
}
Aggregations