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

import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
import net.minecraft.world.level.block.Blocks;
import java.util.Random;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.StructureFeatureManager;
import net.minecraft.world.level.WorldGenLevel;
import com.mojang.serialization.Codec;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;

public class VoidStartPlatformFeature extends Feature<NoneFeatureConfiguration> {
    private static final BlockPos PLATFORM_ORIGIN;
    private static final ChunkPos PLATFORM_ORIGIN_CHUNK;
    
    public VoidStartPlatformFeature(final Codec<NoneFeatureConfiguration> codec) {
        super(codec);
    }
    
    private static int checkerboardDistance(final int integer1, final int integer2, final int integer3, final int integer4) {
        return Math.max(Math.abs(integer1 - integer3), Math.abs(integer2 - integer4));
    }
    
    @Override
    public boolean place(final WorldGenLevel bqu, final StructureFeatureManager bqq, final ChunkGenerator cha, final Random random, final BlockPos fu, final NoneFeatureConfiguration coa) {
        final ChunkPos bph8 = new ChunkPos(fu);
        if (checkerboardDistance(bph8.x, bph8.z, VoidStartPlatformFeature.PLATFORM_ORIGIN_CHUNK.x, VoidStartPlatformFeature.PLATFORM_ORIGIN_CHUNK.z) > 1) {
            return true;
        }
        final BlockPos.MutableBlockPos a9 = new BlockPos.MutableBlockPos();
        for (int integer10 = bph8.getMinBlockZ(); integer10 <= bph8.getMaxBlockZ(); ++integer10) {
            for (int integer11 = bph8.getMinBlockX(); integer11 <= bph8.getMaxBlockX(); ++integer11) {
                if (checkerboardDistance(VoidStartPlatformFeature.PLATFORM_ORIGIN.getX(), VoidStartPlatformFeature.PLATFORM_ORIGIN.getZ(), integer11, integer10) <= 16) {
                    a9.set(integer11, VoidStartPlatformFeature.PLATFORM_ORIGIN.getY(), integer10);
                    if (a9.equals(VoidStartPlatformFeature.PLATFORM_ORIGIN)) {
                        bqu.setBlock(a9, Blocks.COBBLESTONE.defaultBlockState(), 2);
                    }
                    else {
                        bqu.setBlock(a9, Blocks.STONE.defaultBlockState(), 2);
                    }
                }
            }
        }
        return true;
    }
    
    static {
        PLATFORM_ORIGIN = new BlockPos(8, 3, 8);
        PLATFORM_ORIGIN_CHUNK = new ChunkPos(VoidStartPlatformFeature.PLATFORM_ORIGIN);
    }
}
