package net.minecraft.client.renderer.debug;

import com.mojang.blaze3d.vertex.BufferBuilder;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.level.block.state.BlockState;
import java.util.Iterator;
import net.minecraft.world.level.BlockGetter;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.Tesselator;
import net.minecraft.core.Direction;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.level.block.Blocks;
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 SolidFaceRenderer implements DebugRenderer.SimpleDebugRenderer {
    private final Minecraft minecraft;
    
    public SolidFaceRenderer(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 BlockGetter bjg10 = this.minecraft.player.level;
        RenderSystem.enableBlend();
        RenderSystem.defaultBlendFunc();
        RenderSystem.lineWidth(2.0f);
        RenderSystem.disableTexture();
        RenderSystem.depthMask(false);
        final BlockPos fk11 = new BlockPos(double3, double4, double5);
        for (final BlockPos fk12 : BlockPos.betweenClosed(fk11.offset(-6, -6, -6), fk11.offset(6, 6, 6))) {
            final BlockState byj14 = bjg10.getBlockState(fk12);
            if (byj14.getBlock() == Blocks.AIR) {
                continue;
            }
            final VoxelShape cwf15 = byj14.getShape(bjg10, fk12);
            for (final AABB cvf17 : cwf15.toAabbs()) {
                final AABB cvf18 = cvf17.move(fk12).inflate(0.002).move(-double3, -double4, -double5);
                final double double6 = cvf18.minX;
                final double double7 = cvf18.minY;
                final double double8 = cvf18.minZ;
                final double double9 = cvf18.maxX;
                final double double10 = cvf18.maxY;
                final double double11 = cvf18.maxZ;
                final float float31 = 1.0f;
                final float float32 = 0.0f;
                final float float33 = 0.0f;
                final float float34 = 0.5f;
                if (byj14.isFaceSturdy(bjg10, fk12, Direction.WEST)) {
                    final Tesselator cym35 = Tesselator.getInstance();
                    final BufferBuilder cyg36 = cym35.getBuilder();
                    cyg36.begin(5, DefaultVertexFormat.POSITION_COLOR);
                    cyg36.vertex(double6, double7, double8).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    cyg36.vertex(double6, double7, double11).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    cyg36.vertex(double6, double10, double8).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    cyg36.vertex(double6, double10, double11).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    cym35.end();
                }
                if (byj14.isFaceSturdy(bjg10, fk12, Direction.SOUTH)) {
                    final Tesselator cym35 = Tesselator.getInstance();
                    final BufferBuilder cyg36 = cym35.getBuilder();
                    cyg36.begin(5, DefaultVertexFormat.POSITION_COLOR);
                    cyg36.vertex(double6, double10, double11).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    cyg36.vertex(double6, double7, double11).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    cyg36.vertex(double9, double10, double11).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    cyg36.vertex(double9, double7, double11).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    cym35.end();
                }
                if (byj14.isFaceSturdy(bjg10, fk12, Direction.EAST)) {
                    final Tesselator cym35 = Tesselator.getInstance();
                    final BufferBuilder cyg36 = cym35.getBuilder();
                    cyg36.begin(5, DefaultVertexFormat.POSITION_COLOR);
                    cyg36.vertex(double9, double7, double11).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    cyg36.vertex(double9, double7, double8).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    cyg36.vertex(double9, double10, double11).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    cyg36.vertex(double9, double10, double8).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    cym35.end();
                }
                if (byj14.isFaceSturdy(bjg10, fk12, Direction.NORTH)) {
                    final Tesselator cym35 = Tesselator.getInstance();
                    final BufferBuilder cyg36 = cym35.getBuilder();
                    cyg36.begin(5, DefaultVertexFormat.POSITION_COLOR);
                    cyg36.vertex(double9, double10, double8).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    cyg36.vertex(double9, double7, double8).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    cyg36.vertex(double6, double10, double8).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    cyg36.vertex(double6, double7, double8).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    cym35.end();
                }
                if (byj14.isFaceSturdy(bjg10, fk12, Direction.DOWN)) {
                    final Tesselator cym35 = Tesselator.getInstance();
                    final BufferBuilder cyg36 = cym35.getBuilder();
                    cyg36.begin(5, DefaultVertexFormat.POSITION_COLOR);
                    cyg36.vertex(double6, double7, double8).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    cyg36.vertex(double9, double7, double8).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    cyg36.vertex(double6, double7, double11).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    cyg36.vertex(double9, double7, double11).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    cym35.end();
                }
                if (byj14.isFaceSturdy(bjg10, fk12, Direction.UP)) {
                    final Tesselator cym35 = Tesselator.getInstance();
                    final BufferBuilder cyg36 = cym35.getBuilder();
                    cyg36.begin(5, DefaultVertexFormat.POSITION_COLOR);
                    cyg36.vertex(double6, double10, double8).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    cyg36.vertex(double6, double10, double11).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    cyg36.vertex(double9, double10, double8).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    cyg36.vertex(double9, double10, double11).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    cym35.end();
                }
            }
        }
        RenderSystem.depthMask(true);
        RenderSystem.enableTexture();
        RenderSystem.disableBlend();
    }
}
