Search in sources :

Example 26 with MaterialLayer

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

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

Example 28 with MaterialLayer

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

the class GearModel method bake.

@SuppressWarnings("MethodWithTooManyParameters")
public BakedModel bake(ItemStack stack, List<MaterialLayer> layers, int animationFrame, String transformVariant, IModelConfiguration owner, ModelBakery bakery, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelTransform, ItemOverrides overrideList, ResourceLocation modelLocation) {
    ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
    Transformation rotation = modelTransform.getRotation();
    ImmutableMap<ItemTransforms.TransformType, Transformation> transforms = PerspectiveMapWrapper.getTransforms(modelTransform);
    boolean broken = GearHelper.isBroken(stack);
    for (int i = 0; i < layers.size(); i++) {
        MaterialLayer layer = layers.get(i);
        Material renderMaterial = getTexture(layer, animationFrame, broken);
        TextureAtlasSprite texture = spriteGetter.apply(renderMaterial);
        builder.addAll(getQuadsForSprite(i, texture, rotation, layer.getColor()));
        if (GearModelOverrideList.isDebugLoggingEnabled()) {
            SilentGear.LOGGER.info("  - {} -> {}", layer.getTextureId(), renderMaterial.texture());
        }
    }
    // No layers?
    if (layers.isEmpty()) {
        if (Const.Materials.EXAMPLE.isPresent()) {
            buildFakeModel(spriteGetter, builder, rotation, Const.Materials.EXAMPLE.get());
        } else {
            // Shouldn't happen, but...
            SilentGear.LOGGER.error("Example material is missing?");
            TextureAtlasSprite texture = spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, SilentGear.getId("item/error")));
            builder.addAll(getQuadsForSprite(0, texture, rotation, 0xFFFFFF));
        }
    }
    TextureAtlasSprite particle = spriteGetter.apply(owner.resolveTexture("particle"));
    return new BakedPerspectiveModel(builder.build(), particle, transforms, overrideList, rotation.isIdentity(), owner.isSideLit(), getCameraTransforms(transformVariant));
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) BakedPerspectiveModel(net.silentchaos512.gear.client.model.BakedPerspectiveModel) Transformation(com.mojang.math.Transformation) ImmutableList(com.google.common.collect.ImmutableList) MaterialLayer(net.silentchaos512.gear.api.material.MaterialLayer) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) IMaterial(net.silentchaos512.gear.api.material.IMaterial)

Example 29 with MaterialLayer

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

the class GearModel method buildFakeModel.

private void buildFakeModel(Function<Material, TextureAtlasSprite> spriteGetter, ImmutableList.Builder<BakedQuad> builder, Transformation rotation, IMaterial material) {
    // This method will display an example tool for items with no data (ie, for advancements)
    MaterialInstance mat = MaterialInstance.of(material);
    IMaterialDisplay model = mat.getDisplayProperties();
    if (!gearType.isArmor()) {
        MaterialLayer exampleRod = model.getLayerList(this.gearType, PartType.ROD, mat).getFirstLayer();
        if (exampleRod != null) {
            builder.addAll(getQuadsForSprite(0, spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, exampleRod.getTexture(gearType, 0))), rotation, exampleRod.getColor()));
        }
    }
    MaterialLayer exampleMain = model.getLayerList(this.gearType, PartType.MAIN, mat).getFirstLayer();
    if (exampleMain != null) {
        builder.addAll(getQuadsForSprite(0, spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, exampleMain.getTexture(gearType, 0))), rotation, exampleMain.getColor()));
    }
    if (gearType.matches(GearType.RANGED_WEAPON)) {
        MaterialLayer exampleBowstring = model.getLayerList(this.gearType, PartType.CORD, mat).getFirstLayer();
        if (exampleBowstring != null) {
            builder.addAll(getQuadsForSprite(0, spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, exampleBowstring.getTexture(gearType, 0))), rotation, exampleBowstring.getColor()));
        }
    }
}
Also used : IMaterialDisplay(net.silentchaos512.gear.api.material.IMaterialDisplay) MaterialLayer(net.silentchaos512.gear.api.material.MaterialLayer) IMaterial(net.silentchaos512.gear.api.material.IMaterial) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance) LazyMaterialInstance(net.silentchaos512.gear.gear.material.LazyMaterialInstance)

Aggregations

MaterialLayer (net.silentchaos512.gear.api.material.MaterialLayer)27 IMaterialDisplay (net.silentchaos512.gear.api.material.IMaterialDisplay)12 IMaterial (net.silentchaos512.gear.api.material.IMaterial)9 ResourceLocation (net.minecraft.resources.ResourceLocation)6 MaterialInstance (net.silentchaos512.gear.gear.material.MaterialInstance)6 ArrayList (java.util.ArrayList)4 ImmutableList (com.google.common.collect.ImmutableList)3 Transformation (com.mojang.math.Transformation)3 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)3 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)3 IMaterialInstance (net.silentchaos512.gear.api.material.IMaterialInstance)3 StaticLayer (net.silentchaos512.gear.api.material.StaticLayer)3 PartType (net.silentchaos512.gear.api.part.PartType)3 BakedPerspectiveModel (net.silentchaos512.gear.client.model.BakedPerspectiveModel)3 LazyMaterialInstance (net.silentchaos512.gear.gear.material.LazyMaterialInstance)3 GearType (net.silentchaos512.gear.api.item.GearType)2 MaterialLayerList (net.silentchaos512.gear.api.material.MaterialLayerList)2 IPartDisplay (net.silentchaos512.gear.api.part.IPartDisplay)2 PartTextures (net.silentchaos512.gear.client.model.PartTextures)2 PartData (net.silentchaos512.gear.gear.part.PartData)2