| 1 | package net.minecraft.client.renderer.entity;
|
| 2 |
|
| 3 | import com.mojang.blaze3d.vertex.PoseStack;
|
| 4 | import com.mojang.math.Axis;
|
| 5 | import net.fabricmc.api.EnvType;
|
| 6 | import net.fabricmc.api.Environment;
|
| 7 | import net.minecraft.client.model.EntityModel;
|
| 8 | import net.minecraft.client.model.animal.fish.TropicalFishLargeModel;
|
| 9 | import net.minecraft.client.model.animal.fish.TropicalFishSmallModel;
|
| 10 | import net.minecraft.client.model.geom.ModelLayers;
|
| 11 | import net.minecraft.client.renderer.SubmitNodeCollector;
|
| 12 | import net.minecraft.client.renderer.entity.layers.TropicalFishPatternLayer;
|
| 13 | import net.minecraft.client.renderer.entity.state.TropicalFishRenderState;
|
| 14 | import net.minecraft.client.renderer.state.level.CameraRenderState;
|
| 15 | import net.minecraft.resources.Identifier;
|
| 16 | import net.minecraft.util.Mth;
|
| 17 | import net.minecraft.world.entity.animal.fish.TropicalFish;
|
| 18 |
|
| 19 | @Environment(EnvType.CLIENT)
|
| 20 | public class TropicalFishRenderer extends MobRenderer<TropicalFish, TropicalFishRenderState, EntityModel<TropicalFishRenderState>> {
|
| 21 | private final EntityModel<TropicalFishRenderState> smallModel = this.getModel();
|
| 22 | private final EntityModel<TropicalFishRenderState> largeModel;
|
| 23 | private static final Identifier SMALL_TEXTURE = Identifier.withDefaultNamespace("textures/entity/fish/tropical_a.png");
|
| 24 | private static final Identifier LARGE_TEXTURE = Identifier.withDefaultNamespace("textures/entity/fish/tropical_b.png");
|
| 25 |
|
| 26 | public TropicalFishRenderer(final EntityRendererProvider.Context context) {
|
| 27 | super(context, new TropicalFishSmallModel(context.bakeLayer(ModelLayers.TROPICAL_FISH_SMALL)), 0.15F);
|
| 28 | this.largeModel = new TropicalFishLargeModel(context.bakeLayer(ModelLayers.TROPICAL_FISH_LARGE));
|
| 29 | this.addLayer(new TropicalFishPatternLayer(this, context.getModelSet()));
|
| 30 | }
|
| 31 |
|
| 32 | public Identifier getTextureLocation(final TropicalFishRenderState state) {
|
| 33 | return switch (state.pattern.base()) {
|
| 34 | case SMALL -> SMALL_TEXTURE;
|
| 35 | case LARGE -> LARGE_TEXTURE;
|
| 36 | };
|
| 37 | }
|
| 38 |
|
| 39 | public TropicalFishRenderState createRenderState() {
|
| 40 | return new TropicalFishRenderState();
|
| 41 | }
|
| 42 |
|
| 43 | public void extractRenderState(final TropicalFish entity, final TropicalFishRenderState state, final float partialTicks) {
|
| 44 | super.extractRenderState(entity, state, partialTicks);
|
| 45 | state.pattern = entity.getPattern();
|
| 46 | state.baseColor = entity.getBaseColor().getTextureDiffuseColor();
|
| 47 | state.patternColor = entity.getPatternColor().getTextureDiffuseColor();
|
| 48 | }
|
| 49 |
|
| 50 | public void submit(
|
| 51 | final TropicalFishRenderState state, final PoseStack poseStack, final SubmitNodeCollector submitNodeCollector, final CameraRenderState camera
|
| 52 | ) {
|
| 53 | this.model = switch (state.pattern.base()) {
|
| 54 | case SMALL -> this.smallModel;
|
| 55 | case LARGE -> this.largeModel;
|
| 56 | };
|
| 57 | super.submit(state, poseStack, submitNodeCollector, camera);
|
| 58 | }
|
| 59 |
|
| 60 | protected int getModelTint(final TropicalFishRenderState state) {
|
| 61 | return state.baseColor;
|
| 62 | }
|
| 63 |
|
| 64 | protected void setupRotations(final TropicalFishRenderState state, final PoseStack poseStack, final float bodyRot, final float entityScale) {
|
| 65 | super.setupRotations(state, poseStack, bodyRot, entityScale);
|
| 66 | float bodyZRot = 4.3F * Mth.sin(0.6F * state.ageInTicks);
|
| 67 | poseStack.rotateDegrees(Axis.YP, bodyZRot);
|
| 68 | if (!state.isInWater) {
|
| 69 | poseStack.translate(0.2F, 0.1F, 0.0F);
|
| 70 | poseStack.rotateDegrees(Axis.ZP, 90.0F);
|
| 71 | }
|
| 72 | }
|
| 73 | }
|
| 74 |
|