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

import java.util.Collection;
import com.google.common.collect.ImmutableSet;
import net.minecraft.world.level.material.Fluids;
import java.util.Map;
import com.google.common.collect.ImmutableMap;
import java.util.stream.Stream;
import net.minecraft.resources.ResourceLocation;
import java.util.function.Function;
import net.minecraft.core.Registry;
import com.mojang.datafixers.Dynamic;
import com.mojang.datafixers.types.DynamicOps;
import net.minecraft.world.level.block.Block;
import java.util.Set;
import net.minecraft.world.level.material.FluidState;

public class SpringConfiguration implements FeatureConfiguration {
    public final FluidState state;
    public final boolean requiresBlockBelow;
    public final int rockCount;
    public final int holeCount;
    public final Set<Block> validBlocks;
    
    public SpringConfiguration(final FluidState coj, final boolean boolean2, final int integer3, final int integer4, final Set<Block> set) {
        this.state = coj;
        this.requiresBlockBelow = boolean2;
        this.rockCount = integer3;
        this.holeCount = integer4;
        this.validBlocks = set;
    }
    
    @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"), FluidState.<T>serialize(dynamicOps, this.state).getValue(), dynamicOps.createString("requires_block_below"), dynamicOps.createBoolean(this.requiresBlockBelow), dynamicOps.createString("rock_count"), dynamicOps.createInt(this.rockCount), dynamicOps.createString("hole_count"), dynamicOps.createInt(this.holeCount), dynamicOps.createString("valid_blocks"), dynamicOps.createList((Stream)this.validBlocks.stream().map(Registry.BLOCK::getKey).map(ResourceLocation::toString).map(dynamicOps::createString)))));
    }
    
    public static <T> SpringConfiguration deserialize(final Dynamic<T> dynamic) {
        return new SpringConfiguration(dynamic.get("state").map((Function)FluidState::deserialize).orElse(Fluids.EMPTY.defaultFluidState()), dynamic.get("requires_block_below").asBoolean(true), dynamic.get("rock_count").asInt(4), dynamic.get("hole_count").asInt(1), ImmutableSet.copyOf(dynamic.get("valid_blocks").asList(dynamic -> Registry.BLOCK.get(new ResourceLocation(dynamic.asString("minecraft:air"))))));
    }
}
