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

import net.minecraft.core.Registry;
import com.mojang.datafixers.Dynamic;
import java.util.function.Function;

public class FoliagePlacerType<P extends FoliagePlacer> {
    public static final FoliagePlacerType<BlobFoliagePlacer> BLOB_FOLIAGE_PLACER;
    public static final FoliagePlacerType<SpruceFoliagePlacer> SPRUCE_FOLIAGE_PLACER;
    public static final FoliagePlacerType<PineFoliagePlacer> PINE_FOLIAGE_PLACER;
    public static final FoliagePlacerType<AcaciaFoliagePlacer> ACACIA_FOLIAGE_PLACER;
    private final Function<Dynamic<?>, P> deserializer;
    
    private static <P extends FoliagePlacer> FoliagePlacerType<P> register(final String string, final Function<Dynamic<?>, P> function) {
        return Registry.<FoliagePlacerType<P>>register(Registry.FOLIAGE_PLACER_TYPES, string, new FoliagePlacerType<P>(function));
    }
    
    private FoliagePlacerType(final Function<Dynamic<?>, P> function) {
        this.deserializer = function;
    }
    
    public P deserialize(final Dynamic<?> dynamic) {
        return this.deserializer.apply(dynamic);
    }
    
    static {
        BLOB_FOLIAGE_PLACER = FoliagePlacerType.<BlobFoliagePlacer>register("blob_foliage_placer", BlobFoliagePlacer::new);
        SPRUCE_FOLIAGE_PLACER = FoliagePlacerType.<SpruceFoliagePlacer>register("spruce_foliage_placer", SpruceFoliagePlacer::new);
        PINE_FOLIAGE_PLACER = FoliagePlacerType.<PineFoliagePlacer>register("pine_foliage_placer", PineFoliagePlacer::new);
        ACACIA_FOLIAGE_PLACER = FoliagePlacerType.<AcaciaFoliagePlacer>register("acacia_foliage_placer", AcaciaFoliagePlacer::new);
    }
}
