Example usage for net.minecraftforge.client.model ItemLayerModel ItemLayerModel

List of usage examples for net.minecraftforge.client.model ItemLayerModel ItemLayerModel

Introduction

In this page you can find the example usage for net.minecraftforge.client.model ItemLayerModel ItemLayerModel.

Prototype

public ItemLayerModel(ImmutableList<Material> textures) 

Source Link

Usage

From source file:com.teambrmodding.assistedprogression.client.model.ModelPipette.java

License:Creative Commons License

/**
 * Bakes the model with all relevant information, this is the "live" model
 * @param bakery Minecraft model bakery//from w w w  .j a  v a  2  s  .c  o  m
 * @param spriteGetter Function to get textures
 * @param sprite Sprite info
 * @param format Vertex format
 * @return A model baked with all info present
 */
@SuppressWarnings("ConstantConditions")
@Override
public IBakedModel bake(@Nonnull ModelBakery bakery,
        @Nonnull java.util.function.Function<ResourceLocation, TextureAtlasSprite> spriteGetter, ISprite sprite,
        @Nullable VertexFormat format) {

    // Setup Perspectives
    IModelState state = sprite.getState();
    ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transformMap = PerspectiveMapWrapper
            .getTransforms(state);

    // Sprites and quads initialization
    TRSRTransformation transform = state.apply(java.util.Optional.empty())
            .orElse(TRSRTransformation.identity());
    TextureAtlasSprite fluidSprite = null;
    TextureAtlasSprite particleSprite = null;
    ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
    Random random = new Random();
    random.setSeed(42);

    // Load fluid sprite if not an empty pipette
    if (fluid != Fluids.EMPTY) {
        fluidSprite = spriteGetter.apply(fluid.getAttributes().getStillTexture());
    }

    // Draw the wrapped model, the pipette itself with no fluid or cover
    builder.addAll(baseModel.getQuads(null, null, random));

    // Draw fluid
    if (fluidSprite != null) {
        // We are going to use the mask as a stencil for the liquid
        TextureAtlasSprite liquid = spriteGetter.apply(maskLocation);

        // Build new texture based on stencil
        builder.addAll(ItemTextureQuadConverter.convertTextureHorizontal(format, transform, liquid, fluidSprite,
                NORTH_Z_FLUID, Direction.NORTH, fluid.getAttributes().getColor(), 1));
        builder.addAll(ItemTextureQuadConverter.convertTextureHorizontal(format, transform, liquid, fluidSprite,
                SOUTH_Z_FLUID, Direction.SOUTH, fluid.getAttributes().getColor(), 1));
        particleSprite = fluidSprite;
    }

    // Draw mask
    if (maskLocation != null) {
        // Draw rest of pipette, the clear cover over the fluid, do this by making an item with texture of mask
        IBakedModel model = (new ItemLayerModel(ImmutableList.of(maskLocation))).bake(bakery, spriteGetter,
                sprite, format);
        builder.addAll(model.getQuads(null, null, random));
        particleSprite = model.getParticleTexture();
    }

    // The fully processed model
    return new PipetteDynamicModel(bakery, baseModel, builder.build(), particleSprite, transformMap);
}

From source file:mod.rankshank.arbitraria.client.item.spraybottle.ModelSprayBottleFluid.java

@Override
@SuppressWarnings({ "ConstantConditions", "Guava" })
public IBakedModel bake(IModelState state, VertexFormat format,
        Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
    ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transformMap = IPerspectiveAwareModel.MapWrapper
            .getTransforms(state);//from ww w  .  j a va 2 s.c  o  m
    ImmutableList.Builder<BakedQuad> bob = ImmutableList.builder();
    TRSRTransformation transform = state.apply(Optional.absent()).or(TRSRTransformation.identity());
    TextureAtlasSprite fluidSprite = null;

    if (this.bottle != null)
        bob.addAll(new ItemLayerModel(ImmutableList.of(this.bottle)).bake(state, format, bakedTextureGetter)
                .getQuads(null, null, 0L));

    if (this.filler != null && this.fluid != null
            && (fluidSprite = bakedTextureGetter.apply(this.fluid.getStill())) != null) {
        TextureAtlasSprite fillerSprite = bakedTextureGetter.apply(this.filler);
        bob.addAll(ItemTextureQuadConverter.convertTexture(format, transform, fillerSprite, fluidSprite,
                0.468625f, EnumFacing.NORTH, fluid.getColor()));
        bob.addAll(ItemTextureQuadConverter.convertTexture(format, transform, fillerSprite, fluidSprite,
                0.531375f, EnumFacing.SOUTH, fluid.getColor()));
    }

    return new BakedSprayBottleFluid(this, bob.build(), fluidSprite, format, transformMap);
}