Search in sources :

Example 11 with IMaterialDisplay

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

the class GearArmorItem method getArmorTexture.

// endregion
// region Client-side methods and rendering horrors
@Override
public String getArmorTexture(ItemStack stack, Entity entity, EquipmentSlot slot, String type) {
    // Empty texture if broken
    if (GearHelper.isBroken(stack))
        return SilentGear.MOD_ID + ":textures/models/armor/empty.png";
    int layer = slot == EquipmentSlot.LEGS ? 2 : 1;
    // Overlay - default to a blank texture
    if ("overlay".equals(type))
        return SilentGear.MOD_ID + ":textures/models/armor/all_layer_" + layer + "_overlay.png";
    // New material-based armor
    MaterialInstance material = GearData.getPrimaryArmorMaterial(stack);
    if (material != null) {
        IMaterialDisplay materialModel = material.getDisplayProperties();
        PartType partType = GearData.hasPartOfType(stack, PartType.COATING) ? PartType.COATING : PartType.MAIN;
        MaterialLayer materialLayer = materialModel.getLayerList(this.getGearType(), partType, material).getFirstLayer();
        if (materialLayer != null) {
            ResourceLocation tex = materialLayer.getTextureId();
            return tex.getNamespace() + ":textures/models/armor/" + tex.getPath() + "_layer_" + layer + (type != null ? "_" + type : "") + ".png";
        }
    }
    return "silentgear:textures/models/armor/main_generic_hc_layer_" + layer + (type != null ? "_" + type : "") + ".png";
}
Also used : PartType(net.silentchaos512.gear.api.part.PartType) IMaterialDisplay(net.silentchaos512.gear.api.material.IMaterialDisplay) MaterialLayer(net.silentchaos512.gear.api.material.MaterialLayer) ResourceLocation(net.minecraft.resources.ResourceLocation) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance)

Example 12 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(CompoundPartItem 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(item.getGearType(), item.getPartType(), mat).getLayers();
        if (layers.size() > layer) {
            int color = model.getLayerColor(item.getGearType(), item.getPartType(), mat, layer);
            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)

Example 13 with IMaterialDisplay

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

the class CompoundPartModel method getTextures.

@Override
public Collection<Material> getTextures(IModelConfiguration owner, Function<ResourceLocation, UnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors) {
    Set<Material> ret = new HashSet<>();
    if (this.gearType == GearType.SHIELD) {
        // Unobtainable part items, no need for textures
        return ret;
    }
    // Generic built-in textures
    for (PartTextures tex : PartTextures.getTextures(this.gearType)) {
        ret.add(getTexture(tex.getTexture()));
    }
    // Custom textures
    for (IMaterialDisplay materialDisplay : GearDisplayManager.getMaterials()) {
        for (MaterialLayer layer : materialDisplay.getLayerList(this.gearType, this.partType, LazyMaterialInstance.of(materialDisplay.getMaterialId()))) {
            ret.add(getTexture(layer));
        }
    }
    for (ResourceLocation texture : this.extraLayers) {
        ret.add(getTexture(new StaticLayer(texture)));
    }
    ret.add(getTexture(new StaticLayer(PART_MARKER_TEXTURE)));
    ret.add(new Material(InventoryMenu.BLOCK_ATLAS, SilentGear.getId("item/error")));
    if (CompoundPartModelOverrideList.isDebugLoggingEnabled()) {
        SilentGear.LOGGER.info("Textures for compound part model '{}'", PartGearKey.of(this.gearType, this.partType));
        for (Material mat : ret) {
            SilentGear.LOGGER.info("- {}", mat.texture());
        }
    }
    return ret;
}
Also used : PartTextures(net.silentchaos512.gear.client.model.PartTextures) IMaterialDisplay(net.silentchaos512.gear.api.material.IMaterialDisplay) MaterialLayer(net.silentchaos512.gear.api.material.MaterialLayer) ResourceLocation(net.minecraft.resources.ResourceLocation) ModResourceLocation(net.silentchaos512.gear.util.ModResourceLocation) IMaterial(net.silentchaos512.gear.api.material.IMaterial) StaticLayer(net.silentchaos512.gear.api.material.StaticLayer)

Example 14 with IMaterialDisplay

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

the class CompoundPartModelOverrideList method addWithBlendedColor.

@SuppressWarnings("TypeMayBeWeakened")
private void addWithBlendedColor(List<MaterialLayer> list, PartData part, MaterialInstance material, ItemStack stack) {
    IMaterialDisplay materialModel = material.getDisplayProperties();
    List<MaterialLayer> layers = materialModel.getLayerList(this.model.gearType, part, material).getLayers();
    for (int i = 0; i < layers.size(); i++) {
        MaterialLayer layer = layers.get(i);
        if ((layer.getColor() & 0xFFFFFF) < 0xFFFFFF) {
            int blendedColor = part.getColor(stack, i, 0);
            list.add(new MaterialLayer(layer.getTextureId(), part.getType(), blendedColor, false));
        } else {
            list.add(layer);
        }
    }
}
Also used : IMaterialDisplay(net.silentchaos512.gear.api.material.IMaterialDisplay) MaterialLayer(net.silentchaos512.gear.api.material.MaterialLayer)

Example 15 with IMaterialDisplay

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

the class FragmentModelOverrideList method getOverrideModel.

private BakedModel getOverrideModel(ItemStack stack, @Nullable ClientLevel worldIn, @Nullable LivingEntity entityIn) {
    List<MaterialLayer> layers = new ArrayList<>();
    IMaterialInstance material = FragmentItem.getMaterial(stack);
    if (material != null) {
        IMaterialDisplay model = material.getDisplayProperties();
        int layerLevel = 0;
        for (MaterialLayer layer : model.getLayerList(GearType.FRAGMENT, PartType.MAIN, material)) {
            int blendedColor = model.getLayerColor(GearType.FRAGMENT, PartType.MAIN, material, layerLevel);
            layers.add(new MaterialLayer(layer.getTextureId(), blendedColor));
            ++layerLevel;
        }
    }
    return model.bake(layers, owner, bakery, spriteGetter, modelTransform, this, modelLocation);
}
Also used : IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) IMaterialDisplay(net.silentchaos512.gear.api.material.IMaterialDisplay) MaterialLayer(net.silentchaos512.gear.api.material.MaterialLayer) ArrayList(java.util.ArrayList)

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