package net.minecraft.client.renderer.entity; import com.google.common.collect.Maps; import com.mojang.blaze3d.vertex.PoseStack; import java.util.Map; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.model.AdultAndBabyModelPair; import net.minecraft.client.model.ColdPigModel; import net.minecraft.client.model.EntityModel; import net.minecraft.client.model.PigModel; import net.minecraft.client.model.geom.ModelLayers; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.entity.layers.SimpleEquipmentLayer; import net.minecraft.client.renderer.entity.state.PigRenderState; import net.minecraft.client.renderer.texture.MissingTextureAtlasSprite; import net.minecraft.client.resources.model.EquipmentClientInfo; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.animal.Pig; import net.minecraft.world.entity.animal.PigVariant; @Environment(EnvType.CLIENT) public class PigRenderer extends MobRenderer { private final Map> models; public PigRenderer(EntityRendererProvider.Context context) { super(context, new PigModel(context.bakeLayer(ModelLayers.PIG)), 0.7F); this.models = bakeModels(context); this.addLayer( new SimpleEquipmentLayer<>( this, context.getEquipmentRenderer(), EquipmentClientInfo.LayerType.PIG_SADDLE, pigRenderState -> pigRenderState.saddle, new PigModel(context.bakeLayer(ModelLayers.PIG_SADDLE)), new PigModel(context.bakeLayer(ModelLayers.PIG_BABY_SADDLE)) ) ); } private static Map> bakeModels(EntityRendererProvider.Context context) { return Maps.newEnumMap( Map.of( PigVariant.ModelType.NORMAL, new AdultAndBabyModelPair<>(new PigModel(context.bakeLayer(ModelLayers.PIG)), new PigModel(context.bakeLayer(ModelLayers.PIG_BABY))), PigVariant.ModelType.COLD, new AdultAndBabyModelPair<>(new ColdPigModel(context.bakeLayer(ModelLayers.COLD_PIG)), new ColdPigModel(context.bakeLayer(ModelLayers.COLD_PIG_BABY))) ) ); } public void render(PigRenderState renderState, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) { if (renderState.variant != null) { this.model = (EntityModel)((AdultAndBabyModelPair)this.models.get(renderState.variant.modelAndTexture().model())).getModel(renderState.isBaby); super.render(renderState, poseStack, bufferSource, packedLight); } } public ResourceLocation getTextureLocation(PigRenderState renderState) { return renderState.variant == null ? MissingTextureAtlasSprite.getLocation() : renderState.variant.modelAndTexture().asset().texturePath(); } public PigRenderState createRenderState() { return new PigRenderState(); } public void extractRenderState(Pig entity, PigRenderState reusedState, float partialTick) { super.extractRenderState(entity, reusedState, partialTick); reusedState.saddle = entity.getItemBySlot(EquipmentSlot.SADDLE).copy(); reusedState.variant = entity.getVariant().value(); } }