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

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

public class RotatedBlockProvider extends BlockStateProvider {
    private final Block block;
    
    public RotatedBlockProvider(final Block bph) {
        super(BlockStateProviderType.SIMPLE_STATE_PROVIDER);
        this.block = bph;
    }
    
    public <T> RotatedBlockProvider(final Dynamic<T> dynamic) {
        this(BlockState.deserialize((com.mojang.datafixers.Dynamic<Object>)dynamic.get("state").orElseEmptyMap()).getBlock());
    }
    
    @Override
    public BlockState getState(final Random random, final BlockPos fk) {
        final Direction.Axis a4 = Direction.Axis.getRandomAxis(random);
        return ((AbstractStateHolder<O, BlockState>)this.block.defaultBlockState()).<Direction.Axis, Direction.Axis>setValue(RotatedPillarBlock.AXIS, a4);
    }
    
    @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.block.defaultBlockState()).getValue());
        return (T)new Dynamic((DynamicOps)dynamicOps, dynamicOps.createMap((Map)builder3.build())).getValue();
    }
}
