Search in sources :

Example 1 with IModelPart

use of net.minecraftforge.common.model.IModelPart in project MinecraftForge by MinecraftForge.

the class ModelDynBucket method bake.

@Override
public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
    ImmutableMap<TransformType, TRSRTransformation> transformMap = IPerspectiveAwareModel.MapWrapper.getTransforms(state);
    // if the fluid is a gas wi manipulate the initial state to be rotated 180° to turn it upside down
    if (flipGas && fluid != null && fluid.isGaseous()) {
        state = new ModelStateComposition(state, TRSRTransformation.blockCenterToCorner(new TRSRTransformation(null, new Quat4f(0, 0, 1, 0), null, null)));
    }
    TRSRTransformation transform = state.apply(Optional.<IModelPart>absent()).or(TRSRTransformation.identity());
    TextureAtlasSprite fluidSprite = null;
    ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
    if (fluid != null) {
        fluidSprite = bakedTextureGetter.apply(fluid.getStill());
    }
    if (baseLocation != null) {
        // build base (insidest)
        IBakedModel model = (new ItemLayerModel(ImmutableList.of(baseLocation))).bake(state, format, bakedTextureGetter);
        builder.addAll(model.getQuads(null, null, 0));
    }
    if (liquidLocation != null && fluidSprite != null) {
        TextureAtlasSprite liquid = bakedTextureGetter.apply(liquidLocation);
        // build liquid layer (inside)
        builder.addAll(ItemTextureQuadConverter.convertTexture(format, transform, liquid, fluidSprite, NORTH_Z_FLUID, EnumFacing.NORTH, fluid.getColor()));
        builder.addAll(ItemTextureQuadConverter.convertTexture(format, transform, liquid, fluidSprite, SOUTH_Z_FLUID, EnumFacing.SOUTH, fluid.getColor()));
    }
    if (coverLocation != null) {
        // cover (the actual item around the other two)
        TextureAtlasSprite base = bakedTextureGetter.apply(coverLocation);
        builder.add(ItemTextureQuadConverter.genQuad(format, transform, 0, 0, 16, 16, NORTH_Z_BASE, base, EnumFacing.NORTH, 0xffffffff));
        builder.add(ItemTextureQuadConverter.genQuad(format, transform, 0, 0, 16, 16, SOUTH_Z_BASE, base, EnumFacing.SOUTH, 0xffffffff));
    }
    return new BakedDynBucket(this, builder.build(), fluidSprite, format, Maps.immutableEnumMap(transformMap), Maps.<String, IBakedModel>newHashMap());
}
Also used : TRSRTransformation(net.minecraftforge.common.model.TRSRTransformation) BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) ImmutableList(com.google.common.collect.ImmutableList) TransformType(net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType) IModelPart(net.minecraftforge.common.model.IModelPart) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) Quat4f(javax.vecmath.Quat4f) ItemOverride(net.minecraft.client.renderer.block.model.ItemOverride)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 Quat4f (javax.vecmath.Quat4f)1 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)1 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)1 TransformType (net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType)1 ItemOverride (net.minecraft.client.renderer.block.model.ItemOverride)1 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)1 IModelPart (net.minecraftforge.common.model.IModelPart)1 TRSRTransformation (net.minecraftforge.common.model.TRSRTransformation)1