| 1 | package net.minecraft.client.renderer.blockentity;
|
| 2 |
|
| 3 | import com.mojang.blaze3d.vertex.PoseStack;
|
| 4 | import com.mojang.blaze3d.vertex.VertexConsumer;
|
| 5 | import java.util.Collection;
|
| 6 | import java.util.List;
|
| 7 | import java.util.Map;
|
| 8 | import java.util.function.Consumer;
|
| 9 | import net.fabricmc.api.EnvType;
|
| 10 | import net.fabricmc.api.Environment;
|
| 11 | import net.minecraft.client.renderer.FaceInfo;
|
| 12 | import net.minecraft.client.renderer.SubmitNodeCollector;
|
| 13 | import net.minecraft.client.renderer.blockentity.state.EndPortalRenderState;
|
| 14 | import net.minecraft.client.renderer.feature.ModelFeatureRenderer;
|
| 15 | import net.minecraft.client.renderer.rendertype.RenderType;
|
| 16 | import net.minecraft.core.Direction;
|
| 17 | import net.minecraft.resources.Identifier;
|
| 18 | import net.minecraft.util.Util;
|
| 19 | import net.minecraft.world.level.block.entity.TheEndPortalBlockEntity;
|
| 20 | import net.minecraft.world.phys.Vec3;
|
| 21 | import org.joml.Vector3f;
|
| 22 | import org.joml.Vector3fc;
|
| 23 | import org.jspecify.annotations.Nullable;
|
| 24 |
|
| 25 | @Environment(EnvType.CLIENT)
|
| 26 | public abstract class AbstractEndPortalRenderer<T extends TheEndPortalBlockEntity, S extends EndPortalRenderState> implements BlockEntityRenderer<T, S> {
|
| 27 | private static final Vector3fc FROM = new Vector3f(0.0F, 0.0F, 0.0F);
|
| 28 | private static final Vector3fc TO = new Vector3f(1.0F, 1.0F, 1.0F);
|
| 29 | private static final Map<Direction, List<Vector3fc>> FACES = Util.makeEnumMap(
|
| 30 | Direction.class,
|
| 31 | direction -> {
|
| 32 | FaceInfo faceInfo = FaceInfo.fromFacing(direction);
|
| 33 | return List.of(
|
| 34 | faceInfo.getVertexInfo(0).select(FROM, TO),
|
| 35 | faceInfo.getVertexInfo(1).select(FROM, TO),
|
| 36 | faceInfo.getVertexInfo(2).select(FROM, TO),
|
| 37 | faceInfo.getVertexInfo(3).select(FROM, TO)
|
| 38 | );
|
| 39 | }
|
| 40 | );
|
| 41 | public static final Identifier END_SKY_LOCATION = Identifier.withDefaultNamespace("textures/environment/end_sky.png");
|
| 42 | public static final Identifier END_PORTAL_LOCATION = Identifier.withDefaultNamespace("textures/entity/end_portal/end_portal.png");
|
| 43 | private static final List<Direction> ALL_FACES = List.of(Direction.values());
|
| 44 |
|
| 45 | public void extractRenderState(
|
| 46 | final T blockEntity, final S state, final float partialTicks, final Vec3 cameraPosition, final ModelFeatureRenderer.@Nullable CrumblingOverlay breakProgress
|
| 47 | ) {
|
| 48 | BlockEntityRenderer.super.extractRenderState(blockEntity, state, partialTicks, cameraPosition, breakProgress);
|
| 49 | state.facesToShow.clear();
|
| 50 |
|
| 51 | for (Direction direction : Direction.values()) {
|
| 52 | if (blockEntity.shouldRenderFace(direction)) {
|
| 53 | state.facesToShow.add(direction);
|
| 54 | }
|
| 55 | }
|
| 56 | }
|
| 57 |
|
| 58 | protected static void submitCube(
|
| 59 | final Collection<Direction> facesToShow, final RenderType renderType, final PoseStack poseStack, final SubmitNodeCollector submitNodeCollector
|
| 60 | ) {
|
| 61 | submitCube(facesToShow, renderType, poseStack, submitNodeCollector, vertex -> {});
|
| 62 | }
|
| 63 |
|
| 64 | private static void submitCube(
|
| 65 | final Collection<Direction> facesToShow,
|
| 66 | final RenderType renderType,
|
| 67 | final PoseStack poseStack,
|
| 68 | final SubmitNodeCollector submitNodeCollector,
|
| 69 | final Consumer<VertexConsumer> vertexDecorator
|
| 70 | ) {
|
| 71 | if (!facesToShow.isEmpty()) {
|
| 72 | submitNodeCollector.submitCustomGeometry(poseStack, renderType, (pose, buffer) -> {
|
| 73 | for (Direction direction : facesToShow) {
|
| 74 | for (Vector3fc faceVertex : FACES.get(direction)) {
|
| 75 | vertexDecorator.accept(buffer.addVertex(pose, faceVertex));
|
| 76 | }
|
| 77 | }
|
| 78 | });
|
| 79 | }
|
| 80 | }
|
| 81 |
|
| 82 | public static void submitSpecial(final RenderType renderType, final PoseStack poseStack, final SubmitNodeCollector submitNodeCollector, final int outlineColor) {
|
| 83 | submitCube(ALL_FACES, renderType, poseStack, submitNodeCollector);
|
| 84 | if (outlineColor != 0) {
|
| 85 | submitCube(ALL_FACES, renderType.outline().orElseThrow(), poseStack, submitNodeCollector, vertex -> vertex.setUv(0.0F, 0.0F).setColor(outlineColor));
|
| 86 | }
|
| 87 | }
|
| 88 |
|
| 89 | public static void getExtents(final Consumer<Vector3fc> output) {
|
| 90 | FACES.values().forEach(vertices -> vertices.forEach(output));
|
| 91 | }
|
| 92 | }
|
| 93 |
|