67 lines
3.1 KiB
Java
67 lines
3.1 KiB
Java
package net.minecraft.client.renderer.entity;
|
|
|
|
import com.mojang.blaze3d.vertex.PoseStack;
|
|
import com.mojang.blaze3d.vertex.VertexConsumer;
|
|
import net.fabricmc.api.EnvType;
|
|
import net.fabricmc.api.Environment;
|
|
import net.minecraft.client.model.SkullModel;
|
|
import net.minecraft.client.model.geom.ModelLayers;
|
|
import net.minecraft.client.model.geom.PartPose;
|
|
import net.minecraft.client.model.geom.builders.CubeListBuilder;
|
|
import net.minecraft.client.model.geom.builders.LayerDefinition;
|
|
import net.minecraft.client.model.geom.builders.MeshDefinition;
|
|
import net.minecraft.client.model.geom.builders.PartDefinition;
|
|
import net.minecraft.client.renderer.MultiBufferSource;
|
|
import net.minecraft.client.renderer.entity.state.WitherSkullRenderState;
|
|
import net.minecraft.client.renderer.texture.OverlayTexture;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.resources.ResourceLocation;
|
|
import net.minecraft.world.entity.projectile.WitherSkull;
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
public class WitherSkullRenderer extends EntityRenderer<WitherSkull, WitherSkullRenderState> {
|
|
private static final ResourceLocation WITHER_INVULNERABLE_LOCATION = ResourceLocation.withDefaultNamespace("textures/entity/wither/wither_invulnerable.png");
|
|
private static final ResourceLocation WITHER_LOCATION = ResourceLocation.withDefaultNamespace("textures/entity/wither/wither.png");
|
|
private final SkullModel model;
|
|
|
|
public WitherSkullRenderer(EntityRendererProvider.Context context) {
|
|
super(context);
|
|
this.model = new SkullModel(context.bakeLayer(ModelLayers.WITHER_SKULL));
|
|
}
|
|
|
|
public static LayerDefinition createSkullLayer() {
|
|
MeshDefinition meshDefinition = new MeshDefinition();
|
|
PartDefinition partDefinition = meshDefinition.getRoot();
|
|
partDefinition.addOrReplaceChild("head", CubeListBuilder.create().texOffs(0, 35).addBox(-4.0F, -8.0F, -4.0F, 8.0F, 8.0F, 8.0F), PartPose.ZERO);
|
|
return LayerDefinition.create(meshDefinition, 64, 64);
|
|
}
|
|
|
|
protected int getBlockLightLevel(WitherSkull entity, BlockPos pos) {
|
|
return 15;
|
|
}
|
|
|
|
public void render(WitherSkullRenderState renderState, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {
|
|
poseStack.pushPose();
|
|
poseStack.scale(-1.0F, -1.0F, 1.0F);
|
|
VertexConsumer vertexConsumer = bufferSource.getBuffer(this.model.renderType(this.getTextureLocation(renderState)));
|
|
this.model.setupAnim(0.0F, renderState.yRot, renderState.xRot);
|
|
this.model.renderToBuffer(poseStack, vertexConsumer, packedLight, OverlayTexture.NO_OVERLAY);
|
|
poseStack.popPose();
|
|
super.render(renderState, poseStack, bufferSource, packedLight);
|
|
}
|
|
|
|
private ResourceLocation getTextureLocation(WitherSkullRenderState renderState) {
|
|
return renderState.isDangerous ? WITHER_INVULNERABLE_LOCATION : WITHER_LOCATION;
|
|
}
|
|
|
|
public WitherSkullRenderState createRenderState() {
|
|
return new WitherSkullRenderState();
|
|
}
|
|
|
|
public void extractRenderState(WitherSkull entity, WitherSkullRenderState reusedState, float partialTick) {
|
|
super.extractRenderState(entity, reusedState, partialTick);
|
|
reusedState.isDangerous = entity.isDangerous();
|
|
reusedState.yRot = entity.getYRot(partialTick);
|
|
reusedState.xRot = entity.getXRot(partialTick);
|
|
}
|
|
}
|