package net.minecraft.client.particle;

import net.minecraft.client.renderer.MultiBufferSource;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.util.Mth;
import net.minecraft.client.Camera;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.level.Level;
import net.minecraft.client.renderer.entity.EntityRenderDispatcher;
import net.minecraft.world.entity.Entity;
import net.minecraft.client.renderer.RenderBuffers;

public class ItemPickupParticle extends Particle {
    private final RenderBuffers renderBuffers;
    private final Entity itemEntity;
    private final Entity target;
    private int life;
    private final EntityRenderDispatcher entityRenderDispatcher;
    
    public ItemPickupParticle(final EntityRenderDispatcher dvf, final RenderBuffers dqz, final Level bjw, final Entity akq4, final Entity akq5) {
        this(dvf, dqz, bjw, akq4, akq5, akq4.getDeltaMovement());
    }
    
    private ItemPickupParticle(final EntityRenderDispatcher dvf, final RenderBuffers dqz, final Level bjw, final Entity akq4, final Entity akq5, final Vec3 cvl) {
        super(bjw, akq4.getX(), akq4.getY(), akq4.getZ(), cvl.x, cvl.y, cvl.z);
        this.renderBuffers = dqz;
        this.itemEntity = akq4;
        this.target = akq5;
        this.entityRenderDispatcher = dvf;
    }
    
    @Override
    public ParticleRenderType getRenderType() {
        return ParticleRenderType.CUSTOM;
    }
    
    @Override
    public void render(final VertexConsumer cyo, final Camera dbb, final float float3) {
        float float4 = (this.life + float3) / 3.0f;
        float4 *= float4;
        final double double6 = Mth.lerp(float3, this.target.xOld, this.target.getX());
        final double double7 = Mth.lerp(float3, this.target.yOld, this.target.getY()) + 0.5;
        final double double8 = Mth.lerp(float3, this.target.zOld, this.target.getZ());
        final double double9 = Mth.lerp(float4, this.itemEntity.getX(), double6);
        final double double10 = Mth.lerp(float4, this.itemEntity.getY(), double7);
        final double double11 = Mth.lerp(float4, this.itemEntity.getZ(), double8);
        final MultiBufferSource.BufferSource a18 = this.renderBuffers.bufferSource();
        final Vec3 cvl19 = dbb.getPosition();
        this.entityRenderDispatcher.<Entity>render(this.itemEntity, double9 - cvl19.x(), double10 - cvl19.y(), double11 - cvl19.z(), this.itemEntity.yRot, float3, new PoseStack(), a18, this.entityRenderDispatcher.<Entity>getPackedLightCoords(this.itemEntity, float3));
        a18.endBatch();
    }
    
    @Override
    public void tick() {
        ++this.life;
        if (this.life == 3) {
            this.remove();
        }
    }
}
