| 1 | package net.minecraft.client.renderer.entity;
|
| 2 |
|
| 3 | import com.mojang.blaze3d.vertex.PoseStack;
|
| 4 | import java.util.Objects;
|
| 5 | import net.fabricmc.api.EnvType;
|
| 6 | import net.fabricmc.api.Environment;
|
| 7 | import net.minecraft.client.model.geom.ModelLayers;
|
| 8 | import net.minecraft.client.model.monster.shulker.ShulkerModel;
|
| 9 | import net.minecraft.client.renderer.Sheets;
|
| 10 | import net.minecraft.client.renderer.culling.Frustum;
|
| 11 | import net.minecraft.client.renderer.entity.state.ShulkerRenderState;
|
| 12 | import net.minecraft.resources.Identifier;
|
| 13 | import net.minecraft.world.entity.EntityType;
|
| 14 | import net.minecraft.world.entity.monster.Shulker;
|
| 15 | import net.minecraft.world.item.DyeColor;
|
| 16 | import net.minecraft.world.phys.AABB;
|
| 17 | import net.minecraft.world.phys.Vec3;
|
| 18 | import org.jspecify.annotations.Nullable;
|
| 19 |
|
| 20 | @Environment(EnvType.CLIENT)
|
| 21 | public class ShulkerRenderer extends MobRenderer<Shulker, ShulkerRenderState, ShulkerModel> {
|
| 22 | private static final Identifier DEFAULT_TEXTURE_LOCATION = Sheets.DEFAULT_SHULKER_TEXTURE_LOCATION.texture().withPath(path -> "textures/" + path + ".png");
|
| 23 | private static final Identifier[] TEXTURE_LOCATION = Sheets.SHULKER_TEXTURE_LOCATION
|
| 24 | .stream()
|
| 25 | .map(location -> location.texture().withPath(path -> "textures/" + path + ".png"))
|
| 26 | .toArray(Identifier[]::new);
|
| 27 |
|
| 28 | public ShulkerRenderer(final EntityRendererProvider.Context context) {
|
| 29 | super(context, new ShulkerModel(context.bakeLayer(ModelLayers.SHULKER)), 0.0F);
|
| 30 | }
|
| 31 |
|
| 32 | public Vec3 getRenderOffset(final ShulkerRenderState state) {
|
| 33 | return state.renderOffset;
|
| 34 | }
|
| 35 |
|
| 36 | public boolean shouldRender(final Shulker entity, final Frustum culler, final double camX, final double camY, final double camZ, final float partialTicks) {
|
| 37 | if (super.shouldRender(entity, culler, camX, camY, camZ, partialTicks)) {
|
| 38 | return true;
|
| 39 | }
|
| 40 |
|
| 41 | Vec3 startPos = entity.getRenderPosition(0.0F);
|
| 42 | if (startPos == null) {
|
| 43 | return false;
|
| 44 | }
|
| 45 |
|
| 46 | EntityType<?> type = entity.getType();
|
| 47 | float halfHeight = type.getHeight() / 2.0F;
|
| 48 | float halfWidth = type.getWidth() / 2.0F;
|
| 49 | Vec3 targetPos = Vec3.atBottomCenterOf(entity.blockPosition());
|
| 50 | return culler.isVisible(
|
| 51 | new AABB(startPos.x, startPos.y + halfHeight, startPos.z, targetPos.x, targetPos.y + halfHeight, targetPos.z).inflate(halfWidth, halfHeight, halfWidth)
|
| 52 | );
|
| 53 | }
|
| 54 |
|
| 55 | public Identifier getTextureLocation(final ShulkerRenderState state) {
|
| 56 | return getTextureLocation(state.color);
|
| 57 | }
|
| 58 |
|
| 59 | public ShulkerRenderState createRenderState() {
|
| 60 | return new ShulkerRenderState();
|
| 61 | }
|
| 62 |
|
| 63 | public void extractRenderState(final Shulker entity, final ShulkerRenderState state, final float partialTicks) {
|
| 64 | super.extractRenderState(entity, state, partialTicks);
|
| 65 | state.renderOffset = Objects.requireNonNullElse(entity.getRenderPosition(partialTicks), Vec3.ZERO);
|
| 66 | state.color = entity.getColor();
|
| 67 | state.peekAmount = entity.getClientPeekAmount(partialTicks);
|
| 68 | state.yHeadRot = entity.yHeadRot;
|
| 69 | state.yBodyRot = entity.yBodyRot;
|
| 70 | state.attachFace = entity.getAttachFace();
|
| 71 | }
|
| 72 |
|
| 73 | public static Identifier getTextureLocation(final @Nullable DyeColor color) {
|
| 74 | return color == null ? DEFAULT_TEXTURE_LOCATION : TEXTURE_LOCATION[color.getId()];
|
| 75 | }
|
| 76 |
|
| 77 | protected void setupRotations(final ShulkerRenderState state, final PoseStack poseStack, final float bodyRot, final float entityScale) {
|
| 78 | super.setupRotations(state, poseStack, bodyRot + 180.0F, entityScale);
|
| 79 | poseStack.rotateAround(state.attachFace.getOpposite().getRotation(), 0.0F, 0.5F, 0.0F);
|
| 80 | }
|
| 81 | }
|
| 82 |
|