| 1 | package net.minecraft.client.renderer.blockentity;
|
| 2 |
|
| 3 | import com.mojang.math.Axis;
|
| 4 | import com.mojang.math.Transformation;
|
| 5 | import net.fabricmc.api.EnvType;
|
| 6 | import net.fabricmc.api.Environment;
|
| 7 | import net.minecraft.client.renderer.blockentity.state.SignRenderState;
|
| 8 | import net.minecraft.client.renderer.blockentity.state.StandingSignRenderState;
|
| 9 | import net.minecraft.client.renderer.feature.ModelFeatureRenderer;
|
| 10 | import net.minecraft.core.Direction;
|
| 11 | import net.minecraft.world.level.block.PlainSignBlock;
|
| 12 | import net.minecraft.world.level.block.StandingSignBlock;
|
| 13 | import net.minecraft.world.level.block.WallSignBlock;
|
| 14 | import net.minecraft.world.level.block.PlainSignBlock.Attachment;
|
| 15 | import net.minecraft.world.level.block.entity.SignBlockEntity;
|
| 16 | import net.minecraft.world.level.block.state.BlockState;
|
| 17 | import net.minecraft.world.level.block.state.properties.RotationSegment;
|
| 18 | import net.minecraft.world.phys.Vec3;
|
| 19 | import org.joml.Matrix4f;
|
| 20 | import org.joml.Vector3f;
|
| 21 | import org.joml.Vector3fc;
|
| 22 | import org.jspecify.annotations.Nullable;
|
| 23 |
|
| 24 | @Environment(EnvType.CLIENT)
|
| 25 | public class StandingSignRenderer extends AbstractSignRenderer<StandingSignRenderState> {
|
| 26 | private static final float RENDER_SCALE = 0.6666667F;
|
| 27 | private static final Vector3fc TEXT_OFFSET = new Vector3f(0.0F, 0.33333334F, 0.046666667F);
|
| 28 | public static final WallAndGroundTransformations<SignRenderState.SignTransformations> TRANSFORMATIONS = new WallAndGroundTransformations<>(
|
| 29 | StandingSignRenderer::createWallTransformation, StandingSignRenderer::createGroundTransformation, 16
|
| 30 | );
|
| 31 |
|
| 32 | public StandingSignRenderer(final BlockEntityRendererProvider.Context context) {
|
| 33 | super(context);
|
| 34 | }
|
| 35 |
|
| 36 | public StandingSignRenderState createRenderState() {
|
| 37 | return new StandingSignRenderState();
|
| 38 | }
|
| 39 |
|
| 40 | public void extractRenderState(
|
| 41 | final SignBlockEntity blockEntity,
|
| 42 | final StandingSignRenderState state,
|
| 43 | final float partialTicks,
|
| 44 | final Vec3 cameraPosition,
|
| 45 | final ModelFeatureRenderer.@Nullable CrumblingOverlay breakProgress
|
| 46 | ) {
|
| 47 | super.extractRenderState(blockEntity, state, partialTicks, cameraPosition, breakProgress);
|
| 48 | BlockState blockState = blockEntity.getBlockState();
|
| 49 | state.attachmentType = PlainSignBlock.getAttachmentPoint(blockState);
|
| 50 | if (blockState.getBlock() instanceof WallSignBlock) {
|
| 51 | state.transformations = TRANSFORMATIONS.wallTransformation(blockState.getValue(WallSignBlock.FACING));
|
| 52 | } else {
|
| 53 | state.transformations = TRANSFORMATIONS.freeTransformations(blockState.getValue(StandingSignBlock.ROTATION));
|
| 54 | }
|
| 55 | }
|
| 56 |
|
| 57 | private static Transformation textTransformation(final Attachment attachmentType, final float angle, final boolean isFrontText) {
|
| 58 | Matrix4f result = new Matrix4f().translate(0.5F, 0.5F, 0.5F).rotate(Axis.YP.rotationDegrees(-angle));
|
| 59 | if (attachmentType == Attachment.WALL) {
|
| 60 | result.translate(0.0F, -0.3125F, -0.4375F);
|
| 61 | }
|
| 62 |
|
| 63 | if (!isFrontText) {
|
| 64 | result.rotate(Axis.YP.rotationDegrees(180.0F));
|
| 65 | }
|
| 66 |
|
| 67 | float s = 0.010416667F;
|
| 68 | return new Transformation(result.translate(TEXT_OFFSET).scale(0.010416667F, -0.010416667F, 0.010416667F));
|
| 69 | }
|
| 70 |
|
| 71 | private static SignRenderState.SignTransformations createTransformations(final Attachment attachmentType, final float angle) {
|
| 72 | return new SignRenderState.SignTransformations(textTransformation(attachmentType, angle, true), textTransformation(attachmentType, angle, false));
|
| 73 | }
|
| 74 |
|
| 75 | private static SignRenderState.SignTransformations createGroundTransformation(final int segment) {
|
| 76 | return createTransformations(Attachment.GROUND, RotationSegment.convertToDegrees(segment));
|
| 77 | }
|
| 78 |
|
| 79 | private static SignRenderState.SignTransformations createWallTransformation(final Direction direction) {
|
| 80 | return createTransformations(Attachment.WALL, direction.toYRot());
|
| 81 | }
|
| 82 | }
|
| 83 |
|