| 1 | package net.minecraft.client.renderer.entity;
|
| 2 |
|
| 3 | import com.google.common.collect.Maps;
|
| 4 | import java.util.Locale;
|
| 5 | import java.util.Map;
|
| 6 | import net.fabricmc.api.EnvType;
|
| 7 | import net.fabricmc.api.Environment;
|
| 8 | import net.minecraft.client.model.EntityModel;
|
| 9 | import net.minecraft.client.model.animal.axolotl.AdultAxolotlModel;
|
| 10 | import net.minecraft.client.model.animal.axolotl.BabyAxolotlModel;
|
| 11 | import net.minecraft.client.model.geom.ModelLayers;
|
| 12 | import net.minecraft.client.renderer.entity.state.AxolotlRenderState;
|
| 13 | import net.minecraft.resources.Identifier;
|
| 14 | import net.minecraft.util.Util;
|
| 15 | import net.minecraft.world.entity.animal.axolotl.Axolotl;
|
| 16 | import net.minecraft.world.entity.animal.axolotl.Axolotl.Variant;
|
| 17 |
|
| 18 | @Environment(EnvType.CLIENT)
|
| 19 | public class AxolotlRenderer extends AgeableMobRenderer<Axolotl, AxolotlRenderState, EntityModel<AxolotlRenderState>> {
|
| 20 | private static final Map<Variant, AxolotlRenderer.AxolotlTextures> TEXTURE_BY_TYPE = Util.make(
|
| 21 | Maps.newHashMap(),
|
| 22 | map -> {
|
| 23 | for (Variant variant : Variant.values()) {
|
| 24 | AxolotlRenderer.AxolotlTextures textures = new AxolotlRenderer.AxolotlTextures(
|
| 25 | Identifier.withDefaultNamespace(String.format(Locale.ROOT, "textures/entity/axolotl/axolotl_%s.png", variant.getName())),
|
| 26 | Identifier.withDefaultNamespace(String.format(Locale.ROOT, "textures/entity/axolotl/axolotl_%s_baby.png", variant.getName()))
|
| 27 | );
|
| 28 | map.put(variant, textures);
|
| 29 | }
|
| 30 | }
|
| 31 | );
|
| 32 |
|
| 33 | public AxolotlRenderer(final EntityRendererProvider.Context context) {
|
| 34 | super(context, new AdultAxolotlModel(context.bakeLayer(ModelLayers.AXOLOTL)), new BabyAxolotlModel(context.bakeLayer(ModelLayers.AXOLOTL_BABY)), 0.5F);
|
| 35 | }
|
| 36 |
|
| 37 | public Identifier getTextureLocation(final AxolotlRenderState state) {
|
| 38 | AxolotlRenderer.AxolotlTextures textures = TEXTURE_BY_TYPE.get(state.variant);
|
| 39 | return state.isBaby ? textures.baby : textures.adult;
|
| 40 | }
|
| 41 |
|
| 42 | public AxolotlRenderState createRenderState() {
|
| 43 | return new AxolotlRenderState();
|
| 44 | }
|
| 45 |
|
| 46 | public void extractRenderState(final Axolotl entity, final AxolotlRenderState state, final float partialTicks) {
|
| 47 | super.extractRenderState(entity, state, partialTicks);
|
| 48 | state.variant = entity.getVariant();
|
| 49 | state.playingDeadFactor = entity.playingDeadAnimator.getFactor(partialTicks);
|
| 50 | state.inWaterFactor = entity.inWaterAnimator.getFactor(partialTicks);
|
| 51 | state.onGroundFactor = entity.onGroundAnimator.getFactor(partialTicks);
|
| 52 | state.movingFactor = entity.movingAnimator.getFactor(partialTicks);
|
| 53 | state.swimAnimation.copyFrom(entity.swimAnimationState);
|
| 54 | state.walkAnimationState.copyFrom(entity.walkAnimationState);
|
| 55 | state.walkUnderWaterAnimationState.copyFrom(entity.walkUnderWaterAnimationState);
|
| 56 | state.idleOnGroundAnimationState.copyFrom(entity.idleOnGroundAnimationState);
|
| 57 | state.idleUnderWaterOnGroundAnimationState.copyFrom(entity.idleUnderWaterOnGroundAnimationState);
|
| 58 | state.idleUnderWaterAnimationState.copyFrom(entity.idleUnderWaterAnimationState);
|
| 59 | state.playDeadAnimationState.copyFrom(entity.playDeadAnimationState);
|
| 60 | }
|
| 61 |
|
| 62 | @Environment(EnvType.CLIENT)
|
| 63 | private record AxolotlTextures(Identifier adult, Identifier baby) {
|
| 64 | }
|
| 65 | }
|
| 66 |
|