package net.minecraft.client.renderer;

import java.util.Map;
import net.minecraft.Util;
import net.minecraft.client.resources.model.ModelBakery;
import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap;
import com.mojang.blaze3d.vertex.BufferBuilder;
import java.util.SortedMap;

public class RenderBuffers {
    private final ChunkBufferBuilderPack fixedBufferPack;
    private final SortedMap<RenderType, BufferBuilder> fixedBuffers;
    private final MultiBufferSource.BufferSource bufferSource;
    private final MultiBufferSource.BufferSource crumblingBufferSource;
    private final OutlineBufferSource outlineBufferSource;
    
    public RenderBuffers() {
        this.fixedBufferPack = new ChunkBufferBuilderPack();
        this.fixedBuffers = Util.<SortedMap<RenderType, BufferBuilder>>make((SortedMap<RenderType, BufferBuilder>)new Object2ObjectLinkedOpenHashMap(), object2ObjectLinkedOpenHashMap -> {
            object2ObjectLinkedOpenHashMap.put(Sheets.solidBlockSheet(), this.fixedBufferPack.builder(RenderType.solid()));
            object2ObjectLinkedOpenHashMap.put(Sheets.cutoutBlockSheet(), this.fixedBufferPack.builder(RenderType.cutout()));
            object2ObjectLinkedOpenHashMap.put(Sheets.bannerSheet(), this.fixedBufferPack.builder(RenderType.cutoutMipped()));
            object2ObjectLinkedOpenHashMap.put(Sheets.translucentBlockSheet(), this.fixedBufferPack.builder(RenderType.translucent()));
            put(object2ObjectLinkedOpenHashMap, Sheets.shieldSheet());
            put(object2ObjectLinkedOpenHashMap, Sheets.bedSheet());
            put(object2ObjectLinkedOpenHashMap, Sheets.shulkerBoxSheet());
            put(object2ObjectLinkedOpenHashMap, Sheets.signSheet());
            put(object2ObjectLinkedOpenHashMap, Sheets.chestSheet());
            put(object2ObjectLinkedOpenHashMap, RenderType.translucentNoCrumbling());
            put(object2ObjectLinkedOpenHashMap, RenderType.glint());
            put(object2ObjectLinkedOpenHashMap, RenderType.entityGlint());
            put(object2ObjectLinkedOpenHashMap, RenderType.waterMask());
            ModelBakery.DESTROY_TYPES.forEach(drb -> put(object2ObjectLinkedOpenHashMap, drb));
            return;
        });
        this.bufferSource = MultiBufferSource.immediateWithBuffers(this.fixedBuffers, new BufferBuilder(256));
        this.crumblingBufferSource = MultiBufferSource.immediate(new BufferBuilder(256));
        this.outlineBufferSource = new OutlineBufferSource(this.bufferSource);
    }
    
    private static void put(final Object2ObjectLinkedOpenHashMap<RenderType, BufferBuilder> object2ObjectLinkedOpenHashMap, final RenderType drb) {
        object2ObjectLinkedOpenHashMap.put(drb, new BufferBuilder(drb.bufferSize()));
    }
    
    public ChunkBufferBuilderPack fixedBufferPack() {
        return this.fixedBufferPack;
    }
    
    public MultiBufferSource.BufferSource bufferSource() {
        return this.bufferSource;
    }
    
    public MultiBufferSource.BufferSource crumblingBufferSource() {
        return this.crumblingBufferSource;
    }
    
    public OutlineBufferSource outlineBufferSource() {
        return this.outlineBufferSource;
    }
}
