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

import java.util.stream.Collectors;
import java.util.Arrays;
import net.minecraft.world.level.block.state.predicate.BlockPredicate;
import net.minecraft.world.level.block.Block;
import java.util.function.Predicate;
import net.minecraft.world.level.block.Blocks;
import java.util.function.Function;
import java.util.Map;
import com.google.common.collect.ImmutableMap;
import com.mojang.datafixers.Dynamic;
import com.mojang.datafixers.types.DynamicOps;
import net.minecraft.world.level.block.state.BlockState;

public class OreConfiguration implements FeatureConfiguration {
    public final Predicates target;
    public final int size;
    public final BlockState state;
    
    public OreConfiguration(final Predicates a, final BlockState byj, final int integer) {
        this.size = integer;
        this.state = byj;
        this.target = a;
    }
    
    @Override
    public <T> Dynamic<T> serialize(final DynamicOps<T> dynamicOps) {
        return (Dynamic<T>)new Dynamic((DynamicOps)dynamicOps, dynamicOps.createMap((Map)ImmutableMap.of(dynamicOps.createString("size"), dynamicOps.createInt(this.size), dynamicOps.createString("target"), dynamicOps.createString(this.target.getName()), dynamicOps.createString("state"), BlockState.<T>serialize(dynamicOps, this.state).getValue())));
    }
    
    public static OreConfiguration deserialize(final Dynamic<?> dynamic) {
        final int integer2 = dynamic.get("size").asInt(0);
        final Predicates a3 = Predicates.byName(dynamic.get("target").asString(""));
        final BlockState byj4 = dynamic.get("state").map((Function)BlockState::deserialize).orElse(Blocks.AIR.defaultBlockState());
        return new OreConfiguration(a3, byj4, integer2);
    }
    
    public enum Predicates {
        NATURAL_STONE("natural_stone", byj -> {
            if (byj != null) {
                bph2 = byj.getBlock();
                return bph2 == Blocks.STONE || bph2 == Blocks.GRANITE || bph2 == Blocks.DIORITE || bph2 == Blocks.ANDESITE;
            }
            else {
                return false;
            }
        }), 
        NETHERRACK("netherrack", (Predicate<BlockState>)new BlockPredicate(Blocks.NETHERRACK));
        
        private static final Map<String, Predicates> BY_NAME;
        private final String name;
        private final Predicate<BlockState> predicate;
        
        private Predicates(final String string3, final Predicate<BlockState> predicate) {
            this.name = string3;
            this.predicate = predicate;
        }
        
        public String getName() {
            return this.name;
        }
        
        public static Predicates byName(final String string) {
            return Predicates.BY_NAME.get(string);
        }
        
        public Predicate<BlockState> getPredicate() {
            return this.predicate;
        }
        
        static {
            BY_NAME = Arrays.<Predicates>stream(values()).collect(Collectors.toMap(Predicates::getName, a -> a));
        }
    }
}
