| 1 | package net.minecraft.client.renderer.entity;
|
| 2 |
|
| 3 | import net.fabricmc.api.EnvType;
|
| 4 | import net.fabricmc.api.Environment;
|
| 5 | import net.minecraft.client.model.animal.camel.AdultCamelModel;
|
| 6 | import net.minecraft.client.model.animal.camel.BabyCamelModel;
|
| 7 | import net.minecraft.client.model.animal.camel.CamelModel;
|
| 8 | import net.minecraft.client.model.animal.camel.CamelSaddleModel;
|
| 9 | import net.minecraft.client.model.geom.ModelLayerLocation;
|
| 10 | import net.minecraft.client.model.geom.ModelLayers;
|
| 11 | import net.minecraft.client.renderer.entity.layers.SimpleEquipmentLayer;
|
| 12 | import net.minecraft.client.renderer.entity.state.CamelRenderState;
|
| 13 | import net.minecraft.client.resources.model.EquipmentClientInfo;
|
| 14 | import net.minecraft.resources.Identifier;
|
| 15 | import net.minecraft.world.entity.EquipmentSlot;
|
| 16 | import net.minecraft.world.entity.animal.camel.Camel;
|
| 17 |
|
| 18 | @Environment(EnvType.CLIENT)
|
| 19 | public class CamelRenderer extends AgeableMobRenderer<Camel, CamelRenderState, CamelModel> {
|
| 20 | private static final Identifier CAMEL_LOCATION = Identifier.withDefaultNamespace("textures/entity/camel/camel.png");
|
| 21 | private static final Identifier CAMEL_BABY_LOCATION = Identifier.withDefaultNamespace("textures/entity/camel/camel_baby.png");
|
| 22 |
|
| 23 | public CamelRenderer(final EntityRendererProvider.Context context) {
|
| 24 | super(context, new AdultCamelModel(context.bakeLayer(ModelLayers.CAMEL)), new BabyCamelModel(context.bakeLayer(ModelLayers.CAMEL_BABY)), 0.7F);
|
| 25 | this.addLayer(createCamelSaddleLayer(context, this, EquipmentClientInfo.LayerType.CAMEL_SADDLE, ModelLayers.CAMEL_SADDLE));
|
| 26 | }
|
| 27 |
|
| 28 | protected static SimpleEquipmentLayer<CamelRenderState, CamelModel, CamelSaddleModel> createCamelSaddleLayer(
|
| 29 | final EntityRendererProvider.Context context,
|
| 30 | final MobRenderer<Camel, CamelRenderState, CamelModel> renderer,
|
| 31 | final EquipmentClientInfo.LayerType saddleLayerType,
|
| 32 | final ModelLayerLocation saddleModelLayer
|
| 33 | ) {
|
| 34 | return new SimpleEquipmentLayer<>(
|
| 35 | renderer, context.getEquipmentRenderer(), saddleLayerType, state -> state.saddle, new CamelSaddleModel(context.bakeLayer(saddleModelLayer)), null
|
| 36 | );
|
| 37 | }
|
| 38 |
|
| 39 | public Identifier getTextureLocation(final CamelRenderState state) {
|
| 40 | return state.isBaby ? CAMEL_BABY_LOCATION : CAMEL_LOCATION;
|
| 41 | }
|
| 42 |
|
| 43 | public CamelRenderState createRenderState() {
|
| 44 | return new CamelRenderState();
|
| 45 | }
|
| 46 |
|
| 47 | public void extractRenderState(final Camel entity, final CamelRenderState state, final float partialTicks) {
|
| 48 | super.extractRenderState(entity, state, partialTicks);
|
| 49 | extractAdditionalState(entity, state, partialTicks);
|
| 50 | }
|
| 51 |
|
| 52 | public static void extractAdditionalState(final Camel entity, final CamelRenderState state, final float partialTicks) {
|
| 53 | state.saddle = entity.getItemBySlot(EquipmentSlot.SADDLE).copy();
|
| 54 | state.isRidden = entity.isVehicle();
|
| 55 | state.jumpCooldown = getJumpCooldown(entity, partialTicks);
|
| 56 | state.sitAnimationState.copyFrom(entity.sitAnimationState);
|
| 57 | state.sitPoseAnimationState.copyFrom(entity.sitPoseAnimationState);
|
| 58 | state.sitUpAnimationState.copyFrom(entity.sitUpAnimationState);
|
| 59 | state.idleAnimationState.copyFrom(entity.idleAnimationState);
|
| 60 | state.dashAnimationState.copyFrom(entity.dashAnimationState);
|
| 61 | }
|
| 62 |
|
| 63 | private static float getJumpCooldown(final Camel camel, final float partialTicks) {
|
| 64 | return Math.max(camel.getJumpCooldown() - partialTicks, 0.0F);
|
| 65 | }
|
| 66 | }
|
| 67 |
|