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 com.mojang.datafixers.Dynamic;
import com.mojang.datafixers.types.DynamicOps;
import net.minecraft.world.level.block.state.BlockState;

public class ReplaceBlockConfiguration implements FeatureConfiguration {
    public final BlockState target;
    public final BlockState state;
    
    public ReplaceBlockConfiguration(final BlockState byj1, final BlockState byj2) {
        this.target = byj1;
        this.state = byj2;
    }
    
    @Override
    public <T> Dynamic<T> serialize(final DynamicOps<T> dynamicOps) {
        return (Dynamic<T>)new Dynamic((DynamicOps)dynamicOps, dynamicOps.createMap((Map)ImmutableMap.of(dynamicOps.createString("target"), BlockState.<T>serialize(dynamicOps, this.target).getValue(), dynamicOps.createString("state"), BlockState.<T>serialize(dynamicOps, this.state).getValue())));
    }
    
    public static <T> ReplaceBlockConfiguration deserialize(final Dynamic<T> dynamic) {
        final BlockState byj2 = dynamic.get("target").map((Function)BlockState::deserialize).orElse(Blocks.AIR.defaultBlockState());
        final BlockState byj3 = dynamic.get("state").map((Function)BlockState::deserialize).orElse(Blocks.AIR.defaultBlockState());
        return new ReplaceBlockConfiguration(byj2, byj3);
    }
}
