use of net.minecraft.client.renderer.model.RenderMaterial in project Ceramics by KnightMiner.
the class CrackedModel method getTextures.
@Override
public Collection<RenderMaterial> getTextures(IModelConfiguration owner, Function<ResourceLocation, IUnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors) {
Collection<RenderMaterial> textures = model.getTextures(owner, modelGetter, missingTextureErrors);
for (int i = 1; i <= 5; i++) {
String name = "cracks_" + i;
RenderMaterial material = owner.resolveTexture(name);
if (Objects.equals(material.getTextureLocation(), MissingTextureSprite.getLocation())) {
missingTextureErrors.add(Pair.of(name, owner.getModelName()));
}
textures.add(material);
}
return textures;
}
use of net.minecraft.client.renderer.model.RenderMaterial 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());
}
use of net.minecraft.client.renderer.model.RenderMaterial in project Ceramics by KnightMiner.
the class CrackedModel method bake.
@Override
public IBakedModel bake(IModelConfiguration owner, ModelBakery bakery, Function<RenderMaterial, TextureAtlasSprite> spriteGetter, IModelTransform transform, ItemOverrideList overrides, ResourceLocation location) {
// fetch textures
RenderMaterial[] textures = new RenderMaterial[5];
for (int i = 0; i < 5; i++) {
textures[i] = owner.resolveTexture("cracks_" + (i + 1));
}
// create extra quads
List<BlockPart> elements = model.getElements();
List<BlockPart> newElements = new ArrayList<>(elements.size() * 2);
newElements.addAll(elements);
for (BlockPart element : elements) {
Map<Direction, BlockPartFace> mapFaces = new HashMap<>();
for (Entry<Direction, BlockPartFace> entry : element.mapFaces.entrySet()) {
BlockPartFace face = entry.getValue();
mapFaces.put(entry.getKey(), new BlockPartFace(face.cullFace, -1, "cracks", face.blockFaceUV));
}
newElements.add(new BlockPart(element.positionFrom, element.positionTo, mapFaces, element.partRotation, element.shade));
}
// wrap the original model
IBakedModel original = model.bakeModel(owner, transform, OVERRIDES, spriteGetter, location);
return new BakedModel(original, owner, newElements, textures, transform);
}
Aggregations