package net.minecraft.world.level.levelgen.feature.configurations;

import net.minecraft.resources.ResourceLocation;
import java.util.function.Supplier;
import net.minecraft.core.Registry;
import net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProviderType;
import java.util.Map;
import com.google.common.collect.ImmutableMap;
import com.mojang.datafixers.Dynamic;
import com.mojang.datafixers.types.DynamicOps;
import net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProvider;

public class BlockPileConfiguration implements FeatureConfiguration {
    public final BlockStateProvider stateProvider;
    
    public BlockPileConfiguration(final BlockStateProvider chw) {
        this.stateProvider = chw;
    }
    
    @Override
    public <T> Dynamic<T> serialize(final DynamicOps<T> dynamicOps) {
        final ImmutableMap.Builder<T, T> builder3 = ImmutableMap.<T, T>builder();
        builder3.put((T)dynamicOps.createString("state_provider"), this.stateProvider.<T>serialize(dynamicOps));
        return (Dynamic<T>)new Dynamic((DynamicOps)dynamicOps, dynamicOps.createMap((Map)builder3.build()));
    }
    
    public static <T> BlockPileConfiguration deserialize(final Dynamic<T> dynamic) {
        final BlockStateProviderType<?> chx2 = Registry.BLOCKSTATE_PROVIDER_TYPES.get(new ResourceLocation(dynamic.get("state_provider").get("type").asString().<Throwable>orElseThrow(RuntimeException::new)));
        return new BlockPileConfiguration((BlockStateProvider)chx2.deserialize(dynamic.get("state_provider").orElseEmptyMap()));
    }
}
