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

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

public class ColumnPlacer extends BlockPlacer {
    private final int minSize;
    private final int extraSize;
    
    public ColumnPlacer(final int integer1, final int integer2) {
        super(BlockPlacerType.COLUMN_PLACER);
        this.minSize = integer1;
        this.extraSize = integer2;
    }
    
    public <T> ColumnPlacer(final Dynamic<T> dynamic) {
        this(dynamic.get("min_size").asInt(1), dynamic.get("extra_size").asInt(2));
    }
    
    @Override
    public void place(final LevelAccessor bjx, final BlockPos fk, final BlockState byj, final Random random) {
        final BlockPos.MutableBlockPos a6 = new BlockPos.MutableBlockPos(fk);
        for (int integer7 = this.minSize + random.nextInt(random.nextInt(this.extraSize + 1) + 1), integer8 = 0; integer8 < integer7; ++integer8) {
            bjx.setBlock(a6, byj, 2);
            a6.move(Direction.UP);
        }
    }
    
    @Override
    public <T> T serialize(final DynamicOps<T> dynamicOps) {
        return (T)new Dynamic((DynamicOps)dynamicOps, dynamicOps.createMap((Map)ImmutableMap.of(dynamicOps.createString("type"), dynamicOps.createString(Registry.BLOCK_PLACER_TYPES.getKey(this.type).toString()), dynamicOps.createString("min_size"), dynamicOps.createInt(this.minSize), dynamicOps.createString("extra_size"), dynamicOps.createInt(this.extraSize)))).getValue();
    }
}
