package net.minecraft.client.renderer.debug;

import java.util.Iterator;
import com.mojang.blaze3d.vertex.VertexConsumer;
import java.util.Set;
import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.world.phys.AABB;
import net.minecraft.client.renderer.RenderType;
import com.google.common.collect.Sets;
import net.minecraft.client.renderer.MultiBufferSource;
import com.mojang.blaze3d.vertex.PoseStack;
import java.util.Comparator;
import com.google.common.collect.Maps;
import com.google.common.collect.Ordering;
import net.minecraft.core.BlockPos;
import java.util.Map;
import net.minecraft.client.Minecraft;

public class NeighborsUpdateRenderer implements DebugRenderer.SimpleDebugRenderer {
    private final Minecraft minecraft;
    private final Map<Long, Map<BlockPos, Integer>> lastUpdate;
    
    NeighborsUpdateRenderer(final Minecraft dlx) {
        this.lastUpdate = Maps.newTreeMap(Ordering.<Comparable>natural().reverse());
        this.minecraft = dlx;
    }
    
    public void addUpdate(final long long1, final BlockPos fu) {
        final Map<BlockPos, Integer> map5 = this.lastUpdate.computeIfAbsent(Long.valueOf(long1), long1 -> Maps.newHashMap());
        final int integer6 = map5.getOrDefault(fu, 0);
        map5.put(fu, integer6 + 1);
    }
    
    @Override
    public void render(final PoseStack dhl, final MultiBufferSource ebz, final double double3, final double double4, final double double5) {
        final long long10 = this.minecraft.level.getGameTime();
        final int integer12 = 200;
        final double double6 = 0.0025;
        final Set<BlockPos> set15 = Sets.newHashSet();
        final Map<BlockPos, Integer> map16 = Maps.newHashMap();
        final VertexConsumer dhp17 = ebz.getBuffer(RenderType.lines());
        final Iterator<Map.Entry<Long, Map<BlockPos, Integer>>> iterator18 = this.lastUpdate.entrySet().iterator();
        while (iterator18.hasNext()) {
            final Map.Entry<Long, Map<BlockPos, Integer>> entry19 = iterator18.next();
            final Long long11 = entry19.getKey();
            final Map<BlockPos, Integer> map17 = entry19.getValue();
            final long long12 = long10 - long11;
            if (long12 > 200L) {
                iterator18.remove();
            }
            else {
                for (final Map.Entry<BlockPos, Integer> entry20 : map17.entrySet()) {
                    final BlockPos fu26 = entry20.getKey();
                    final Integer integer13 = entry20.getValue();
                    if (set15.add(fu26)) {
                        final AABB deg28 = new AABB(BlockPos.ZERO).inflate(0.002).deflate(0.0025 * long12).move(fu26.getX(), fu26.getY(), fu26.getZ()).move(-double3, -double4, -double5);
                        LevelRenderer.renderLineBox(dhl, dhp17, deg28.minX, deg28.minY, deg28.minZ, deg28.maxX, deg28.maxY, deg28.maxZ, 1.0f, 1.0f, 1.0f, 1.0f);
                        map16.put(fu26, integer13);
                    }
                }
            }
        }
        for (final Map.Entry<BlockPos, Integer> entry21 : map16.entrySet()) {
            final BlockPos fu27 = entry21.getKey();
            final Integer integer14 = entry21.getValue();
            DebugRenderer.renderFloatingText(String.valueOf(integer14), fu27.getX(), fu27.getY(), fu27.getZ(), -1);
        }
    }
}
