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 java.util.List;

public class RandomRandomFeatureConfiguration implements FeatureConfiguration {
    public final List<ConfiguredFeature<?, ?>> features;
    public final int count;
    
    public RandomRandomFeatureConfiguration(final List<ConfiguredFeature<?, ?>> list, final int integer) {
        this.features = list;
        this.count = integer;
    }
    
    @Override
    public <T> Dynamic<T> serialize(final DynamicOps<T> dynamicOps) {
        return (Dynamic<T>)new Dynamic((DynamicOps)dynamicOps, dynamicOps.createMap((Map)ImmutableMap.of(dynamicOps.createString("features"), dynamicOps.createList((Stream)this.features.stream().map(cdc -> cdc.<T>serialize(dynamicOps).getValue())), dynamicOps.createString("count"), dynamicOps.createInt(this.count))));
    }
    
    public static <T> RandomRandomFeatureConfiguration deserialize(final Dynamic<T> dynamic) {
        final List<ConfiguredFeature<?, ?>> list2 = (List<ConfiguredFeature<?, ?>>)dynamic.get("features").asList((Function)ConfiguredFeature::deserialize);
        final int integer3 = dynamic.get("count").asInt(0);
        return new RandomRandomFeatureConfiguration(list2, integer3);
    }
}
