| 1 | package net.minecraft.client.renderer.entity;
|
| 2 |
|
| 3 | import com.google.common.collect.Maps;
|
| 4 | import java.util.Map;
|
| 5 | import net.fabricmc.api.EnvType;
|
| 6 | import net.fabricmc.api.Environment;
|
| 7 | import net.minecraft.client.model.animal.cow.BabyCowModel;
|
| 8 | import net.minecraft.client.model.animal.cow.CowModel;
|
| 9 | import net.minecraft.client.model.geom.ModelLayers;
|
| 10 | import net.minecraft.client.renderer.block.BlockModelResolver;
|
| 11 | import net.minecraft.client.renderer.block.model.BlockDisplayContext;
|
| 12 | import net.minecraft.client.renderer.entity.layers.MushroomCowMushroomLayer;
|
| 13 | import net.minecraft.client.renderer.entity.state.MushroomCowRenderState;
|
| 14 | import net.minecraft.resources.Identifier;
|
| 15 | import net.minecraft.util.Util;
|
| 16 | import net.minecraft.world.entity.animal.cow.MushroomCow;
|
| 17 | import net.minecraft.world.entity.animal.cow.MushroomCow.Variant;
|
| 18 |
|
| 19 | @Environment(EnvType.CLIENT)
|
| 20 | public class MushroomCowRenderer extends AgeableMobRenderer<MushroomCow, MushroomCowRenderState, CowModel> {
|
| 21 | public static final BlockDisplayContext BLOCK_DISPLAY_CONTEXT = BlockDisplayContext.create();
|
| 22 | private static final Map<Variant, MushroomCowRenderer.MushroomCowTexture> TEXTURES = Util.make(
|
| 23 | Maps.newHashMap(),
|
| 24 | map -> {
|
| 25 | map.put(
|
| 26 | Variant.BROWN,
|
| 27 | new MushroomCowRenderer.MushroomCowTexture(
|
| 28 | Identifier.withDefaultNamespace("textures/entity/cow/mooshroom_brown.png"),
|
| 29 | Identifier.withDefaultNamespace("textures/entity/cow/mooshroom_brown_baby.png")
|
| 30 | )
|
| 31 | );
|
| 32 | map.put(
|
| 33 | Variant.RED,
|
| 34 | new MushroomCowRenderer.MushroomCowTexture(
|
| 35 | Identifier.withDefaultNamespace("textures/entity/cow/mooshroom_red.png"), Identifier.withDefaultNamespace("textures/entity/cow/mooshroom_red_baby.png")
|
| 36 | )
|
| 37 | );
|
| 38 | }
|
| 39 | );
|
| 40 | private final BlockModelResolver blockModelResolver;
|
| 41 |
|
| 42 | public MushroomCowRenderer(final EntityRendererProvider.Context context) {
|
| 43 | super(context, new CowModel(context.bakeLayer(ModelLayers.MOOSHROOM)), new BabyCowModel(context.bakeLayer(ModelLayers.MOOSHROOM_BABY)), 0.7F);
|
| 44 | this.blockModelResolver = context.getBlockModelResolver();
|
| 45 | this.addLayer(new MushroomCowMushroomLayer(this));
|
| 46 | }
|
| 47 |
|
| 48 | public Identifier getTextureLocation(final MushroomCowRenderState state) {
|
| 49 | return state.isBaby ? TEXTURES.get(state.variant).baby : TEXTURES.get(state.variant).adult;
|
| 50 | }
|
| 51 |
|
| 52 | public MushroomCowRenderState createRenderState() {
|
| 53 | return new MushroomCowRenderState();
|
| 54 | }
|
| 55 |
|
| 56 | public void extractRenderState(final MushroomCow entity, final MushroomCowRenderState state, final float partialTicks) {
|
| 57 | super.extractRenderState(entity, state, partialTicks);
|
| 58 | state.variant = entity.getVariant();
|
| 59 | this.blockModelResolver.update(state.mushroomModel, state.variant.getBlockState(), BLOCK_DISPLAY_CONTEXT);
|
| 60 | }
|
| 61 |
|
| 62 | @Environment(EnvType.CLIENT)
|
| 63 | private record MushroomCowTexture(Identifier adult, Identifier baby) {
|
| 64 | }
|
| 65 | }
|
| 66 |
|