Search in sources :

Example 1 with CompoundMaterialItem

use of net.silentchaos512.gear.item.CompoundMaterialItem 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;
}
Also used : ItemStack(net.minecraft.world.item.ItemStack) CompoundMaterialItem(net.silentchaos512.gear.item.CompoundMaterialItem)

Example 2 with CompoundMaterialItem

use of net.silentchaos512.gear.item.CompoundMaterialItem 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);
}
Also used : IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) IMaterialDisplay(net.silentchaos512.gear.api.material.IMaterialDisplay) MaterialLayer(net.silentchaos512.gear.api.material.MaterialLayer)

Aggregations

ItemStack (net.minecraft.world.item.ItemStack)1 IMaterialDisplay (net.silentchaos512.gear.api.material.IMaterialDisplay)1 IMaterialInstance (net.silentchaos512.gear.api.material.IMaterialInstance)1 MaterialLayer (net.silentchaos512.gear.api.material.MaterialLayer)1 CompoundMaterialItem (net.silentchaos512.gear.item.CompoundMaterialItem)1