package net.minecraft.data.info;

import com.google.gson.GsonBuilder;
import java.io.IOException;
import java.nio.file.Path;
import com.google.common.collect.UnmodifiableIterator;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.resources.ResourceLocation;
import java.util.Iterator;
import net.minecraft.world.level.block.state.BlockState;
import com.google.gson.JsonElement;
import net.minecraft.Util;
import com.google.gson.JsonArray;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.block.Block;
import net.minecraft.core.Registry;
import com.google.gson.JsonObject;
import net.minecraft.data.HashCache;
import net.minecraft.data.DataGenerator;
import com.google.gson.Gson;
import net.minecraft.data.DataProvider;

public class BlockListReport implements DataProvider {
    private static final Gson GSON;
    private final DataGenerator generator;
    
    public BlockListReport(final DataGenerator hk) {
        this.generator = hk;
    }
    
    @Override
    public void run(final HashCache hm) throws IOException {
        final JsonObject jsonObject3 = new JsonObject();
        for (final Block bvr5 : Registry.BLOCK) {
            final ResourceLocation uh6 = Registry.BLOCK.getKey(bvr5);
            final JsonObject jsonObject4 = new JsonObject();
            final StateDefinition<Block, BlockState> cfk8 = bvr5.getStateDefinition();
            if (!cfk8.getProperties().isEmpty()) {
                final JsonObject jsonObject5 = new JsonObject();
                for (final Property<?> cgl11 : cfk8.getProperties()) {
                    final JsonArray jsonArray12 = new JsonArray();
                    for (final Comparable<?> comparable14 : cgl11.getPossibleValues()) {
                        jsonArray12.add(Util.getPropertyName(cgl11, comparable14));
                    }
                    jsonObject5.add(cgl11.getName(), jsonArray12);
                }
                jsonObject4.add("properties", jsonObject5);
            }
            final JsonArray jsonArray13 = new JsonArray();
            for (final BlockState cfj11 : cfk8.getPossibleStates()) {
                final JsonObject jsonObject6 = new JsonObject();
                final JsonObject jsonObject7 = new JsonObject();
                for (final Property<?> cgl12 : cfk8.getProperties()) {
                    jsonObject7.addProperty(cgl12.getName(), Util.getPropertyName(cgl12, cfj11.getValue(cgl12)));
                }
                if (jsonObject7.size() > 0) {
                    jsonObject6.add("properties", jsonObject7);
                }
                jsonObject6.addProperty("id", Block.getId(cfj11));
                if (cfj11 == bvr5.defaultBlockState()) {
                    jsonObject6.addProperty("default", true);
                }
                jsonArray13.add(jsonObject6);
            }
            jsonObject4.add("states", jsonArray13);
            jsonObject3.add(uh6.toString(), jsonObject4);
        }
        final Path path4 = this.generator.getOutputFolder().resolve("reports/blocks.json");
        DataProvider.save(BlockListReport.GSON, hm, jsonObject3, path4);
    }
    
    @Override
    public String getName() {
        return "Block List";
    }
    
    static {
        GSON = new GsonBuilder().setPrettyPrinting().create();
    }
}
