| 1 | package net.minecraft.client.renderer.entity;
|
| 2 |
|
| 3 | import net.fabricmc.api.EnvType;
|
| 4 | import net.fabricmc.api.Environment;
|
| 5 | import net.minecraft.client.model.geom.ModelLayers;
|
| 6 | import net.minecraft.client.model.monster.enderman.EndermanModel;
|
| 7 | import net.minecraft.client.renderer.block.BlockModelResolver;
|
| 8 | import net.minecraft.client.renderer.block.model.BlockDisplayContext;
|
| 9 | import net.minecraft.client.renderer.entity.layers.CarriedBlockLayer;
|
| 10 | import net.minecraft.client.renderer.entity.layers.EnderEyesLayer;
|
| 11 | import net.minecraft.client.renderer.entity.state.EndermanRenderState;
|
| 12 | import net.minecraft.resources.Identifier;
|
| 13 | import net.minecraft.util.RandomSource;
|
| 14 | import net.minecraft.world.entity.monster.Enderman;
|
| 15 | import net.minecraft.world.level.block.state.BlockState;
|
| 16 | import net.minecraft.world.phys.Vec3;
|
| 17 |
|
| 18 | @Environment(EnvType.CLIENT)
|
| 19 | public class EndermanRenderer extends MobRenderer<Enderman, EndermanRenderState, EndermanModel<EndermanRenderState>> {
|
| 20 | public static final BlockDisplayContext BLOCK_DISPLAY_CONTEXT = BlockDisplayContext.create();
|
| 21 | private static final Identifier ENDERMAN_LOCATION = Identifier.withDefaultNamespace("textures/entity/enderman/enderman.png");
|
| 22 | private final RandomSource random = RandomSource.create();
|
| 23 | private final BlockModelResolver blockModelResolver;
|
| 24 |
|
| 25 | public EndermanRenderer(final EntityRendererProvider.Context context) {
|
| 26 | super(context, new EndermanModel<>(context.bakeLayer(ModelLayers.ENDERMAN)), 0.5F);
|
| 27 | this.blockModelResolver = context.getBlockModelResolver();
|
| 28 | this.addLayer(new EnderEyesLayer(this));
|
| 29 | this.addLayer(new CarriedBlockLayer(this));
|
| 30 | }
|
| 31 |
|
| 32 | public Vec3 getRenderOffset(final EndermanRenderState state) {
|
| 33 | Vec3 offset = super.getRenderOffset(state);
|
| 34 | if (state.isCreepy) {
|
| 35 | double d = 0.02 * state.scale;
|
| 36 | return offset.add(this.random.nextGaussian() * d, 0.0, this.random.nextGaussian() * d);
|
| 37 | } else {
|
| 38 | return offset;
|
| 39 | }
|
| 40 | }
|
| 41 |
|
| 42 | public Identifier getTextureLocation(final EndermanRenderState state) {
|
| 43 | return ENDERMAN_LOCATION;
|
| 44 | }
|
| 45 |
|
| 46 | public EndermanRenderState createRenderState() {
|
| 47 | return new EndermanRenderState();
|
| 48 | }
|
| 49 |
|
| 50 | public void extractRenderState(final Enderman entity, final EndermanRenderState state, final float partialTicks) {
|
| 51 | super.extractRenderState(entity, state, partialTicks);
|
| 52 | HumanoidMobRenderer.extractHumanoidRenderState(entity, state, partialTicks, this.itemModelResolver);
|
| 53 | state.isCreepy = entity.isCreepy();
|
| 54 | BlockState carriedBlock = entity.getCarriedBlock();
|
| 55 | if (carriedBlock != null) {
|
| 56 | this.blockModelResolver.update(state.carriedBlock, carriedBlock, BLOCK_DISPLAY_CONTEXT);
|
| 57 | } else {
|
| 58 | state.carriedBlock.clear();
|
| 59 | }
|
| 60 | }
|
| 61 | }
|
| 62 |
|