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 dbn) {
        this.postMainBoxes = Maps.newIdentityHashMap();
        this.postPiecesBoxes = Maps.newIdentityHashMap();
        this.startPiecesMap = Maps.newIdentityHashMap();
        this.minecraft = dbn;
    }
    
    @Override
    public void render(final PoseStack cyl, final MultiBufferSource dqt, final double double3, final double double4, final double double5) {
        final Camera dbb10 = this.minecraft.gameRenderer.getMainCamera();
        final LevelAccessor bjx11 = this.minecraft.level;
        final DimensionType cbi12 = bjx11.getDimension().getType();
        final BlockPos fk13 = new BlockPos(dbb10.getPosition().x, 0.0, dbb10.getPosition().z);
        final VertexConsumer cyo14 = dqt.getBuffer(RenderType.lines());
        if (this.postMainBoxes.containsKey(cbi12)) {
            for (final BoundingBox clb16 : this.postMainBoxes.get(cbi12).values()) {
                if (fk13.closerThan(clb16.getCenter(), 500.0)) {
                    LevelRenderer.renderLineBox(cyo14, clb16.x0 - double3, clb16.y0 - double4, clb16.z0 - double5, clb16.x1 + 1 - double3, clb16.y1 + 1 - double4, clb16.z1 + 1 - double5, 1.0f, 1.0f, 1.0f, 1.0f);
                }
            }
        }
        if (this.postPiecesBoxes.containsKey(cbi12)) {
            for (final Map.Entry<String, BoundingBox> entry16 : this.postPiecesBoxes.get(cbi12).entrySet()) {
                final String string17 = entry16.getKey();
                final BoundingBox clb17 = entry16.getValue();
                final Boolean boolean19 = this.startPiecesMap.get(cbi12).get(string17);
                if (fk13.closerThan(clb17.getCenter(), 500.0)) {
                    if (boolean19) {
                        LevelRenderer.renderLineBox(cyo14, clb17.x0 - double3, clb17.y0 - double4, clb17.z0 - double5, clb17.x1 + 1 - double3, clb17.y1 + 1 - double4, clb17.z1 + 1 - double5, 0.0f, 1.0f, 0.0f, 1.0f);
                    }
                    else {
                        LevelRenderer.renderLineBox(cyo14, clb17.x0 - double3, clb17.y0 - double4, clb17.z0 - double5, clb17.x1 + 1 - double3, clb17.y1 + 1 - double4, clb17.z1 + 1 - double5, 0.0f, 0.0f, 1.0f, 1.0f);
                    }
                }
            }
        }
    }
    
    public void addBoundingBox(final BoundingBox clb, final List<BoundingBox> list2, final List<Boolean> list3, final DimensionType cbi) {
        if (!this.postMainBoxes.containsKey(cbi)) {
            this.postMainBoxes.put(cbi, Maps.newHashMap());
        }
        if (!this.postPiecesBoxes.containsKey(cbi)) {
            this.postPiecesBoxes.put(cbi, Maps.newHashMap());
            this.startPiecesMap.put(cbi, Maps.newHashMap());
        }
        this.postMainBoxes.get(cbi).put(clb.toString(), clb);
        for (int integer6 = 0; integer6 < list2.size(); ++integer6) {
            final BoundingBox clb2 = list2.get(integer6);
            final Boolean boolean8 = list3.get(integer6);
            this.postPiecesBoxes.get(cbi).put(clb2.toString(), clb2);
            this.startPiecesMap.get(cbi).put(clb2.toString(), boolean8);
        }
    }
    
    @Override
    public void clear() {
        this.postMainBoxes.clear();
        this.postPiecesBoxes.clear();
        this.startPiecesMap.clear();
    }
}
