package net.minecraft.client.renderer.entity; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Axis; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.model.ArmorStandArmorModel; import net.minecraft.client.model.ArmorStandModel; import net.minecraft.client.model.geom.ModelLayers; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.entity.layers.CustomHeadLayer; import net.minecraft.client.renderer.entity.layers.ElytraLayer; import net.minecraft.client.renderer.entity.layers.HumanoidArmorLayer; import net.minecraft.client.renderer.entity.layers.ItemInHandLayer; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; import net.minecraft.world.entity.decoration.ArmorStand; import org.jetbrains.annotations.Nullable; @Environment(EnvType.CLIENT) public class ArmorStandRenderer extends LivingEntityRenderer { /** * A constant instance of the armor stand texture, wrapped inside a ResourceLocation wrapper. */ public static final ResourceLocation DEFAULT_SKIN_LOCATION = ResourceLocation.withDefaultNamespace("textures/entity/armorstand/wood.png"); public ArmorStandRenderer(EntityRendererProvider.Context context) { super(context, new ArmorStandModel(context.bakeLayer(ModelLayers.ARMOR_STAND)), 0.0F); this.addLayer( new HumanoidArmorLayer<>( this, new ArmorStandArmorModel(context.bakeLayer(ModelLayers.ARMOR_STAND_INNER_ARMOR)), new ArmorStandArmorModel(context.bakeLayer(ModelLayers.ARMOR_STAND_OUTER_ARMOR)), context.getModelManager() ) ); this.addLayer(new ItemInHandLayer<>(this, context.getItemInHandRenderer())); this.addLayer(new ElytraLayer<>(this, context.getModelSet())); this.addLayer(new CustomHeadLayer<>(this, context.getModelSet(), context.getItemInHandRenderer())); } /** * Returns the location of an entity's texture. */ public ResourceLocation getTextureLocation(ArmorStand entity) { return DEFAULT_SKIN_LOCATION; } protected void setupRotations(ArmorStand entity, PoseStack poseStack, float bob, float yBodyRot, float partialTick, float scale) { poseStack.mulPose(Axis.YP.rotationDegrees(180.0F - yBodyRot)); float f = (float)(entity.level().getGameTime() - entity.lastHit) + partialTick; if (f < 5.0F) { poseStack.mulPose(Axis.YP.rotationDegrees(Mth.sin(f / 1.5F * (float) Math.PI) * 3.0F)); } } protected boolean shouldShowName(ArmorStand entity) { double d = this.entityRenderDispatcher.distanceToSqr(entity); float f = entity.isCrouching() ? 32.0F : 64.0F; return d >= f * f ? false : entity.isCustomNameVisible(); } @Nullable protected RenderType getRenderType(ArmorStand livingEntity, boolean bodyVisible, boolean translucent, boolean glowing) { if (!livingEntity.isMarker()) { return super.getRenderType(livingEntity, bodyVisible, translucent, glowing); } else { ResourceLocation resourceLocation = this.getTextureLocation(livingEntity); if (translucent) { return RenderType.entityTranslucent(resourceLocation, false); } else { return bodyVisible ? RenderType.entityCutoutNoCull(resourceLocation, false) : null; } } } }