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

import java.util.Map;
import net.minecraft.core.Registry;
import com.google.common.collect.ImmutableMap;
import com.mojang.datafixers.types.DynamicOps;
import net.minecraft.core.BlockPos;
import java.util.Random;
import com.mojang.datafixers.Dynamic;
import net.minecraft.world.level.block.state.BlockState;

public class SimpleStateProvider extends BlockStateProvider {
    private final BlockState state;
    
    public SimpleStateProvider(final BlockState byj) {
        super(BlockStateProviderType.SIMPLE_STATE_PROVIDER);
        this.state = byj;
    }
    
    public <T> SimpleStateProvider(final Dynamic<T> dynamic) {
        this(BlockState.deserialize((com.mojang.datafixers.Dynamic<Object>)dynamic.get("state").orElseEmptyMap()));
    }
    
    @Override
    public BlockState getState(final Random random, final BlockPos fk) {
        return this.state;
    }
    
    @Override
    public <T> T serialize(final DynamicOps<T> dynamicOps) {
        final ImmutableMap.Builder<T, T> builder3 = ImmutableMap.<T, T>builder();
        builder3.put((T)dynamicOps.createString("type"), (T)dynamicOps.createString(Registry.BLOCKSTATE_PROVIDER_TYPES.getKey(this.type).toString())).put((T)dynamicOps.createString("state"), (T)BlockState.<T>serialize(dynamicOps, this.state).getValue());
        return (T)new Dynamic((DynamicOps)dynamicOps, dynamicOps.createMap((Map)builder3.build())).getValue();
    }
}
