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

import net.minecraft.world.level.levelgen.ChunkGeneratorSettings;
import java.util.Random;
import net.minecraft.world.level.levelgen.structure.ShipwreckPieces;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.biome.Biome;
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.chunk.ChunkGenerator;
import com.mojang.datafixers.Dynamic;
import java.util.function.Function;
import net.minecraft.world.level.levelgen.feature.configurations.ShipwreckConfiguration;

public class ShipwreckFeature extends RandomScatteredFeature<ShipwreckConfiguration> {
    public ShipwreckFeature(final Function<Dynamic<?>, ? extends ShipwreckConfiguration> function) {
        super(function);
    }
    
    @Override
    public String getFeatureName() {
        return "Shipwreck";
    }
    
    @Override
    public int getLookupRange() {
        return 3;
    }
    
    @Override
    public StructureStartFactory getStartFactory() {
        return FeatureStart::new;
    }
    
    @Override
    protected int getRandomSalt() {
        return 165745295;
    }
    
    @Override
    protected int getSpacing(final ChunkGenerator<?> caa) {
        return ((ChunkGeneratorSettings)caa.getSettings()).getShipwreckSpacing();
    }
    
    @Override
    protected int getSeparation(final ChunkGenerator<?> caa) {
        return ((ChunkGeneratorSettings)caa.getSettings()).getShipwreckSeparation();
    }
    
    public static class FeatureStart extends StructureStart {
        public FeatureStart(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 ShipwreckConfiguration chf7 = caa.<ShipwreckConfiguration>getStructureConfiguration(bkt, Feature.SHIPWRECK);
            final Rotation btu8 = Rotation.values()[this.random.nextInt(Rotation.values().length)];
            final BlockPos fk9 = new BlockPos(integer3 * 16, 90, integer4 * 16);
            ShipwreckPieces.addPieces(cmo, fk9, btu8, this.pieces, this.random, chf7);
            this.calculateBoundingBox();
        }
    }
}
