| 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.animal.golem.IronGolemModel;
|
| 8 | import net.minecraft.client.model.geom.ModelLayers;
|
| 9 | import net.minecraft.client.renderer.block.BlockModelResolver;
|
| 10 | import net.minecraft.client.renderer.block.model.BlockDisplayContext;
|
| 11 | import net.minecraft.client.renderer.entity.layers.IronGolemCrackinessLayer;
|
| 12 | import net.minecraft.client.renderer.entity.layers.IronGolemFlowerLayer;
|
| 13 | import net.minecraft.client.renderer.entity.state.IronGolemRenderState;
|
| 14 | import net.minecraft.resources.Identifier;
|
| 15 | import net.minecraft.world.entity.animal.golem.IronGolem;
|
| 16 | import net.minecraft.world.level.block.Blocks;
|
| 17 |
|
| 18 | @Environment(EnvType.CLIENT)
|
| 19 | public class IronGolemRenderer extends MobRenderer<IronGolem, IronGolemRenderState, IronGolemModel> {
|
| 20 | public static final BlockDisplayContext BLOCK_DISPLAY_CONTEXT = BlockDisplayContext.create();
|
| 21 | private static final Identifier GOLEM_LOCATION = Identifier.withDefaultNamespace("textures/entity/iron_golem/iron_golem.png");
|
| 22 | private final BlockModelResolver blockModelResolver;
|
| 23 |
|
| 24 | public IronGolemRenderer(final EntityRendererProvider.Context context) {
|
| 25 | super(context, new IronGolemModel(context.bakeLayer(ModelLayers.IRON_GOLEM)), 0.7F);
|
| 26 | this.blockModelResolver = context.getBlockModelResolver();
|
| 27 | this.addLayer(new IronGolemCrackinessLayer(this));
|
| 28 | this.addLayer(new IronGolemFlowerLayer(this));
|
| 29 | }
|
| 30 |
|
| 31 | public Identifier getTextureLocation(final IronGolemRenderState state) {
|
| 32 | return GOLEM_LOCATION;
|
| 33 | }
|
| 34 |
|
| 35 | public IronGolemRenderState createRenderState() {
|
| 36 | return new IronGolemRenderState();
|
| 37 | }
|
| 38 |
|
| 39 | public void extractRenderState(final IronGolem entity, final IronGolemRenderState state, final float partialTicks) {
|
| 40 | super.extractRenderState(entity, state, partialTicks);
|
| 41 | state.attackTicksRemaining = entity.getAttackAnimationTick() > 0.0F ? entity.getAttackAnimationTick() - partialTicks : 0.0F;
|
| 42 | state.offerFlowerTick = entity.getOfferFlowerTick();
|
| 43 | if (state.offerFlowerTick > 0) {
|
| 44 | this.blockModelResolver.update(state.flowerBlock, Blocks.POPPY.defaultBlockState(), BLOCK_DISPLAY_CONTEXT);
|
| 45 | } else {
|
| 46 | state.flowerBlock.clear();
|
| 47 | }
|
| 48 |
|
| 49 | state.crackiness = entity.getCrackiness();
|
| 50 | }
|
| 51 |
|
| 52 | protected void setupRotations(final IronGolemRenderState state, final PoseStack poseStack, final float bodyRot, final float entityScale) {
|
| 53 | super.setupRotations(state, poseStack, bodyRot, entityScale);
|
| 54 | if (!(state.walkAnimationSpeed < 0.01)) {
|
| 55 | float p = 13.0F;
|
| 56 | float wp = state.walkAnimationPos + 6.0F;
|
| 57 | float triangleWave = (Math.abs(wp % 13.0F - 6.5F) - 3.25F) / 3.25F;
|
| 58 | poseStack.rotateDegrees(Axis.ZP, 6.5F * triangleWave);
|
| 59 | }
|
| 60 | }
|
| 61 | }
|
| 62 |
|