package net.minecraft.client.renderer.entity;

import net.minecraft.world.entity.Entity;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.client.renderer.texture.OverlayTexture;
import com.mojang.math.Vector3f;
import net.minecraft.client.renderer.block.model.ItemTransforms;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.Item;
import net.minecraft.client.renderer.MultiBufferSource;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.world.item.ItemStack;
import java.util.Random;
import net.minecraft.world.entity.item.ItemEntity;

public class ItemEntityRenderer extends EntityRenderer<ItemEntity> {
    private final ItemRenderer itemRenderer;
    private final Random random;
    
    public ItemEntityRenderer(final EntityRenderDispatcher dvf, final ItemRenderer dvz) {
        super(dvf);
        this.random = new Random();
        this.itemRenderer = dvz;
        this.shadowRadius = 0.15f;
        this.shadowStrength = 0.75f;
    }
    
    private int getRenderAmount(final ItemStack ben) {
        int integer3 = 1;
        if (ben.getCount() > 48) {
            integer3 = 5;
        }
        else if (ben.getCount() > 32) {
            integer3 = 4;
        }
        else if (ben.getCount() > 16) {
            integer3 = 3;
        }
        else if (ben.getCount() > 1) {
            integer3 = 2;
        }
        return integer3;
    }
    
    @Override
    public void render(final ItemEntity awb, final float float2, final float float3, final PoseStack cyl, final MultiBufferSource dqt, final int integer) {
        cyl.pushPose();
        final ItemStack ben8 = awb.getItem();
        final int integer2 = ben8.isEmpty() ? 187 : (Item.getId(ben8.getItem()) + ben8.getDamageValue());
        this.random.setSeed(integer2);
        final BakedModel ebv10 = this.itemRenderer.getModel(ben8, awb.level, null);
        final boolean boolean11 = ebv10.isGui3d();
        final int integer3 = this.getRenderAmount(ben8);
        final float float4 = 0.25f;
        final float float5 = Mth.sin((awb.getAge() + float3) / 10.0f + awb.bobOffs) * 0.1f + 0.1f;
        final float float6 = ebv10.getTransforms().getTransform(ItemTransforms.TransformType.GROUND).scale.y();
        cyl.translate(0.0, float5 + 0.25f * float6, 0.0);
        final float float7 = (awb.getAge() + float3) / 20.0f + awb.bobOffs;
        cyl.mulPose(Vector3f.YP.rotation(float7));
        final float float8 = ebv10.getTransforms().ground.scale.x();
        final float float9 = ebv10.getTransforms().ground.scale.y();
        final float float10 = ebv10.getTransforms().ground.scale.z();
        if (!boolean11) {
            final float float11 = -0.0f * (integer3 - 1) * 0.5f * float8;
            final float float12 = -0.0f * (integer3 - 1) * 0.5f * float9;
            final float float13 = -0.09375f * (integer3 - 1) * 0.5f * float10;
            cyl.translate(float11, float12, float13);
        }
        for (int integer4 = 0; integer4 < integer3; ++integer4) {
            cyl.pushPose();
            if (integer4 > 0) {
                if (boolean11) {
                    final float float12 = (this.random.nextFloat() * 2.0f - 1.0f) * 0.15f;
                    final float float13 = (this.random.nextFloat() * 2.0f - 1.0f) * 0.15f;
                    final float float14 = (this.random.nextFloat() * 2.0f - 1.0f) * 0.15f;
                    cyl.translate(float12, float13, float14);
                }
                else {
                    final float float12 = (this.random.nextFloat() * 2.0f - 1.0f) * 0.15f * 0.5f;
                    final float float13 = (this.random.nextFloat() * 2.0f - 1.0f) * 0.15f * 0.5f;
                    cyl.translate(float12, float13, 0.0);
                }
            }
            this.itemRenderer.render(ben8, ItemTransforms.TransformType.GROUND, false, cyl, dqt, integer, OverlayTexture.NO_OVERLAY, ebv10);
            cyl.popPose();
            if (!boolean11) {
                cyl.translate(0.0f * float8, 0.0f * float9, 0.09375f * float10);
            }
        }
        cyl.popPose();
        super.render(awb, float2, float3, cyl, dqt, integer);
    }
    
    @Override
    public ResourceLocation getTextureLocation(final ItemEntity awb) {
        return TextureAtlas.LOCATION_BLOCKS;
    }
}
