Example usage for net.minecraftforge.client.model PerspectiveMapWrapper getTransforms

List of usage examples for net.minecraftforge.client.model PerspectiveMapWrapper getTransforms

Introduction

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

Prototype

@SuppressWarnings("deprecation")
    public static ImmutableMap<ItemCameraTransforms.TransformType, TransformationMatrix> getTransforms(
            ItemCameraTransforms transforms) 

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 ww.ja v a 2  s.  c om
 * @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);
}