| 1 | package net.minecraft.client.renderer.entity;
|
| 2 |
|
| 3 | import com.mojang.blaze3d.vertex.PoseStack;
|
| 4 | import com.mojang.math.Axis;
|
| 5 | import java.util.EnumMap;
|
| 6 | import net.fabricmc.api.EnvType;
|
| 7 | import net.fabricmc.api.Environment;
|
| 8 | import net.minecraft.client.model.geom.ModelLayers;
|
| 9 | import net.minecraft.client.model.object.cushion.CushionModel;
|
| 10 | import net.minecraft.client.renderer.SubmitNodeCollector;
|
| 11 | import net.minecraft.client.renderer.entity.state.CushionRenderState;
|
| 12 | import net.minecraft.client.renderer.state.level.CameraRenderState;
|
| 13 | import net.minecraft.client.renderer.texture.OverlayTexture;
|
| 14 | import net.minecraft.core.Direction;
|
| 15 | import net.minecraft.resources.Identifier;
|
| 16 | import net.minecraft.util.Util;
|
| 17 | import net.minecraft.world.entity.decoration.Cushion;
|
| 18 | import net.minecraft.world.item.DyeColor;
|
| 19 |
|
| 20 | @Environment(EnvType.CLIENT)
|
| 21 | public class CushionRenderer extends EntityRenderer<Cushion, CushionRenderState> {
|
| 22 | private static final EnumMap<DyeColor, Identifier> TEXTURES_BY_COLOR = Util.make(new EnumMap<>(DyeColor.class), textures -> {
|
| 23 | for (DyeColor color : DyeColor.values()) {
|
| 24 | textures.put(color, Identifier.withDefaultNamespace("textures/entity/cushion/" + color.getName() + "_cushion.png"));
|
| 25 | }
|
| 26 | });
|
| 27 | private final CushionModel model;
|
| 28 |
|
| 29 | public CushionRenderer(final EntityRendererProvider.Context context) {
|
| 30 | super(context);
|
| 31 | this.model = new CushionModel(context.bakeLayer(ModelLayers.CUSHION));
|
| 32 | }
|
| 33 |
|
| 34 | public void extractRenderState(final Cushion cushion, final CushionRenderState state, final float partialTicks) {
|
| 35 | super.extractRenderState(cushion, state, partialTicks);
|
| 36 | state.direction = Direction.fromYRot(cushion.getYRot());
|
| 37 | state.texture = TEXTURES_BY_COLOR.get(cushion.getColor());
|
| 38 | }
|
| 39 |
|
| 40 | public void submit(final CushionRenderState state, final PoseStack poseStack, final SubmitNodeCollector submitNodeCollector, final CameraRenderState camera) {
|
| 41 | poseStack.pushPose();
|
| 42 | poseStack.rotateDegrees(Axis.YP, 180.0F - state.direction.toYRot());
|
| 43 | poseStack.rotateDegrees(Axis.XP, 180.0F);
|
| 44 | poseStack.translate(0.0, -0.25, 0.0);
|
| 45 | submitNodeCollector.submitModel(
|
| 46 | this.model, state, poseStack, this.model.renderType(state.texture), state.lightCoords, OverlayTexture.NO_OVERLAY, state.outlineColor
|
| 47 | );
|
| 48 | poseStack.popPose();
|
| 49 | super.submit(state, poseStack, submitNodeCollector, camera);
|
| 50 | }
|
| 51 |
|
| 52 | public CushionRenderState createRenderState() {
|
| 53 | return new CushionRenderState();
|
| 54 | }
|
| 55 | }
|
| 56 |
|