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<?> dxj, final BlockEntityRenderDispatcher edw) {
        super(edw);
        this.model = dxj;
    }
    
    @Override
    public void render(final ShulkerBoxBlockEntity ceg, final float float2, final PoseStack dhl, final MultiBufferSource ebz, final int integer5, final int integer6) {
        Direction fz8 = Direction.UP;
        if (ceg.hasLevel()) {
            final BlockState cfj9 = ceg.getLevel().getBlockState(ceg.getBlockPos());
            if (cfj9.getBlock() instanceof ShulkerBoxBlock) {
                fz8 = cfj9.<Direction>getValue(ShulkerBoxBlock.FACING);
            }
        }
        final DyeColor bje10 = ceg.getColor();
        Material enk9;
        if (bje10 == null) {
            enk9 = Sheets.DEFAULT_SHULKER_TEXTURE_LOCATION;
        }
        else {
            enk9 = Sheets.SHULKER_TEXTURE_LOCATION.get(bje10.getId());
        }
        dhl.pushPose();
        dhl.translate(0.5, 0.5, 0.5);
        final float float3 = 0.9995f;
        dhl.scale(0.9995f, 0.9995f, 0.9995f);
        dhl.mulPose(fz8.getRotation());
        dhl.scale(1.0f, -1.0f, -1.0f);
        dhl.translate(0.0, -1.0, 0.0);
        final VertexConsumer dhp12 = enk9.buffer(ebz, RenderType::entityCutoutNoCull);
        this.model.getBase().render(dhl, dhp12, integer5, integer6);
        dhl.translate(0.0, -ceg.getProgress(float2) * 0.5f, 0.0);
        dhl.mulPose(Vector3f.YP.rotationDegrees(270.0f * ceg.getProgress(float2)));
        this.model.getLid().render(dhl, dhp12, integer5, integer6);
        dhl.popPose();
    }
}
