Search in sources :

Example 21 with MaterialLayer

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

the class GearModelOverrideList method addSimplePartLayers.

private static void addSimplePartLayers(List<MaterialLayer> list, PartData part, ItemStack stack) {
    IPartDisplay model = GearDisplayManager.get(part.get());
    if (model != null) {
        GearType gearType = GearHelper.getType(stack);
        List<MaterialLayer> layers = model.getLayers(gearType, part).getLayers();
        addColorBlendedLayers(list, part, stack, layers);
    }
}
Also used : GearType(net.silentchaos512.gear.api.item.GearType) IPartDisplay(net.silentchaos512.gear.api.part.IPartDisplay) MaterialLayer(net.silentchaos512.gear.api.material.MaterialLayer)

Example 22 with MaterialLayer

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

the class GearModelOverrideList method getCrossbowCharge.

private static Optional<MaterialLayer> getCrossbowCharge(ItemStack stack, @Nullable ClientLevel world, @Nullable LivingEntity entity) {
    // TODO: Maybe should add an ICoreItem method to get additional layers?
    ItemPropertyFunction chargedProperty = ItemProperties.getProperty(stack.getItem(), new ResourceLocation("charged"));
    ItemPropertyFunction fireworkProperty = ItemProperties.getProperty(stack.getItem(), new ResourceLocation("firework"));
    if (chargedProperty != null && fireworkProperty != null) {
        boolean charged = chargedProperty.call(stack, world, entity, 0) > 0;
        boolean firework = fireworkProperty.call(stack, world, entity, 0) > 0;
        if (charged) {
            if (firework) {
                return Optional.of(new MaterialLayer(PartTextures.CHARGED_FIREWORK, Color.VALUE_WHITE));
            }
            return Optional.of(new MaterialLayer(PartTextures.CHARGED_ARROW, Color.VALUE_WHITE));
        }
    }
    return Optional.empty();
}
Also used : MaterialLayer(net.silentchaos512.gear.api.material.MaterialLayer) ResourceLocation(net.minecraft.resources.ResourceLocation) ItemPropertyFunction(net.minecraft.client.renderer.item.ItemPropertyFunction)

Example 23 with MaterialLayer

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

the class GearModelOverrideList method getOverrideModel.

private BakedModel getOverrideModel(CacheKey key, ItemStack stack, @Nullable ClientLevel worldIn, @Nullable LivingEntity entityIn, int animationFrame) {
    boolean broken = GearHelper.isBroken(stack);
    if (isDebugLoggingEnabled()) {
        SilentGear.LOGGER.info("getOverrideModel for {} ({})", stack.getHoverName().getString(), broken ? "broken" : "normal");
        SilentGear.LOGGER.info("- model key {}", key.data);
    }
    List<MaterialLayer> layers = new ArrayList<>();
    for (PartData part : getPartsInRenderOrder(stack)) {
        if (((ICoreItem) stack.getItem()).hasTexturesFor(part.getType())) {
            addSimplePartLayers(layers, part, stack);
            if (part.get() instanceof CompoundPart) {
                MaterialInstance mat = CompoundPart.getPrimaryMaterial(part);
                if (mat != null) {
                    addWithBlendedColor(layers, part, mat, stack);
                }
            }
        }
    }
    // TODO: Make this not a special case...
    if (stack.getItem() instanceof GearCrossbowItem) {
        getCrossbowCharge(stack, worldIn, entityIn).ifPresent(layers::add);
    }
    return model.bake(stack, layers, animationFrame, "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) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem) CompoundPart(net.silentchaos512.gear.gear.part.CompoundPart) GearCrossbowItem(net.silentchaos512.gear.item.gear.GearCrossbowItem) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance)

Example 24 with MaterialLayer

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

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

the class CompoundPartModel method bake.

@SuppressWarnings("MethodWithTooManyParameters")
public BakedModel bake(List<MaterialLayer> layers, 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);
    for (int i = 0; i < layers.size(); i++) {
        MaterialLayer layer = layers.get(i);
        TextureAtlasSprite texture = spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, layer.getTexture(this.texturePath, 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, Color.VALUE_WHITE));
        }
    }
    // Extras
    for (int i = 0; i < this.extraLayers.size(); i++) {
        ResourceLocation texture = this.extraLayers.get(i);
        builder.addAll(getQuadsForSprite(layers.size() + i, spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, new StaticLayer(texture).getTexture())), rotation, Color.VALUE_WHITE));
    }
    builder.addAll(getQuadsForSprite(layers.size(), spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, new StaticLayer(PART_MARKER_TEXTURE).getTexture())), rotation, Color.LIGHTSKYBLUE.getColor()));
    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) 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) BakedPerspectiveModel(net.silentchaos512.gear.client.model.BakedPerspectiveModel) ResourceLocation(net.minecraft.resources.ResourceLocation) ModResourceLocation(net.silentchaos512.gear.util.ModResourceLocation) StaticLayer(net.silentchaos512.gear.api.material.StaticLayer)

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