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

import net.minecraft.world.level.levelgen.structure.BuriedTreasurePieces;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import net.minecraft.world.level.levelgen.structure.StructureStart;
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.levelgen.WorldgenRandom;
import net.minecraft.world.level.biome.BiomeSource;
import net.minecraft.world.level.chunk.ChunkGenerator;
import com.mojang.serialization.Codec;
import net.minecraft.world.level.levelgen.feature.configurations.BuriedTreasureConfiguration;

public class BuriedTreasureFeature extends StructureFeature<BuriedTreasureConfiguration> {
    public BuriedTreasureFeature(final Codec<BuriedTreasureConfiguration> codec) {
        super(codec);
    }
    
    @Override
    protected boolean isFeatureChunk(final ChunkGenerator cha, final BiomeSource brh, final long long3, final WorldgenRandom ciy, final int integer5, final int integer6, final Biome bre, final ChunkPos bph, final BuriedTreasureConfiguration cnh) {
        ciy.setLargeFeatureWithSalt(long3, integer5, integer6, 10387320);
        return ciy.nextFloat() < cnh.probability;
    }
    
    @Override
    public StructureStartFactory<BuriedTreasureConfiguration> getStartFactory() {
        return BuriedTreasureStart::new;
    }
    
    public static class BuriedTreasureStart extends StructureStart<BuriedTreasureConfiguration> {
        public BuriedTreasureStart(final StructureFeature<BuriedTreasureConfiguration> cml, final int integer2, final int integer3, final BoundingBox ctd, final int integer5, final long long6) {
            super(cml, integer2, integer3, ctd, integer5, long6);
        }
        
        @Override
        public void generatePieces(final ChunkGenerator cha, final StructureManager cva, final int integer3, final int integer4, final Biome bre, final BuriedTreasureConfiguration cnh) {
            final int integer5 = integer3 * 16;
            final int integer6 = integer4 * 16;
            final BlockPos fu10 = new BlockPos(integer5 + 9, 90, integer6 + 9);
            this.pieces.add(new BuriedTreasurePieces.BuriedTreasurePiece(fu10));
            this.calculateBoundingBox();
        }
        
        @Override
        public BlockPos getLocatePos() {
            return new BlockPos((this.getChunkX() << 4) + 9, 0, (this.getChunkZ() << 4) + 9);
        }
    }
}
