package net.minecraft.client.renderer.debug;

import java.util.Iterator;
import com.mojang.blaze3d.vertex.BufferBuilder;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.world.level.levelgen.Heightmap;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.Tesselator;
import net.minecraft.core.BlockPos;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.renderer.MultiBufferSource;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Minecraft;

public class HeightMapRenderer implements DebugRenderer.SimpleDebugRenderer {
    private final Minecraft minecraft;
    
    public HeightMapRenderer(final Minecraft dbn) {
        this.minecraft = dbn;
    }
    
    @Override
    public void render(final PoseStack cyl, final MultiBufferSource dqt, final double double3, final double double4, final double double5) {
        final LevelAccessor bjx10 = this.minecraft.level;
        RenderSystem.pushMatrix();
        RenderSystem.enableBlend();
        RenderSystem.defaultBlendFunc();
        RenderSystem.disableTexture();
        final BlockPos fk11 = new BlockPos(double3, 0.0, double5);
        final Tesselator cym12 = Tesselator.getInstance();
        final BufferBuilder cyg13 = cym12.getBuilder();
        cyg13.begin(5, DefaultVertexFormat.POSITION_COLOR);
        for (final BlockPos fk12 : BlockPos.betweenClosed(fk11.offset(-40, 0, -40), fk11.offset(40, 0, 40))) {
            final int integer16 = bjx10.getHeight(Heightmap.Types.WORLD_SURFACE_WG, fk12.getX(), fk12.getZ());
            if (bjx10.getBlockState(fk12.offset(0, integer16, 0).below()).isAir()) {
                LevelRenderer.addChainedFilledBoxVertices(cyg13, fk12.getX() + 0.25f - double3, integer16 - double4, fk12.getZ() + 0.25f - double5, fk12.getX() + 0.75f - double3, integer16 + 0.09375 - double4, fk12.getZ() + 0.75f - double5, 0.0f, 0.0f, 1.0f, 0.5f);
            }
            else {
                LevelRenderer.addChainedFilledBoxVertices(cyg13, fk12.getX() + 0.25f - double3, integer16 - double4, fk12.getZ() + 0.25f - double5, fk12.getX() + 0.75f - double3, integer16 + 0.09375 - double4, fk12.getZ() + 0.75f - double5, 0.0f, 1.0f, 0.0f, 0.5f);
            }
        }
        cym12.end();
        RenderSystem.enableTexture();
        RenderSystem.popMatrix();
    }
}
