@Mod.EventBusSubscriber(modid = PetyasMod.MODID)
public class OreGeneration {
private static ConfiguredFeature oreConfiguredFeature;
private static ConfiguredFeature oreConfiguredFeature() {
if (oreConfiguredFeature == null) {
oreConfiguredFeature = new ReplaceBlockFeature(ReplaceBlockConfig.NO_FEATURE_CONFIG) {
@Override
public boolean generate(ISeedReader reader, ChunkGenerator generator, Random rand, BlockPos pos, ReplaceBlockConfig config) {
if(rand.nextInt(20) == 0)
return super.generate(reader, generator, rand, pos, config);
else
return false;
}
}.withConfiguration(new ReplaceBlockConfig(Blocks.STONE.getDefaultState(), ModBlocks.COPPER_ORE.get().getDefaultState()))
.withPlacement(new Height4To32(NoPlacementConfig.CODEC) {
@Override
public Stream<BlockPos> getPositions(Random random, NoPlacementConfig config, BlockPos pos) {
return IntStream.range(0, 8 + random.nextInt(3)).mapToObj((count) -> {
int j = random.nextInt(16) + pos.getX();
int k = random.nextInt(16) + pos.getZ();
int l = random.nextInt(64) + 4;
return new BlockPos(j, l, k);
});
}
}.configure(IPlacementConfig.NO_PLACEMENT_CONFIG));
}
return oreConfiguredFeature;
}
@SubscribeEvent
public static void registerOreAtBiomes() {
for(Biome biome : ForgeRegistries.BIOMES)
if (!biome.getCategory().equals(Biome.Category.NETHER) && !biome.getCategory().equals(Biome.Category.THEEND))
biome.addFeature(GenerationStage.Decoration.UNDERGROUND_ORES, oreConfiguredFeature());
}
}