G

CustomArmorStandRenderer

public
Guest Aug 13, 2024 Never 33
Clone
Java CustomArmorStandRenderer 66 lines (54 loc) | 3.13 KB
1
package net.hero61.projectspartan.entity.client;
2
3
import com.mojang.blaze3d.vertex.PoseStack;
4
import com.mojang.math.Axis;
5
import net.hero61.projectspartan.entity.client.model.ModelCustomStand;
6
import net.hero61.projectspartan.entity.custom.CustomArmorStand;
7
import net.minecraft.client.renderer.RenderType;
8
import net.minecraft.client.renderer.entity.EntityRendererProvider;
9
import net.minecraft.client.renderer.entity.LivingEntityRenderer;
10
import net.minecraft.client.renderer.entity.layers.CustomHeadLayer;
11
import net.minecraft.client.renderer.entity.layers.ElytraLayer;
12
import net.minecraft.client.renderer.entity.layers.ItemInHandLayer;
13
import net.minecraft.resources.ResourceLocation;
14
import net.minecraft.util.Mth;
15
import net.minecraftforge.api.distmarker.Dist;
16
import net.minecraftforge.api.distmarker.OnlyIn;
17
18
import javax.annotation.Nullable;
19
20
@OnlyIn(Dist.CLIENT)
21
public class CustomArmorStandRenderer extends LivingEntityRenderer<CustomArmorStand, ModelCustomStand> {
22
23
public CustomArmorStandRenderer(EntityRendererProvider.Context context) {
24
super(context, new ModelCustomStand(context.bakeLayer(ModModelLayers.CUSTOM_ARMOR_STAND_LAYER)), 0.0F);
25
//this.addLayer(new HumanoidArmorLayer<>(this, new ModModelLayers(context.bakeLayer(ModModelLayers.CUSTOM_ARMOR_STAND_LAYER)), new ModelCustomStand(context.bakeLayer(ModModelLayers.CUSTOM_ARMOR_STAND_LAYER)), context.getModelManager()));
26
//this.addLayer(new ItemInHandLayer<>(this, context.getItemInHandRenderer()));
27
//this.addLayer(new ElytraLayer<>(this, context.getModelSet()));
28
//this.addLayer(new CustomHeadLayer<>(this, context.getModelSet(), context.getItemInHandRenderer()));
29
}
30
31
@Override
32
public ResourceLocation getTextureLocation(CustomArmorStand pEntity) {
33
return new ResourceLocation("mcspartan","textures/models/entity/custom_armor_stand.png");
34
}
35
36
/**
37
* Returns the location of an entity's texture.
38
*/
39
40
protected void setupRotations(CustomArmorStand pEntityLiving, PoseStack pMatrixStack, float pAgeInTicks, float pRotationYaw, float pPartialTicks) {
41
pMatrixStack.mulPose(Axis.YP.rotationDegrees(180.0F - pRotationYaw));
42
float f = (float)(pEntityLiving.level().getGameTime() - pEntityLiving.lastHit) + pPartialTicks;
43
if (f < 5.0F) {
44
pMatrixStack.mulPose(Axis.YP.rotationDegrees(Mth.sin(f / 1.5F * (float)Math.PI) * 3.0F));
45
}
46
47
}
48
49
protected boolean shouldShowName(CustomArmorStand pEntity) {
50
double d0 = this.entityRenderDispatcher.distanceToSqr(pEntity);
51
float f = pEntity.isCrouching() ? 32.0F : 64.0F;
52
return d0 >= (double)(f * f) ? false : pEntity.isCustomNameVisible();
53
}
54
55
@Override
56
protected RenderType getRenderType(CustomArmorStand entity, boolean isBodyVisible, boolean isTranslucent, boolean isGlowing) {
57
ResourceLocation texture = getTextureLocation(entity);
58
if (isTranslucent) {
59
return RenderType.entityTranslucentCull(texture);
60
} else {
61
return isBodyVisible ? RenderType.entityCutoutNoCull(texture) : null;
62
}
63
}
64
65
66
}
67