Search in sources :

Example 6 with MaterialLayer

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

the class CompoundPartModelOverrideList method getOverrideModel.

private BakedModel getOverrideModel(ItemStack stack, @Nullable ClientLevel worldIn, @Nullable LivingEntity entityIn) {
    List<MaterialLayer> layers = new ArrayList<>();
    PartData part = PartData.from(stack);
    MaterialInstance primaryMaterial = CompoundPartItem.getPrimaryMaterial(stack);
    if (part != null && primaryMaterial != null) {
        addWithBlendedColor(layers, part, primaryMaterial, stack);
    }
    return model.bake(layers, "test", owner, bakery, spriteGetter, modelTransform, this, modelLocation);
}
Also used : MaterialLayer(net.silentchaos512.gear.api.material.MaterialLayer) ArrayList(java.util.ArrayList) PartData(net.silentchaos512.gear.gear.part.PartData) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance)

Example 7 with MaterialLayer

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

the class FragmentModel method buildFakeModel.

private void buildFakeModel(Function<Material, TextureAtlasSprite> spriteGetter, ImmutableList.Builder<BakedQuad> builder, Transformation rotation, IMaterial material) {
    // This method will display an example item for items with no data (ie, for advancements)
    MaterialInstance mat = MaterialInstance.of(material);
    IMaterialDisplay model = mat.getDisplayProperties();
    MaterialLayer exampleMain = model.getLayerList(GearType.FRAGMENT, PartType.MAIN, mat).getFirstLayer();
    if (exampleMain != null) {
        builder.addAll(getQuadsForSprite(0, spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, exampleMain.getTexture(GearType.FRAGMENT, 0))), rotation, exampleMain.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)

Example 8 with MaterialLayer

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

the class FragmentModel method bake.

@SuppressWarnings("MethodWithTooManyParameters")
public BakedModel bake(List<MaterialLayer> layers, IModelConfiguration owner, ModelBakery bakery, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelTransform, FragmentModelOverrideList fragmentModelOverrideList, ResourceLocation modelLocation) {
    ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
    Transformation rotation = modelTransform.getRotation();
    ImmutableMap<ItemTransforms.TransformType, Transformation> transforms = PerspectiveMapWrapper.getTransforms(modelTransform);
    for (int i = 0; i < layers.size(); i++) {
        MaterialLayer layer = layers.get(i);
        TextureAtlasSprite texture = spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, layer.getTexture(GearType.FRAGMENT, 0)));
        builder.addAll(getQuadsForSprite(i, texture, rotation, layer.getColor()));
    }
    // 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(), cameraTransforms);
}
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 9 with MaterialLayer

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

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

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