package net.minecraft.client.renderer.debug;

import java.util.Iterator;
import com.mojang.blaze3d.vertex.BufferBuilder;
import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.core.Vec3i;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.Tesselator;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.renderer.MultiBufferSource;
import com.mojang.blaze3d.vertex.PoseStack;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import java.util.List;
import net.minecraft.core.BlockPos;
import java.util.Map;

public class CaveDebugRenderer implements DebugRenderer.SimpleDebugRenderer {
    private final Map<BlockPos, BlockPos> tunnelsList;
    private final Map<BlockPos, Float> thicknessMap;
    private final List<BlockPos> startPoses;
    
    public CaveDebugRenderer() {
        this.tunnelsList = Maps.newHashMap();
        this.thicknessMap = Maps.newHashMap();
        this.startPoses = Lists.newArrayList();
    }
    
    public void addTunnel(final BlockPos fk, final List<BlockPos> list2, final List<Float> list3) {
        for (int integer5 = 0; integer5 < list2.size(); ++integer5) {
            this.tunnelsList.put(list2.get(integer5), fk);
            this.thicknessMap.put(list2.get(integer5), list3.get(integer5));
        }
        this.startPoses.add(fk);
    }
    
    @Override
    public void render(final PoseStack cyl, final MultiBufferSource dqt, final double double3, final double double4, final double double5) {
        RenderSystem.pushMatrix();
        RenderSystem.enableBlend();
        RenderSystem.defaultBlendFunc();
        RenderSystem.disableTexture();
        final BlockPos fk10 = new BlockPos(double3, 0.0, double5);
        final Tesselator cym11 = Tesselator.getInstance();
        final BufferBuilder cyg12 = cym11.getBuilder();
        cyg12.begin(5, DefaultVertexFormat.POSITION_COLOR);
        for (final Map.Entry<BlockPos, BlockPos> entry14 : this.tunnelsList.entrySet()) {
            final BlockPos fk11 = entry14.getKey();
            final BlockPos fk12 = entry14.getValue();
            final float float17 = fk12.getX() * 128 % 256 / 256.0f;
            final float float18 = fk12.getY() * 128 % 256 / 256.0f;
            final float float19 = fk12.getZ() * 128 % 256 / 256.0f;
            final float float20 = this.thicknessMap.get(fk11);
            if (fk10.closerThan(fk11, 160.0)) {
                LevelRenderer.addChainedFilledBoxVertices(cyg12, fk11.getX() + 0.5f - double3 - float20, fk11.getY() + 0.5f - double4 - float20, fk11.getZ() + 0.5f - double5 - float20, fk11.getX() + 0.5f - double3 + float20, fk11.getY() + 0.5f - double4 + float20, fk11.getZ() + 0.5f - double5 + float20, float17, float18, float19, 0.5f);
            }
        }
        for (final BlockPos fk13 : this.startPoses) {
            if (fk10.closerThan(fk13, 160.0)) {
                LevelRenderer.addChainedFilledBoxVertices(cyg12, fk13.getX() - double3, fk13.getY() - double4, fk13.getZ() - double5, fk13.getX() + 1.0f - double3, fk13.getY() + 1.0f - double4, fk13.getZ() + 1.0f - double5, 1.0f, 1.0f, 1.0f, 1.0f);
            }
        }
        cym11.end();
        RenderSystem.enableDepthTest();
        RenderSystem.enableTexture();
        RenderSystem.popMatrix();
    }
}
