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

import java.util.Set;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.levelgen.feature.configurations.SmallTreeConfiguration;
import java.util.Random;
import net.minecraft.world.level.LevelSimulatedRW;
import com.mojang.datafixers.Dynamic;

public class SpruceFoliagePlacer extends FoliagePlacer {
    public SpruceFoliagePlacer(final int integer1, final int integer2) {
        super(integer1, integer2, FoliagePlacerType.SPRUCE_FOLIAGE_PLACER);
    }
    
    public <T> SpruceFoliagePlacer(final Dynamic<T> dynamic) {
        this(dynamic.get("radius").asInt(0), dynamic.get("radius_random").asInt(0));
    }
    
    @Override
    public void createFoliage(final LevelSimulatedRW bkb, final Random random, final SmallTreeConfiguration chi, final int integer4, final int integer5, final int integer6, final BlockPos fk, final Set<BlockPos> set) {
        int integer7 = random.nextInt(2);
        int integer8 = 1;
        int integer9 = 0;
        for (int integer10 = integer4; integer10 >= integer5; --integer10) {
            this.placeLeavesRow(bkb, random, chi, integer4, fk, integer10, integer7, set);
            if (integer7 >= integer8) {
                integer7 = integer9;
                integer9 = 1;
                integer8 = Math.min(integer8 + 1, integer6);
            }
            else {
                ++integer7;
            }
        }
    }
    
    @Override
    public int foliageRadius(final Random random, final int integer2, final int integer3, final SmallTreeConfiguration chi) {
        return this.radius + random.nextInt(this.radiusRandom + 1);
    }
    
    @Override
    protected boolean shouldSkipLocation(final Random random, final int integer2, final int integer3, final int integer4, final int integer5, final int integer6) {
        return Math.abs(integer3) == integer6 && Math.abs(integer5) == integer6 && integer6 > 0;
    }
    
    @Override
    public int getTreeRadiusForHeight(final int integer1, final int integer2, final int integer3, final int integer4) {
        return (integer4 <= 1) ? 0 : 2;
    }
}
