Search in sources :

Example 1 with TransformType

use of net.minecraft.client.renderer.model.ItemCameraTransforms.TransformType in project Ceramics by KnightMiner.

the class ClayBucketModel method bake.

@Override
public IBakedModel bake(IModelConfiguration owner, ModelBakery bakery, Function<RenderMaterial, TextureAtlasSprite> spriteGetter, IModelTransform modelTransform, ItemOverrideList overrides, ResourceLocation modelLocation) {
    RenderMaterial particleLocation = getMaterial(owner, "particle");
    // front texture, full 3D
    RenderMaterial baseLocation = getMaterial(owner, "base");
    // inner (texture in the middle, flat)
    RenderMaterial fluidMaskLocation = getMaterial(owner, "fluid");
    // inner (texture in the back, flat)
    RenderMaterial innerLocation = getMaterial(owner, "inner");
    // determine the transforms to use
    IModelTransform transformsFromModel = owner.getCombinedTransform();
    ImmutableMap<TransformType, TransformationMatrix> transformMap = PerspectiveMapWrapper.getTransforms(new ModelTransformComposition(transformsFromModel, modelTransform));
    // particle has fallback if null based on a few other sprites
    TextureAtlasSprite particleSprite = particleLocation != null ? spriteGetter.apply(particleLocation) : null;
    // if the fluid is lighter than air, will manipulate the initial state to be rotated 180 deg to turn it upside down
    if (flipGas && fluid != Fluids.EMPTY && fluid.getAttributes().isLighterThanAir()) {
        modelTransform = new ModelTransformComposition(modelTransform, new SimpleModelTransform(new TransformationMatrix(null, new Quaternion(0, 0, 1, 0), null, null)));
    }
    // start building quads
    TransformationMatrix transform = modelTransform.getRotation();
    ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
    if (fluid == Fluids.EMPTY) {
        // use base if no inner sprite
        if (innerLocation == null)
            innerLocation = baseLocation;
        if (innerLocation != null) {
            // this sprite will be used as particle
            if (particleSprite == null)
                particleSprite = spriteGetter.apply(innerLocation);
            // add to builder
            builder.addAll(ItemLayerModel.getQuadsForSprites(ImmutableList.of(innerLocation), transform, spriteGetter));
        }
    } else {
        // base is the outer cover, but is also the only layer in full 3D
        if (baseLocation != null) {
            builder.addAll(ItemLayerModel.getQuadsForSprites(ImmutableList.of(baseLocation), transform, spriteGetter));
        }
        // fluid is next one in
        TextureAtlasSprite fluidSprite = spriteGetter.apply(ForgeHooksClient.getBlockMaterial(fluid.getAttributes().getStillTexture()));
        if (particleSprite == null)
            particleSprite = fluidSprite;
        if (fluidMaskLocation != null && fluidSprite != null) {
            TextureAtlasSprite templateSprite = spriteGetter.apply(fluidMaskLocation);
            if (templateSprite != null) {
                int color = tint ? fluid.getAttributes().getColor() : 0xFFFFFFFF;
                builder.addAll(ItemTextureQuadConverter.convertTexture(transform, templateSprite, fluidSprite, NORTH_Z_FLUID, Direction.NORTH, color, 1));
                builder.addAll(ItemTextureQuadConverter.convertTexture(transform, templateSprite, fluidSprite, SOUTH_Z_FLUID, Direction.SOUTH, color, 1));
            }
        }
        // inventory will not see this regardless
        if (innerLocation != null) {
            // inner (the actual item around the other two)
            TextureAtlasSprite innerSprite = spriteGetter.apply(innerLocation);
            builder.add(ItemTextureQuadConverter.genQuad(transform, 0, 0, 16, 16, NORTH_Z_INNER, innerSprite, Direction.NORTH, 0xFFFFFFFF, 2));
            builder.add(ItemTextureQuadConverter.genQuad(transform, 0, 0, 16, 16, SOUTH_Z_INNER, innerSprite, Direction.SOUTH, 0xFFFFFFFF, 2));
        }
    }
    if (particleSprite == null) {
        particleSprite = spriteGetter.apply(ModelLoaderRegistry.blockMaterial(MissingTextureSprite.getLocation()));
    }
    return new BakedModel(bakery, owner, this, builder.build(), particleSprite, Maps.immutableEnumMap(transformMap), Maps.newHashMap(), transform.isIdentity(), modelTransform, owner.isSideLit());
}
Also used : BakedQuad(net.minecraft.client.renderer.model.BakedQuad) SimpleModelTransform(net.minecraftforge.client.model.SimpleModelTransform) Quaternion(net.minecraft.util.math.vector.Quaternion) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) ImmutableList(com.google.common.collect.ImmutableList) TransformType(net.minecraft.client.renderer.model.ItemCameraTransforms.TransformType) IModelTransform(net.minecraft.client.renderer.model.IModelTransform) TransformationMatrix(net.minecraft.util.math.vector.TransformationMatrix) IBakedModel(net.minecraft.client.renderer.model.IBakedModel) ModelTransformComposition(net.minecraftforge.client.model.ModelTransformComposition) RenderMaterial(net.minecraft.client.renderer.model.RenderMaterial)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 BakedQuad (net.minecraft.client.renderer.model.BakedQuad)1 IBakedModel (net.minecraft.client.renderer.model.IBakedModel)1 IModelTransform (net.minecraft.client.renderer.model.IModelTransform)1 TransformType (net.minecraft.client.renderer.model.ItemCameraTransforms.TransformType)1 RenderMaterial (net.minecraft.client.renderer.model.RenderMaterial)1 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)1 Quaternion (net.minecraft.util.math.vector.Quaternion)1 TransformationMatrix (net.minecraft.util.math.vector.TransformationMatrix)1 ModelTransformComposition (net.minecraftforge.client.model.ModelTransformComposition)1 SimpleModelTransform (net.minecraftforge.client.model.SimpleModelTransform)1