package net.minecraft.client.renderer.debug;

import java.util.List;
import java.util.Iterator;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.client.Camera;
import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.core.BlockPos;
import net.minecraft.client.renderer.MultiBufferSource;
import com.mojang.blaze3d.vertex.PoseStack;
import com.google.common.collect.Maps;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import net.minecraft.world.level.dimension.DimensionType;
import java.util.Map;
import net.minecraft.client.Minecraft;

public class StructureRenderer implements DebugRenderer.SimpleDebugRenderer {
    private final Minecraft minecraft;
    private final Map<DimensionType, Map<String, BoundingBox>> postMainBoxes;
    private final Map<DimensionType, Map<String, BoundingBox>> postPiecesBoxes;
    private final Map<DimensionType, Map<String, Boolean>> startPiecesMap;
    
    public StructureRenderer(final Minecraft dlx) {
        this.postMainBoxes = Maps.newIdentityHashMap();
        this.postPiecesBoxes = Maps.newIdentityHashMap();
        this.startPiecesMap = Maps.newIdentityHashMap();
        this.minecraft = dlx;
    }
    
    @Override
    public void render(final PoseStack dhl, final MultiBufferSource ebz, final double double3, final double double4, final double double5) {
        final Camera dlj10 = this.minecraft.gameRenderer.getMainCamera();
        final LevelAccessor bqc11 = this.minecraft.level;
        final DimensionType cif12 = bqc11.dimensionType();
        final BlockPos fu13 = new BlockPos(dlj10.getPosition().x, 0.0, dlj10.getPosition().z);
        final VertexConsumer dhp14 = ebz.getBuffer(RenderType.lines());
        if (this.postMainBoxes.containsKey(cif12)) {
            for (final BoundingBox ctd16 : this.postMainBoxes.get(cif12).values()) {
                if (fu13.closerThan(ctd16.getCenter(), 500.0)) {
                    LevelRenderer.renderLineBox(dhl, dhp14, ctd16.x0 - double3, ctd16.y0 - double4, ctd16.z0 - double5, ctd16.x1 + 1 - double3, ctd16.y1 + 1 - double4, ctd16.z1 + 1 - double5, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f);
                }
            }
        }
        if (this.postPiecesBoxes.containsKey(cif12)) {
            for (final Map.Entry<String, BoundingBox> entry16 : this.postPiecesBoxes.get(cif12).entrySet()) {
                final String string17 = entry16.getKey();
                final BoundingBox ctd17 = entry16.getValue();
                final Boolean boolean19 = this.startPiecesMap.get(cif12).get(string17);
                if (fu13.closerThan(ctd17.getCenter(), 500.0)) {
                    if (boolean19) {
                        LevelRenderer.renderLineBox(dhl, dhp14, ctd17.x0 - double3, ctd17.y0 - double4, ctd17.z0 - double5, ctd17.x1 + 1 - double3, ctd17.y1 + 1 - double4, ctd17.z1 + 1 - double5, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f);
                    }
                    else {
                        LevelRenderer.renderLineBox(dhl, dhp14, ctd17.x0 - double3, ctd17.y0 - double4, ctd17.z0 - double5, ctd17.x1 + 1 - double3, ctd17.y1 + 1 - double4, ctd17.z1 + 1 - double5, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f);
                    }
                }
            }
        }
    }
    
    public void addBoundingBox(final BoundingBox ctd, final List<BoundingBox> list2, final List<Boolean> list3, final DimensionType cif) {
        if (!this.postMainBoxes.containsKey(cif)) {
            this.postMainBoxes.put(cif, Maps.newHashMap());
        }
        if (!this.postPiecesBoxes.containsKey(cif)) {
            this.postPiecesBoxes.put(cif, Maps.newHashMap());
            this.startPiecesMap.put(cif, Maps.newHashMap());
        }
        this.postMainBoxes.get(cif).put(ctd.toString(), ctd);
        for (int integer6 = 0; integer6 < list2.size(); ++integer6) {
            final BoundingBox ctd2 = list2.get(integer6);
            final Boolean boolean8 = list3.get(integer6);
            this.postPiecesBoxes.get(cif).put(ctd2.toString(), ctd2);
            this.startPiecesMap.get(cif).put(ctd2.toString(), boolean8);
        }
    }
    
    @Override
    public void clear() {
        this.postMainBoxes.clear();
        this.postPiecesBoxes.clear();
        this.startPiecesMap.clear();
    }
}
