use of net.minecraft.client.renderer.block.model.ItemTransforms.TransformType in project MinecraftForge by MinecraftForge.
the class DynamicBucketModel method bake.
@Override
public BakedModel bake(IModelConfiguration owner, ModelBakery bakery, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelTransform, ItemOverrides overrides, ResourceLocation modelLocation) {
Material particleLocation = owner.isTexturePresent("particle") ? owner.resolveTexture("particle") : null;
Material baseLocation = owner.isTexturePresent("base") ? owner.resolveTexture("base") : null;
Material fluidMaskLocation = owner.isTexturePresent("fluid") ? owner.resolveTexture("fluid") : null;
Material coverLocation = owner.isTexturePresent("cover") ? owner.resolveTexture("cover") : null;
ModelState transformsFromModel = owner.getCombinedTransform();
TextureAtlasSprite fluidSprite = fluid != Fluids.EMPTY ? spriteGetter.apply(ForgeHooksClient.getBlockMaterial(fluid.getAttributes().getStillTexture())) : null;
TextureAtlasSprite coverSprite = (coverLocation != null && (!coverIsMask || baseLocation != null)) ? spriteGetter.apply(coverLocation) : null;
ImmutableMap<TransformType, Transformation> transformMap = PerspectiveMapWrapper.getTransforms(new CompositeModelState(transformsFromModel, modelTransform));
TextureAtlasSprite particleSprite = particleLocation != null ? spriteGetter.apply(particleLocation) : null;
if (particleSprite == null)
particleSprite = fluidSprite;
if (particleSprite == null && !coverIsMask)
particleSprite = coverSprite;
// if the fluid is lighter than air, will manipulate the initial state to be rotated 180deg to turn it upside down
if (flipGas && fluid != Fluids.EMPTY && fluid.getAttributes().isLighterThanAir()) {
modelTransform = new SimpleModelState(modelTransform.getRotation().blockCornerToCenter().compose(new Transformation(null, new Quaternion(0, 0, 1, 0), null, null)).blockCenterToCorner());
}
Transformation transform = modelTransform.getRotation();
ItemMultiLayerBakedModel.Builder builder = ItemMultiLayerBakedModel.builder(owner, particleSprite, new ContainedFluidOverrideHandler(overrides, bakery, owner, this), transformMap);
if (baseLocation != null) {
// build base (insidest)
builder.addQuads(ItemLayerModel.getLayerRenderType(false), ItemLayerModel.getQuadsForSprites(ImmutableList.of(baseLocation), transform, spriteGetter));
}
if (fluidMaskLocation != null && fluidSprite != null) {
TextureAtlasSprite templateSprite = spriteGetter.apply(fluidMaskLocation);
if (templateSprite != null) {
// build liquid layer (inside)
int luminosity = applyFluidLuminosity ? fluid.getAttributes().getLuminosity() : 0;
int color = tint ? fluid.getAttributes().getColor() : 0xFFFFFFFF;
builder.addQuads(ItemLayerModel.getLayerRenderType(luminosity > 0), ItemTextureQuadConverter.convertTexture(transform, templateSprite, fluidSprite, NORTH_Z_FLUID, Direction.NORTH, color, 1, luminosity));
builder.addQuads(ItemLayerModel.getLayerRenderType(luminosity > 0), ItemTextureQuadConverter.convertTexture(transform, templateSprite, fluidSprite, SOUTH_Z_FLUID, Direction.SOUTH, color, 1, luminosity));
}
}
if (coverIsMask) {
if (coverSprite != null && baseLocation != null) {
TextureAtlasSprite baseSprite = spriteGetter.apply(baseLocation);
builder.addQuads(ItemLayerModel.getLayerRenderType(false), ItemTextureQuadConverter.convertTexture(transform, coverSprite, baseSprite, NORTH_Z_COVER, Direction.NORTH, 0xFFFFFFFF, 2));
builder.addQuads(ItemLayerModel.getLayerRenderType(false), ItemTextureQuadConverter.convertTexture(transform, coverSprite, baseSprite, SOUTH_Z_COVER, Direction.SOUTH, 0xFFFFFFFF, 2));
}
} else {
if (coverSprite != null) {
builder.addQuads(ItemLayerModel.getLayerRenderType(false), ItemTextureQuadConverter.genQuad(transform, 0, 0, 16, 16, NORTH_Z_COVER, coverSprite, Direction.NORTH, 0xFFFFFFFF, 2));
builder.addQuads(ItemLayerModel.getLayerRenderType(false), ItemTextureQuadConverter.genQuad(transform, 0, 0, 16, 16, SOUTH_Z_COVER, coverSprite, Direction.SOUTH, 0xFFFFFFFF, 2));
}
}
builder.setParticle(particleSprite);
return builder.build();
}
Aggregations