use of net.minecraftforge.client.model.SimpleModelTransform 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());
}
Aggregations