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.WorldgenRandom;
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
import net.minecraft.world.level.biome.Biome;
import java.util.Random;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.biome.BiomeManager;
import com.mojang.datafixers.Dynamic;
import java.util.function.Function;
import net.minecraft.world.level.levelgen.feature.configurations.BuriedTreasureConfiguration;

public class BuriedTreasureFeature extends StructureFeature<BuriedTreasureConfiguration> {
    public BuriedTreasureFeature(final Function<Dynamic<?>, ? extends BuriedTreasureConfiguration> function) {
        super(function);
    }
    
    @Override
    public boolean isFeatureChunk(final BiomeManager bkv, final ChunkGenerator<?> caa, final Random random, final int integer4, final int integer5, final Biome bkt) {
        if (caa.isBiomeValidStartForStructure(bkt, this)) {
            ((WorldgenRandom)random).setLargeFeatureWithSalt(caa.getSeed(), integer4, integer5, 10387320);
            final BuriedTreasureConfiguration cgf8 = caa.<BuriedTreasureConfiguration>getStructureConfiguration(bkt, (StructureFeature<BuriedTreasureConfiguration>)this);
            return random.nextFloat() < cgf8.probability;
        }
        return false;
    }
    
    @Override
    public StructureStartFactory getStartFactory() {
        return BuriedTreasureStart::new;
    }
    
    @Override
    public String getFeatureName() {
        return "Buried_Treasure";
    }
    
    @Override
    public int getLookupRange() {
        return 1;
    }
    
    public static class BuriedTreasureStart extends StructureStart {
        public BuriedTreasureStart(final StructureFeature<?> cfl, final int integer2, final int integer3, final BoundingBox clb, final int integer5, final long long6) {
            super(cfl, integer2, integer3, clb, integer5, long6);
        }
        
        @Override
        public void generatePieces(final ChunkGenerator<?> caa, final StructureManager cmo, final int integer3, final int integer4, final Biome bkt) {
            final int integer5 = integer3 * 16;
            final int integer6 = integer4 * 16;
            final BlockPos fk9 = new BlockPos(integer5 + 9, 90, integer6 + 9);
            this.pieces.add(new BuriedTreasurePieces.BuriedTreasurePiece(fk9));
            this.calculateBoundingBox();
        }
        
        @Override
        public BlockPos getLocatePos() {
            return new BlockPos((this.getChunkX() << 4) + 9, 0, (this.getChunkZ() << 4) + 9);
        }
    }
}
