/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  net.minecraft.class_2338
 *  net.minecraft.class_2586
 *  net.minecraft.class_2791
 */
package meteordevelopment.meteorclient.utils.world;

import java.util.Iterator;
import java.util.Map;
import meteordevelopment.meteorclient.mixin.ChunkAccessor;
import meteordevelopment.meteorclient.utils.world.ChunkIterator;
import net.minecraft.class_2338;
import net.minecraft.class_2586;
import net.minecraft.class_2791;

public class BlockEntityIterator
implements Iterator<class_2586> {
    private final Iterator<class_2791> chunks = new ChunkIterator(false);
    private Iterator<class_2586> blockEntities;

    public BlockEntityIterator() {
        this.nextChunk();
    }

    private void nextChunk() {
        while (this.chunks.hasNext()) {
            Map<class_2338, class_2586> blockEntityMap = ((ChunkAccessor)this.chunks.next()).getBlockEntities();
            if (blockEntityMap.isEmpty()) continue;
            this.blockEntities = blockEntityMap.values().iterator();
            break;
        }
    }

    @Override
    public boolean hasNext() {
        if (this.blockEntities == null) {
            return false;
        }
        if (this.blockEntities.hasNext()) {
            return true;
        }
        this.nextChunk();
        return this.blockEntities.hasNext();
    }

    @Override
    public class_2586 next() {
        return this.blockEntities.next();
    }
}

