package net.minecraft.client.renderer.blockentity;

import net.minecraft.world.level.block.entity.BlockEntity;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.level.block.state.BlockState;
import com.mojang.math.Vector3f;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.resources.model.Material;
import net.minecraft.client.renderer.Sheets;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.block.ShulkerBoxBlock;
import net.minecraft.core.Direction;
import net.minecraft.client.renderer.MultiBufferSource;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.model.ShulkerModel;
import net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity;

public class ShulkerBoxRenderer extends BlockEntityRenderer<ShulkerBoxBlockEntity> {
    private final ShulkerModel<?> model;
    
    public ShulkerBoxRenderer(final ShulkerModel<?> dmm, final BlockEntityRenderDispatcher dsq) {
        super(dsq);
        this.model = dmm;
    }
    
    @Override
    public void render(final ShulkerBoxBlockEntity bxg, final float float2, final PoseStack cyl, final MultiBufferSource dqt, final int integer5, final int integer6) {
        Direction fp8 = Direction.UP;
        if (bxg.hasLevel()) {
            final BlockState byj9 = bxg.getLevel().getBlockState(bxg.getBlockPos());
            if (byj9.getBlock() instanceof ShulkerBoxBlock) {
                fp8 = byj9.<Direction>getValue(ShulkerBoxBlock.FACING);
            }
        }
        final DyeColor bdj10 = bxg.getColor();
        Material eby9;
        if (bdj10 == null) {
            eby9 = Sheets.DEFAULT_SHULKER_TEXTURE_LOCATION;
        }
        else {
            eby9 = Sheets.SHULKER_TEXTURE_LOCATION.get(bdj10.getId());
        }
        cyl.pushPose();
        cyl.translate(0.5, 0.5, 0.5);
        final float float3 = 0.9995f;
        cyl.scale(0.9995f, 0.9995f, 0.9995f);
        cyl.mulPose(fp8.getRotation());
        cyl.scale(1.0f, -1.0f, -1.0f);
        cyl.translate(0.0, -1.0, 0.0);
        final VertexConsumer cyo12 = eby9.buffer(dqt, RenderType::entityCutoutNoCull);
        this.model.getBase().render(cyl, cyo12, integer5, integer6);
        cyl.translate(0.0, -bxg.getProgress(float2) * 0.5f, 0.0);
        cyl.mulPose(Vector3f.YP.rotationDegrees(270.0f * bxg.getProgress(float2)));
        this.model.getLid().render(cyl, cyo12, integer5, integer6);
        cyl.popPose();
    }
}
