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 java.util.List;
import net.minecraft.world.level.block.state.BlockState;

public class DiskConfiguration implements FeatureConfiguration {
    public final BlockState state;
    public final int radius;
    public final int ySize;
    public final List<BlockState> targets;
    
    public DiskConfiguration(final BlockState byj, final int integer2, final int integer3, final List<BlockState> list) {
        this.state = byj;
        this.radius = integer2;
        this.ySize = integer3;
        this.targets = list;
    }
    
    @Override
    public <T> Dynamic<T> serialize(final DynamicOps<T> dynamicOps) {
        return (Dynamic<T>)new Dynamic((DynamicOps)dynamicOps, dynamicOps.createMap((Map)ImmutableMap.of(dynamicOps.createString("state"), BlockState.<T>serialize(dynamicOps, this.state).getValue(), dynamicOps.createString("radius"), dynamicOps.createInt(this.radius), dynamicOps.createString("y_size"), dynamicOps.createInt(this.ySize), dynamicOps.createString("targets"), dynamicOps.createList((Stream)this.targets.stream().map(byj -> BlockState.<T>serialize(dynamicOps, byj).getValue())))));
    }
    
    public static <T> DiskConfiguration deserialize(final Dynamic<T> dynamic) {
        final BlockState byj2 = dynamic.get("state").map((Function)BlockState::deserialize).orElse(Blocks.AIR.defaultBlockState());
        final int integer3 = dynamic.get("radius").asInt(0);
        final int integer4 = dynamic.get("y_size").asInt(0);
        final List<BlockState> list5 = (List<BlockState>)dynamic.get("targets").asList((Function)BlockState::deserialize);
        return new DiskConfiguration(byj2, integer3, integer4, list5);
    }
}
