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

import net.minecraft.world.level.block.Blocks;
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 com.google.common.collect.Lists;
import java.util.List;
import net.minecraft.world.level.block.state.BlockState;

public class SimpleBlockConfiguration implements FeatureConfiguration {
    public final BlockState toPlace;
    public final List<BlockState> placeOn;
    public final List<BlockState> placeIn;
    public final List<BlockState> placeUnder;
    
    public SimpleBlockConfiguration(final BlockState byj, final List<BlockState> list2, final List<BlockState> list3, final List<BlockState> list4) {
        this.toPlace = byj;
        this.placeOn = list2;
        this.placeIn = list3;
        this.placeUnder = list4;
    }
    
    public SimpleBlockConfiguration(final BlockState byj, final BlockState[] arr2, final BlockState[] arr3, final BlockState[] arr4) {
        this(byj, Lists.<BlockState>newArrayList(arr2), Lists.<BlockState>newArrayList(arr3), Lists.<BlockState>newArrayList(arr4));
    }
    
    @Override
    public <T> Dynamic<T> serialize(final DynamicOps<T> dynamicOps) {
        final T object3 = (T)BlockState.<T>serialize(dynamicOps, this.toPlace).getValue();
        final T object4 = (T)dynamicOps.createList((Stream)this.placeOn.stream().map(byj -> BlockState.<T>serialize(dynamicOps, byj).getValue()));
        final T object5 = (T)dynamicOps.createList((Stream)this.placeIn.stream().map(byj -> BlockState.<T>serialize(dynamicOps, byj).getValue()));
        final T object6 = (T)dynamicOps.createList((Stream)this.placeUnder.stream().map(byj -> BlockState.<T>serialize(dynamicOps, byj).getValue()));
        return (Dynamic<T>)new Dynamic((DynamicOps)dynamicOps, dynamicOps.createMap((Map)ImmutableMap.<Object, T>of(dynamicOps.createString("to_place"), object3, dynamicOps.createString("place_on"), object4, dynamicOps.createString("place_in"), object5, dynamicOps.createString("place_under"), object6)));
    }
    
    public static <T> SimpleBlockConfiguration deserialize(final Dynamic<T> dynamic) {
        final BlockState byj2 = dynamic.get("to_place").map((Function)BlockState::deserialize).orElse(Blocks.AIR.defaultBlockState());
        final List<BlockState> list3 = (List<BlockState>)dynamic.get("place_on").asList((Function)BlockState::deserialize);
        final List<BlockState> list4 = (List<BlockState>)dynamic.get("place_in").asList((Function)BlockState::deserialize);
        final List<BlockState> list5 = (List<BlockState>)dynamic.get("place_under").asList((Function)BlockState::deserialize);
        return new SimpleBlockConfiguration(byj2, list3, list4, list5);
    }
}
