Jump to content

Recommended Posts

Posted (edited)

For anyone who is stuck on ore generation, this is what I've come up with. It works, of course everything is already filled in, the variable effecting the ore spawning is at the top. 

 

Feel free to use code, just make sure you use your blocks instead of mine.

package com.ianite.main.world;

import com.ianite.main.block.IaniteBlocks;

import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biomes;
import net.minecraft.world.gen.GenerationStage;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.OreFeatureConfig;
import net.minecraft.world.gen.placement.CountRangeConfig;
import net.minecraft.world.gen.placement.Placement;
import net.minecraftforge.common.BiomeManager;

public class IaniteOreGeneration {
    private static final CountRangeConfig IANITE = new CountRangeConfig(15, 10, 0, 25);
    private static final int IANITE_VEINSIZE = 5;
    private static final CountRangeConfig TRITANIUM = new CountRangeConfig(25, 10, 0, 128);
    private static final int TRITANIUM_VEINSIZE = 8;

    public static void setupOreGeneration() {
        for (BiomeManager.BiomeType btype : BiomeManager.BiomeType.values()) {
                for (BiomeManager.BiomeEntry biomeEntry : BiomeManager.getBiomes(btype)) {
                    if (IaniteOreConfig.enableIaniteOre) {
                        biomeEntry.biome.addFeature(GenerationStage.Decoration.UNDERGROUND_ORES, Biome.createDecoratedFeature(Feature.ORE, new OreFeatureConfig(OreFeatureConfig.FillerBlockType.NATURAL_STONE, 
                        		IaniteBlocks.ianite_ore.getDefaultState(), IANITE_VEINSIZE), Placement.COUNT_RANGE, IANITE));
                    }
                }
        }
    }

    public static void setupNetherOreGeneration() {
        if (IaniteOreConfig.enableTritaniumOre) {
            Biomes.NETHER.addFeature(GenerationStage.Decoration.UNDERGROUND_ORES, Biome.createDecoratedFeature(Feature.ORE, new OreFeatureConfig(OreFeatureConfig.FillerBlockType.NETHERRACK, 
            		IaniteBlocks.tritanium_ore.getDefaultState(), TRITANIUM_VEINSIZE), Placement.COUNT_RANGE, TRITANIUM));
        }
    }
}

 

Edited by ianm1647
fixed
  • Thanks 1
Posted (edited)

The wonder of open source code is that you can freely copy and modify it, though I will note that most licenses, like my LGPL-3.0 licensed code, do require attribution. The problem of open source code is that you can freely copy and implement other people's mistakes.

 

The above code is incorrect, and will only generate ore in vanilla biomes, as I finally figured out after bug reports from users. Iterate over the Forge biome register, NOT the vanilla BiomeManager.

 

For example, if you have an ore that should generate in all overworld-type biomes, code like this works:

 

public class OreGeneration
{
    // Vein/Chunk Count, MinHeight, MaxHeightBase, MaxHeight
    private static final CountRangeConfig copper_cfg = new CountRangeConfig(15, 40, 0, 128);
    private static final int copper_veinsize = 7;

	public static void setupOreGen()
    {
    	for (Biome biome: ForgeRegistries.BIOMES.getValues())
        {
            // we have no End or Nether ores, so skip those.
            if (  biome.getCategory() == Biome.Category.THEEND || biome.getCategory() == Biome.Category.NETHER)
            {
                continue;
            }
            
            // Overworld-type Ore generation
            if (SimpleOresConfig.enableCopperOre)
            {
                biome.addFeature(
                        GenerationStage.Decoration.UNDERGROUND_ORES,
                        Biome.createDecoratedFeature(Feature.ORE,
                                                     new OreFeatureConfig(
                                                             OreFeatureConfig.FillerBlockType.NATURAL_STONE,
                                                             ModBlocks.copper_ore.getDefaultState(),
                                                             copper_veinsize),
                                                     Placement.COUNT_RANGE,
                                                     copper_cfg));
        	} // end if copper_ore
		} // end for biomes
	} // end setupOreGen()
} // end class

 

This is, of course, a very stripped-down example. The full mod is here, for those that want to study the code: https://github.com/Sinhika/SimpleOres2

Edited by Sinhika
  • 5 weeks later...
Posted
1 hour ago, fanor said:

Guys, have you an idea of remplace Natural_stone by other block ? like custom block ?

Currently, you need to create your own Feature implementation that does the same thing as OreFeature but can be configured to replace your desired block.

 

If/when this pull request is merged, all you'll need to do is create a new FillerBlockType that matches the block you want to replace.

  • Thanks 1

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.