Search in sources :

Example 6 with IMaterialDisplay

use of net.silentchaos512.gear.api.material.IMaterialDisplay in project Silent-Gear by SilentChaos512.

the class FragmentModel method getTextures.

@Override
public Collection<Material> getTextures(IModelConfiguration owner, Function<ResourceLocation, UnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors) {
    Set<Material> ret = new HashSet<>();
    ret.add(new Material(InventoryMenu.BLOCK_ATLAS, SilentGear.getId("item/error")));
    // Generic built-in textures
    ret.add(getTexture(PartTextures.CLOTH.getTexture()));
    ret.add(getTexture(PartTextures.METAL.getTexture()));
    ret.add(getTexture(PartTextures.WOOD.getTexture()));
    // Custom textures
    for (IMaterialDisplay materialDisplay : GearDisplayManager.getMaterials()) {
        for (MaterialLayer layer : materialDisplay.getLayerList(GearType.FRAGMENT, PartType.MAIN, LazyMaterialInstance.of(materialDisplay.getMaterialId()))) {
            ret.add(getTexture(layer));
        }
    }
    SilentGear.LOGGER.info("Textures for fragment model");
    for (Material mat : ret) {
        SilentGear.LOGGER.info("- {}", mat.texture());
    }
    return ret;
}
Also used : IMaterialDisplay(net.silentchaos512.gear.api.material.IMaterialDisplay) MaterialLayer(net.silentchaos512.gear.api.material.MaterialLayer) IMaterial(net.silentchaos512.gear.api.material.IMaterial)

Example 7 with IMaterialDisplay

use of net.silentchaos512.gear.api.material.IMaterialDisplay in project Silent-Gear by SilentChaos512.

the class GearModel method getTextures.

@SuppressWarnings("OverlyComplexMethod")
@Override
public Collection<Material> getTextures(IModelConfiguration owner, Function<ResourceLocation, UnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors) {
    Set<Material> ret = new HashSet<>();
    ret.add(new Material(InventoryMenu.BLOCK_ATLAS, SilentGear.getId("item/error")));
    // Generic built-in textures
    for (PartTextures tex : PartTextures.getTextures(this.gearType)) {
        int animationFrames = tex.isAnimated() ? item.getAnimationFrames() : 1;
        for (int i = 0; i < animationFrames; ++i) {
            MaterialLayer layer = new MaterialLayer(tex, Color.VALUE_WHITE);
            ret.add(getTexture(layer, i, false));
            ret.add(getTexture(layer, 0, true));
        }
    }
    // Custom textures
    for (IMaterialDisplay materialDisplay : GearDisplayManager.getMaterials()) {
        for (PartType partType : PartType.getValues()) {
            if (item.hasTexturesFor(partType)) {
                for (MaterialLayer layer : materialDisplay.getLayerList(gearType, partType, LazyMaterialInstance.of(materialDisplay.getMaterialId()))) {
                    int animationFrames = layer.isAnimated() ? item.getAnimationFrames() : 1;
                    ret.addAll(this.getTexturesForAllFrames(layer, animationFrames, false));
                    ret.addAll(this.getTexturesForAllFrames(layer, 1, true));
                }
            }
        }
    }
    for (IPartDisplay partDisplay : GearDisplayManager.getParts()) {
        for (MaterialLayer layer : partDisplay.getLayers(gearType, FakePartData.of(PartType.NONE))) {
            int animationFrames = layer.isAnimated() ? item.getAnimationFrames() : 1;
            ret.addAll(this.getTexturesForAllFrames(layer, animationFrames, false));
            ret.addAll(this.getTexturesForAllFrames(layer, animationFrames, true));
        }
    }
    if (GearModelOverrideList.isDebugLoggingEnabled()) {
        SilentGear.LOGGER.info("Textures for gear model '{}' ({})", getTexturePath(false), this.gearType.getName());
        for (Material mat : ret) {
            SilentGear.LOGGER.info("- {}", mat.texture());
        }
    }
    return ret;
}
Also used : PartType(net.silentchaos512.gear.api.part.PartType) PartTextures(net.silentchaos512.gear.client.model.PartTextures) IMaterialDisplay(net.silentchaos512.gear.api.material.IMaterialDisplay) IPartDisplay(net.silentchaos512.gear.api.part.IPartDisplay) MaterialLayer(net.silentchaos512.gear.api.material.MaterialLayer) IMaterial(net.silentchaos512.gear.api.material.IMaterial)

Example 8 with IMaterialDisplay

use of net.silentchaos512.gear.api.material.IMaterialDisplay in project Silent-Gear by SilentChaos512.

the class CraftedMaterialItem method getColor.

@Override
public int getColor(ItemStack stack, int layer) {
    IMaterialInstance material = getMaterial(stack);
    IMaterialDisplay model = material.getDisplayProperties();
    return model.getLayerColor(GearType.ALL, PartType.MAIN, material, layer);
}
Also used : IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) IMaterialDisplay(net.silentchaos512.gear.api.material.IMaterialDisplay)

Example 9 with IMaterialDisplay

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

Example 10 with IMaterialDisplay

use of net.silentchaos512.gear.api.material.IMaterialDisplay 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

IMaterialDisplay (net.silentchaos512.gear.api.material.IMaterialDisplay)16 MaterialLayer (net.silentchaos512.gear.api.material.MaterialLayer)12 IMaterial (net.silentchaos512.gear.api.material.IMaterial)7 IMaterialInstance (net.silentchaos512.gear.api.material.IMaterialInstance)6 MaterialInstance (net.silentchaos512.gear.gear.material.MaterialInstance)5 ResourceLocation (net.minecraft.resources.ResourceLocation)3 LazyMaterialInstance (net.silentchaos512.gear.gear.material.LazyMaterialInstance)3 StaticLayer (net.silentchaos512.gear.api.material.StaticLayer)2 PartType (net.silentchaos512.gear.api.part.PartType)2 PartTextures (net.silentchaos512.gear.client.model.PartTextures)2 JsonObject (com.google.gson.JsonObject)1 JsonParseException (com.google.gson.JsonParseException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Resource (net.minecraft.server.packs.resources.Resource)1 GearType (net.silentchaos512.gear.api.item.GearType)1 IPartDisplay (net.silentchaos512.gear.api.part.IPartDisplay)1 ModResourceLocation (net.silentchaos512.gear.util.ModResourceLocation)1