/* * Decompiled with CFR 0.152. * * Could not load the following classes: * it.unimi.dsi.fastutil.ints.Int2IntFunction * org.joml.Quaternionfc * org.joml.Vector3f * org.jspecify.annotations.Nullable */ package net.minecraft.client.renderer.blockentity; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Axis; import it.unimi.dsi.fastutil.ints.Int2IntFunction; import java.util.Set; import net.minecraft.client.model.Model; import net.minecraft.client.model.geom.EntityModelSet; import net.minecraft.client.model.geom.ModelLayers; import net.minecraft.client.model.geom.PartPose; import net.minecraft.client.model.geom.builders.CubeListBuilder; import net.minecraft.client.model.geom.builders.LayerDefinition; import net.minecraft.client.model.geom.builders.MeshDefinition; import net.minecraft.client.model.geom.builders.PartDefinition; import net.minecraft.client.renderer.Sheets; import net.minecraft.client.renderer.SubmitNodeCollector; import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; import net.minecraft.client.renderer.blockentity.BrightnessCombiner; import net.minecraft.client.renderer.blockentity.state.BedRenderState; import net.minecraft.client.renderer.feature.ModelFeatureRenderer; import net.minecraft.client.renderer.rendertype.RenderTypes; import net.minecraft.client.renderer.special.SpecialModelRenderer; import net.minecraft.client.renderer.state.CameraRenderState; import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.client.resources.model.Material; import net.minecraft.client.resources.model.MaterialSet; import net.minecraft.core.Direction; import net.minecraft.util.Unit; import net.minecraft.world.level.block.BedBlock; import net.minecraft.world.level.block.ChestBlock; import net.minecraft.world.level.block.DoubleBlockCombiner; import net.minecraft.world.level.block.entity.BedBlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.properties.BedPart; import net.minecraft.world.phys.Vec3; import org.joml.Quaternionfc; import org.joml.Vector3f; import org.jspecify.annotations.Nullable; public class BedRenderer implements BlockEntityRenderer { private final MaterialSet materials; private final Model.Simple headModel; private final Model.Simple footModel; public BedRenderer(BlockEntityRendererProvider.Context context) { this(context.materials(), context.entityModelSet()); } public BedRenderer(SpecialModelRenderer.BakingContext context) { this(context.materials(), context.entityModelSet()); } public BedRenderer(MaterialSet materials, EntityModelSet entityModelSet) { this.materials = materials; this.headModel = new Model.Simple(entityModelSet.bakeLayer(ModelLayers.BED_HEAD), RenderTypes::entitySolid); this.footModel = new Model.Simple(entityModelSet.bakeLayer(ModelLayers.BED_FOOT), RenderTypes::entitySolid); } public static LayerDefinition createHeadLayer() { MeshDefinition mesh = new MeshDefinition(); PartDefinition root = mesh.getRoot(); root.addOrReplaceChild("main", CubeListBuilder.create().texOffs(0, 0).addBox(0.0f, 0.0f, 0.0f, 16.0f, 16.0f, 6.0f), PartPose.ZERO); root.addOrReplaceChild("left_leg", CubeListBuilder.create().texOffs(50, 6).addBox(0.0f, 6.0f, 0.0f, 3.0f, 3.0f, 3.0f), PartPose.rotation(1.5707964f, 0.0f, 1.5707964f)); root.addOrReplaceChild("right_leg", CubeListBuilder.create().texOffs(50, 18).addBox(-16.0f, 6.0f, 0.0f, 3.0f, 3.0f, 3.0f), PartPose.rotation(1.5707964f, 0.0f, (float)Math.PI)); return LayerDefinition.create(mesh, 64, 64); } public static LayerDefinition createFootLayer() { MeshDefinition mesh = new MeshDefinition(); PartDefinition root = mesh.getRoot(); root.addOrReplaceChild("main", CubeListBuilder.create().texOffs(0, 22).addBox(0.0f, 0.0f, 0.0f, 16.0f, 16.0f, 6.0f), PartPose.ZERO); root.addOrReplaceChild("left_leg", CubeListBuilder.create().texOffs(50, 0).addBox(0.0f, 6.0f, -16.0f, 3.0f, 3.0f, 3.0f), PartPose.rotation(1.5707964f, 0.0f, 0.0f)); root.addOrReplaceChild("right_leg", CubeListBuilder.create().texOffs(50, 12).addBox(-16.0f, 6.0f, -16.0f, 3.0f, 3.0f, 3.0f), PartPose.rotation(1.5707964f, 0.0f, 4.712389f)); return LayerDefinition.create(mesh, 64, 64); } @Override public BedRenderState createRenderState() { return new BedRenderState(); } @Override public void extractRenderState(BedBlockEntity blockEntity, BedRenderState state, float partialTicks, Vec3 cameraPosition, @Nullable ModelFeatureRenderer.CrumblingOverlay breakProgress) { BlockEntityRenderer.super.extractRenderState(blockEntity, state, partialTicks, cameraPosition, breakProgress); state.color = blockEntity.getColor(); state.facing = (Direction)blockEntity.getBlockState().getValue(BedBlock.FACING); boolean bl = state.isHead = blockEntity.getBlockState().getValue(BedBlock.PART) == BedPart.HEAD; if (blockEntity.getLevel() != null) { DoubleBlockCombiner.NeighborCombineResult combineResult = DoubleBlockCombiner.combineWithNeigbour(BlockEntityType.BED, BedBlock::getBlockType, BedBlock::getConnectedDirection, ChestBlock.FACING, blockEntity.getBlockState(), blockEntity.getLevel(), blockEntity.getBlockPos(), (levelAccessor, blockPos) -> false); state.lightCoords = ((Int2IntFunction)combineResult.apply(new BrightnessCombiner())).get(state.lightCoords); } } @Override public void submit(BedRenderState state, PoseStack poseStack, SubmitNodeCollector submitNodeCollector, CameraRenderState camera) { Material material = Sheets.getBedMaterial(state.color); this.submitPiece(poseStack, submitNodeCollector, state.isHead ? this.headModel : this.footModel, state.facing, material, state.lightCoords, OverlayTexture.NO_OVERLAY, false, state.breakProgress, 0); } public void submitSpecial(PoseStack poseStack, SubmitNodeCollector submitNodeCollector, int lightCoords, int overlayCoords, Material material, int outlineColor) { this.submitPiece(poseStack, submitNodeCollector, this.headModel, Direction.SOUTH, material, lightCoords, overlayCoords, false, null, outlineColor); this.submitPiece(poseStack, submitNodeCollector, this.footModel, Direction.SOUTH, material, lightCoords, overlayCoords, true, null, outlineColor); } private void submitPiece(PoseStack poseStack, SubmitNodeCollector submitNodeCollector, Model.Simple model, Direction direction, Material material, int lightCoords, int overlayCoords, boolean translateZ, @Nullable ModelFeatureRenderer.CrumblingOverlay breakProgress, int outlineColor) { poseStack.pushPose(); BedRenderer.preparePose(poseStack, translateZ, direction); submitNodeCollector.submitModel(model, Unit.INSTANCE, poseStack, material.renderType(RenderTypes::entitySolid), lightCoords, overlayCoords, -1, this.materials.get(material), outlineColor, breakProgress); poseStack.popPose(); } private static void preparePose(PoseStack poseStack, boolean translateZ, Direction direction) { poseStack.translate(0.0f, 0.5625f, translateZ ? -1.0f : 0.0f); poseStack.mulPose((Quaternionfc)Axis.XP.rotationDegrees(90.0f)); poseStack.translate(0.5f, 0.5f, 0.5f); poseStack.mulPose((Quaternionfc)Axis.ZP.rotationDegrees(180.0f + direction.toYRot())); poseStack.translate(-0.5f, -0.5f, -0.5f); } public void getExtents(Set result) { PoseStack poseStack = new PoseStack(); BedRenderer.preparePose(poseStack, false, Direction.SOUTH); this.headModel.root().getExtentsForGui(poseStack, result); poseStack.setIdentity(); BedRenderer.preparePose(poseStack, true, Direction.SOUTH); this.footModel.root().getExtentsForGui(poseStack, result); } }