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 dlx) {
        this.minecraft = dlx;
    }
    
    @Override
    public void render(final PoseStack dhl, final MultiBufferSource ebz, final double double3, final double double4, final double double5) {
        final BlockGetter bpg10 = this.minecraft.player.level;
        RenderSystem.enableBlend();
        RenderSystem.defaultBlendFunc();
        RenderSystem.lineWidth(2.0f);
        RenderSystem.disableTexture();
        RenderSystem.depthMask(false);
        final BlockPos fu11 = new BlockPos(double3, double4, double5);
        for (final BlockPos fu12 : BlockPos.betweenClosed(fu11.offset(-6, -6, -6), fu11.offset(6, 6, 6))) {
            final BlockState cfj14 = bpg10.getBlockState(fu12);
            if (cfj14.is(Blocks.AIR)) {
                continue;
            }
            final VoxelShape dfg15 = cfj14.getShape(bpg10, fu12);
            for (final AABB deg17 : dfg15.toAabbs()) {
                final AABB deg18 = deg17.move(fu12).inflate(0.002).move(-double3, -double4, -double5);
                final double double6 = deg18.minX;
                final double double7 = deg18.minY;
                final double double8 = deg18.minZ;
                final double double9 = deg18.maxX;
                final double double10 = deg18.maxY;
                final double double11 = deg18.maxZ;
                final float float31 = 1.0f;
                final float float32 = 0.0f;
                final float float33 = 0.0f;
                final float float34 = 0.5f;
                if (cfj14.isFaceSturdy(bpg10, fu12, Direction.WEST)) {
                    final Tesselator dhn35 = Tesselator.getInstance();
                    final BufferBuilder dhg36 = dhn35.getBuilder();
                    dhg36.begin(5, DefaultVertexFormat.POSITION_COLOR);
                    dhg36.vertex(double6, double7, double8).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    dhg36.vertex(double6, double7, double11).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    dhg36.vertex(double6, double10, double8).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    dhg36.vertex(double6, double10, double11).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    dhn35.end();
                }
                if (cfj14.isFaceSturdy(bpg10, fu12, Direction.SOUTH)) {
                    final Tesselator dhn35 = Tesselator.getInstance();
                    final BufferBuilder dhg36 = dhn35.getBuilder();
                    dhg36.begin(5, DefaultVertexFormat.POSITION_COLOR);
                    dhg36.vertex(double6, double10, double11).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    dhg36.vertex(double6, double7, double11).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    dhg36.vertex(double9, double10, double11).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    dhg36.vertex(double9, double7, double11).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    dhn35.end();
                }
                if (cfj14.isFaceSturdy(bpg10, fu12, Direction.EAST)) {
                    final Tesselator dhn35 = Tesselator.getInstance();
                    final BufferBuilder dhg36 = dhn35.getBuilder();
                    dhg36.begin(5, DefaultVertexFormat.POSITION_COLOR);
                    dhg36.vertex(double9, double7, double11).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    dhg36.vertex(double9, double7, double8).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    dhg36.vertex(double9, double10, double11).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    dhg36.vertex(double9, double10, double8).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    dhn35.end();
                }
                if (cfj14.isFaceSturdy(bpg10, fu12, Direction.NORTH)) {
                    final Tesselator dhn35 = Tesselator.getInstance();
                    final BufferBuilder dhg36 = dhn35.getBuilder();
                    dhg36.begin(5, DefaultVertexFormat.POSITION_COLOR);
                    dhg36.vertex(double9, double10, double8).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    dhg36.vertex(double9, double7, double8).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    dhg36.vertex(double6, double10, double8).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    dhg36.vertex(double6, double7, double8).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    dhn35.end();
                }
                if (cfj14.isFaceSturdy(bpg10, fu12, Direction.DOWN)) {
                    final Tesselator dhn35 = Tesselator.getInstance();
                    final BufferBuilder dhg36 = dhn35.getBuilder();
                    dhg36.begin(5, DefaultVertexFormat.POSITION_COLOR);
                    dhg36.vertex(double6, double7, double8).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    dhg36.vertex(double9, double7, double8).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    dhg36.vertex(double6, double7, double11).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    dhg36.vertex(double9, double7, double11).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    dhn35.end();
                }
                if (cfj14.isFaceSturdy(bpg10, fu12, Direction.UP)) {
                    final Tesselator dhn35 = Tesselator.getInstance();
                    final BufferBuilder dhg36 = dhn35.getBuilder();
                    dhg36.begin(5, DefaultVertexFormat.POSITION_COLOR);
                    dhg36.vertex(double6, double10, double8).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    dhg36.vertex(double6, double10, double11).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    dhg36.vertex(double9, double10, double8).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    dhg36.vertex(double9, double10, double11).color(1.0f, 0.0f, 0.0f, 0.5f).endVertex();
                    dhn35.end();
                }
            }
        }
        RenderSystem.depthMask(true);
        RenderSystem.enableTexture();
        RenderSystem.disableBlend();
    }
}
