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

import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
import java.util.Iterator;
import net.minecraft.core.Direction;
import net.minecraft.core.BlockPos;
import java.util.Random;
import net.minecraft.world.level.levelgen.ChunkGeneratorSettings;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.Blocks;
import com.mojang.datafixers.Dynamic;
import java.util.function.Function;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.predicate.BlockStatePredicate;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;

public class DesertWellFeature extends Feature<NoneFeatureConfiguration> {
    private static final BlockStatePredicate IS_SAND;
    private final BlockState sandSlab;
    private final BlockState sandstone;
    private final BlockState water;
    
    public DesertWellFeature(final Function<Dynamic<?>, ? extends NoneFeatureConfiguration> function) {
        super(function);
        this.sandSlab = Blocks.SANDSTONE_SLAB.defaultBlockState();
        this.sandstone = Blocks.SANDSTONE.defaultBlockState();
        this.water = Blocks.WATER.defaultBlockState();
    }
    
    @Override
    public boolean place(final LevelAccessor bjx, final ChunkGenerator<? extends ChunkGeneratorSettings> caa, final Random random, BlockPos fk, final NoneFeatureConfiguration cgv) {
        for (fk = fk.above(); bjx.isEmptyBlock(fk) && fk.getY() > 2; fk = fk.below()) {}
        if (!DesertWellFeature.IS_SAND.test(bjx.getBlockState(fk))) {
            return false;
        }
        for (int integer7 = -2; integer7 <= 2; ++integer7) {
            for (int integer8 = -2; integer8 <= 2; ++integer8) {
                if (bjx.isEmptyBlock(fk.offset(integer7, -1, integer8)) && bjx.isEmptyBlock(fk.offset(integer7, -2, integer8))) {
                    return false;
                }
            }
        }
        for (int integer7 = -1; integer7 <= 0; ++integer7) {
            for (int integer8 = -2; integer8 <= 2; ++integer8) {
                for (int integer9 = -2; integer9 <= 2; ++integer9) {
                    bjx.setBlock(fk.offset(integer8, integer7, integer9), this.sandstone, 2);
                }
            }
        }
        bjx.setBlock(fk, this.water, 2);
        for (final Direction fp8 : Direction.Plane.HORIZONTAL) {
            bjx.setBlock(fk.relative(fp8), this.water, 2);
        }
        for (int integer7 = -2; integer7 <= 2; ++integer7) {
            for (int integer8 = -2; integer8 <= 2; ++integer8) {
                if (integer7 == -2 || integer7 == 2 || integer8 == -2 || integer8 == 2) {
                    bjx.setBlock(fk.offset(integer7, 1, integer8), this.sandstone, 2);
                }
            }
        }
        bjx.setBlock(fk.offset(2, 1, 0), this.sandSlab, 2);
        bjx.setBlock(fk.offset(-2, 1, 0), this.sandSlab, 2);
        bjx.setBlock(fk.offset(0, 1, 2), this.sandSlab, 2);
        bjx.setBlock(fk.offset(0, 1, -2), this.sandSlab, 2);
        for (int integer7 = -1; integer7 <= 1; ++integer7) {
            for (int integer8 = -1; integer8 <= 1; ++integer8) {
                if (integer7 == 0 && integer8 == 0) {
                    bjx.setBlock(fk.offset(integer7, 4, integer8), this.sandstone, 2);
                }
                else {
                    bjx.setBlock(fk.offset(integer7, 4, integer8), this.sandSlab, 2);
                }
            }
        }
        for (int integer7 = 1; integer7 <= 3; ++integer7) {
            bjx.setBlock(fk.offset(-1, integer7, -1), this.sandstone, 2);
            bjx.setBlock(fk.offset(-1, integer7, 1), this.sandstone, 2);
            bjx.setBlock(fk.offset(1, integer7, -1), this.sandstone, 2);
            bjx.setBlock(fk.offset(1, integer7, 1), this.sandstone, 2);
        }
        return true;
    }
    
    static {
        IS_SAND = BlockStatePredicate.forBlock(Blocks.SAND);
    }
}
