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

import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.core.Registry;
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.levelgen.placement.ConfiguredDecorator;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;

public class DecoratedFeatureConfiguration implements FeatureConfiguration {
    public final ConfiguredFeature<?, ?> feature;
    public final ConfiguredDecorator<?> decorator;
    
    public DecoratedFeatureConfiguration(final ConfiguredFeature<?, ?> cdc, final ConfiguredDecorator<?> cjj) {
        this.feature = cdc;
        this.decorator = cjj;
    }
    
    @Override
    public <T> Dynamic<T> serialize(final DynamicOps<T> dynamicOps) {
        return (Dynamic<T>)new Dynamic((DynamicOps)dynamicOps, dynamicOps.createMap((Map)ImmutableMap.of(dynamicOps.createString("feature"), this.feature.<T>serialize(dynamicOps).getValue(), dynamicOps.createString("decorator"), this.decorator.<T>serialize(dynamicOps).getValue())));
    }
    
    @Override
    public String toString() {
        return String.format("< %s [%s | %s] >", this.getClass().getSimpleName(), Registry.FEATURE.getKey(this.feature.feature), Registry.DECORATOR.getKey(this.decorator.decorator));
    }
    
    public static <T> DecoratedFeatureConfiguration deserialize(final Dynamic<T> dynamic) {
        final ConfiguredFeature<?, ?> cdc2 = ConfiguredFeature.deserialize((com.mojang.datafixers.Dynamic<Object>)dynamic.get("feature").orElseEmptyMap());
        final ConfiguredDecorator<?> cjj3 = ConfiguredDecorator.deserialize((com.mojang.datafixers.Dynamic<Object>)dynamic.get("decorator").orElseEmptyMap());
        return new DecoratedFeatureConfiguration(cdc2, cjj3);
    }
}
