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

import net.minecraft.world.level.LevelWriter;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.LevelSimulatedRW;
import net.minecraft.world.level.block.VineBlock;
import net.minecraft.world.level.LevelSimulatedReader;
import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import java.util.Set;
import net.minecraft.core.BlockPos;
import java.util.List;
import java.util.Random;
import net.minecraft.world.level.LevelAccessor;
import com.mojang.serialization.Codec;

public class LeaveVineDecorator extends TreeDecorator {
    public static final Codec<LeaveVineDecorator> CODEC;
    public static final LeaveVineDecorator INSTANCE;
    
    @Override
    protected TreeDecoratorType<?> type() {
        return TreeDecoratorType.LEAVE_VINE;
    }
    
    @Override
    public void place(final LevelAccessor bqc, final Random random, final List<BlockPos> list3, final List<BlockPos> list4, final Set<BlockPos> set, final BoundingBox ctd) {
        BlockPos fu2;
        BlockPos fu3;
        BlockPos fu4;
        BlockPos fu5;
        list4.forEach(fu -> {
            if (random.nextInt(4) == 0) {
                fu2 = fu.west();
                if (Feature.isAir(bqc, fu2)) {
                    this.addHangingVine(bqc, fu2, VineBlock.EAST, set, ctd);
                }
            }
            if (random.nextInt(4) == 0) {
                fu3 = fu.east();
                if (Feature.isAir(bqc, fu3)) {
                    this.addHangingVine(bqc, fu3, VineBlock.WEST, set, ctd);
                }
            }
            if (random.nextInt(4) == 0) {
                fu4 = fu.north();
                if (Feature.isAir(bqc, fu4)) {
                    this.addHangingVine(bqc, fu4, VineBlock.SOUTH, set, ctd);
                }
            }
            if (random.nextInt(4) == 0) {
                fu5 = fu.south();
                if (Feature.isAir(bqc, fu5)) {
                    this.addHangingVine(bqc, fu5, VineBlock.NORTH, set, ctd);
                }
            }
        });
    }
    
    private void addHangingVine(final LevelSimulatedRW bqf, BlockPos fu, final BooleanProperty cga, final Set<BlockPos> set, final BoundingBox ctd) {
        this.placeVine(bqf, fu, cga, set, ctd);
        int integer7;
        for (integer7 = 4, fu = fu.below(); Feature.isAir(bqf, fu) && integer7 > 0; fu = fu.below(), --integer7) {
            this.placeVine(bqf, fu, cga, set, ctd);
        }
    }
    
    static {
        CODEC = Codec.unit(() -> LeaveVineDecorator.INSTANCE);
        INSTANCE = new LeaveVineDecorator();
    }
}
