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

import java.util.function.Function;
import java.util.Map;
import com.google.common.collect.ImmutableMap;
import java.util.stream.Stream;
import com.mojang.datafixers.Dynamic;
import com.mojang.datafixers.types.DynamicOps;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.level.levelgen.feature.WeightedConfiguredFeature;
import java.util.List;

public class RandomFeatureConfiguration implements FeatureConfiguration {
    public final List<WeightedConfiguredFeature<?>> features;
    public final ConfiguredFeature<?, ?> defaultFeature;
    
    public RandomFeatureConfiguration(final List<WeightedConfiguredFeature<?>> list, final ConfiguredFeature<?, ?> cdc) {
        this.features = list;
        this.defaultFeature = cdc;
    }
    
    @Override
    public <T> Dynamic<T> serialize(final DynamicOps<T> dynamicOps) {
        final T object3 = (T)dynamicOps.createList((Stream)this.features.stream().map(cfu -> cfu.<T>serialize(dynamicOps).getValue()));
        final T object4 = (T)this.defaultFeature.<T>serialize(dynamicOps).getValue();
        return (Dynamic<T>)new Dynamic((DynamicOps)dynamicOps, dynamicOps.createMap((Map)ImmutableMap.<Object, T>of(dynamicOps.createString("features"), object3, dynamicOps.createString("default"), object4)));
    }
    
    public static <T> RandomFeatureConfiguration deserialize(final Dynamic<T> dynamic) {
        final List<WeightedConfiguredFeature<?>> list2 = (List<WeightedConfiguredFeature<?>>)dynamic.get("features").asList((Function)WeightedConfiguredFeature::deserialize);
        final ConfiguredFeature<?, ?> cdc3 = ConfiguredFeature.deserialize((com.mojang.datafixers.Dynamic<Object>)dynamic.get("default").orElseEmptyMap());
        return new RandomFeatureConfiguration(list2, cdc3);
    }
}
