Jump to content

Recommended Posts

Posted

I have a mod in which I want to add ores that generate in the world. I have done everything I believe is needed to be done (made ores, made an IWorldGenerator that generates the ores, and registered the generator) but when I test it none of the ores spawn.

 

Main mod file:

@Mod(modid = "ores", name = "Ores", version = "0.0.1")
public class OresMod 
{
static final String TEXTURE = "ores:";

static Block tinOre = new BlockOre(),
	  		 copperOre = new BlockOre(),
	  		 leadOre = new BlockOre(),
	  		 uraniumOre = new BlockOre(),
	  		 nickelOre = new BlockOre(),
	  		 silverOre = new BlockOre(),
	  		 osmiumOre = new BlockOre();

static Item tinIngot = new Item(),
	 	    copperIngot = new Item(),
	 	    leadIngot = new Item(),
	 	    uraniumIngot = new Item(),
	 	    nickelIngot = new Item(),
	 	    silverIngot = new Item(),
	 	    osmiumIngot = new Item();

public static void initializeBlocks()
{
	tinOre.setHardness(3.0F).setResistance(5.0F).setStepSound(Block.soundTypeStone).setBlockTextureName(TEXTURE + "oreTin").setBlockName("oreTin").setCreativeTab(CreativeTabs.tabBlock).setHarvestLevel("ItemPickaxe", 2);
	copperOre.setHardness(3.0F).setResistance(5.0F).setStepSound(Block.soundTypeStone).setBlockTextureName(TEXTURE + "oreCopper").setBlockName("oreCopper").setCreativeTab(CreativeTabs.tabBlock).setHarvestLevel("ItemPickaxe", 1);
	leadOre.setHardness(3.0F).setResistance(5.0F).setStepSound(Block.soundTypeStone).setBlockTextureName(TEXTURE + "oreLead").setBlockName("oreLead").setCreativeTab(CreativeTabs.tabBlock).setHarvestLevel("ItemPickaxe", 2);
	uraniumOre.setHardness(3.0F).setResistance(5.0F).setStepSound(Block.soundTypeStone).setBlockTextureName(TEXTURE + "oreUranium").setBlockName("oreUranium").setCreativeTab(CreativeTabs.tabBlock).setHarvestLevel("ItemPickaxe", 2);
	nickelOre.setHardness(3.0F).setResistance(5.0F).setStepSound(Block.soundTypeStone).setBlockTextureName(TEXTURE + "oreNickel").setBlockName("oreNickel").setCreativeTab(CreativeTabs.tabBlock).setHarvestLevel("ItemPickaxe", 2);
	silverOre.setHardness(3.0F).setResistance(5.0F).setStepSound(Block.soundTypeStone).setBlockTextureName(TEXTURE + "oreSilver").setBlockName("oreSilver").setCreativeTab(CreativeTabs.tabBlock).setHarvestLevel("ItemPickaxe", 2);
	osmiumOre.setHardness(3.0F).setResistance(5.0F).setStepSound(Block.soundTypeStone).setBlockTextureName(TEXTURE + "oreOsmium").setBlockName("oreOsmium").setCreativeTab(CreativeTabs.tabBlock).setHarvestLevel("ItemPickaxe", 0);
}

public static void registerBlocks()
{
	GameRegistry.registerBlock(tinOre, "oreTin");
	GameRegistry.registerBlock(copperOre, "oreCopper");
	GameRegistry.registerBlock(leadOre, "oreLead");
	GameRegistry.registerBlock(uraniumOre, "oreUranium");
	GameRegistry.registerBlock(nickelOre, "oreNickel");
	GameRegistry.registerBlock(silverOre, "oreSilver");
	GameRegistry.registerBlock(osmiumOre, "oreOsmium");
}

public static void initializeItems()
{
	tinIngot.setUnlocalizedName("ingotTin").setCreativeTab(CreativeTabs.tabMaterials).setTextureName(TEXTURE + "ingotTin");
	copperIngot.setUnlocalizedName("ingotCopper").setCreativeTab(CreativeTabs.tabMaterials).setTextureName(TEXTURE + "ingotCopper");
	leadIngot.setUnlocalizedName("ingotLead").setCreativeTab(CreativeTabs.tabMaterials).setTextureName(TEXTURE + "ingotLead");
	uraniumIngot.setUnlocalizedName("ingotUranium").setCreativeTab(CreativeTabs.tabMaterials).setTextureName(TEXTURE + "ingotUranium");
	nickelIngot.setUnlocalizedName("ingotNickel").setCreativeTab(CreativeTabs.tabMaterials).setTextureName(TEXTURE + "ingotNickel");
	silverIngot.setUnlocalizedName("ingotSilver").setCreativeTab(CreativeTabs.tabMaterials).setTextureName(TEXTURE + "ingotSilver");
	osmiumIngot.setUnlocalizedName("ingotOsmium").setCreativeTab(CreativeTabs.tabMaterials).setTextureName(TEXTURE + "ingotOsmium");
}

public static void registerItems()
{
	GameRegistry.registerItem(tinIngot, "ingotTin");
	GameRegistry.registerItem(copperIngot, "ingotCopper");
	GameRegistry.registerItem(leadIngot, "ingotLead");
	GameRegistry.registerItem(uraniumIngot, "ingotUranium");
	GameRegistry.registerItem(nickelIngot, "ingotNickel");
	GameRegistry.registerItem(silverIngot, "ingotSilver");
	GameRegistry.registerItem(osmiumIngot, "ingotOsmium");
}

public static void registerSmelts()
{
	GameRegistry.addSmelting(tinOre, new ItemStack(tinIngot), 3.0F);
	GameRegistry.addSmelting(copperOre, new ItemStack(copperIngot), 3.0F);
	GameRegistry.addSmelting(leadOre, new ItemStack(leadIngot), 3.0F);
	GameRegistry.addSmelting(uraniumOre, new ItemStack(uraniumIngot), 3.0F);
	GameRegistry.addSmelting(nickelOre, new ItemStack(nickelIngot), 3.0F);
	GameRegistry.addSmelting(silverOre, new ItemStack(silverIngot), 3.0F);
	GameRegistry.addSmelting(osmiumOre, new ItemStack(osmiumIngot), 3.0F);
}

public static void registerOreDict()
{
	OreDictionary.registerOre("oreTin", tinOre);
	OreDictionary.registerOre("oreCopper", copperOre);
	OreDictionary.registerOre("oreLead", leadOre);
	OreDictionary.registerOre("oreUranium", uraniumOre);
	OreDictionary.registerOre("oreNickel", nickelOre);
	OreDictionary.registerOre("oreSilver", silverOre);
	OreDictionary.registerOre("oreOsmium", osmiumOre);
}
    
    @EventHandler
    public void preInit(FMLPreInitializationEvent event) 
    {
    	initializeBlocks();
    	registerBlocks();
    	initializeItems();
    	registerItems();
    	registerSmelts();
    	registerOreDict();
    	GameRegistry.registerWorldGenerator(new OreGenerator(), 1);
    }
    
    @EventHandler
    public void init(FMLInitializationEvent event) 
    {}
    
    @EventHandler
    public void postInit(FMLPostInitializationEvent event) 
    {}
}

 

IWorldGenerator:

public class OreGenerator implements IWorldGenerator
{
@Override
    public void generate(Random r, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
    {
        switch (world.provider.dimensionId)
        {
        case -1:
            generateNether(world, r, chunkX * 16, chunkZ * 16);
            break;
        case 0:
            generateSurface(world, r, chunkX * 16, chunkZ * 16);
            break;
        case 1:
            generateEnd(world, r, chunkX * 16, chunkZ * 16);
            break;
        }
    }

    private void generateEnd(World world, Random random, int x, int z)
    {}

    private void generateSurface(World world, Random random, int x, int z)
    {
        this.addOreSpawn(OresMod.tinOre, world, random, x, z, 15, 15, Info.tinVS, Info.tinOC, Info.tinSL[1], Info.tinSL[0]);
        this.addOreSpawn(OresMod.copperOre, world, random, x, z, 15, 15, Info.copperVS, Info.copperOC, Info.copperSL[1], Info.copperSL[0]);
        this.addOreSpawn(OresMod.leadOre, world, random, x, z, 15, 15, Info.leadVS, Info.leadOC, Info.leadSL[1], Info.leadSL[0]);
        this.addOreSpawn(OresMod.uraniumOre, world, random, x, z, 15, 15, Info.uraniumVS, Info.uraniumOC, Info.uraniumSL[1], Info.uraniumSL[0]);
        this.addOreSpawn(OresMod.nickelOre, world, random, x, z, 15, 15, Info.nickelVS, Info.nickelOC, Info.nickelSL[1], Info.nickelSL[0]);
        this.addOreSpawn(OresMod.silverOre, world, random, x, z, 15, 15, Info.silverVS, Info.silverOC, Info.silverSL[1], Info.silverSL[0]);
        this.addOreSpawn(OresMod.osmiumOre, world, random, x, z, 15, 15, Info.osmiumVS, Info.osmiumOC, Info.osmiumSL[1], Info.osmiumSL[0]);
    }

    private void generateNether(World world, Random random, int x, int z)
    {}

    /**
     * Adds an Ore Spawn to Minecraft. Simply register all Ores to spawn with this method in your Generation method in your IWorldGeneration extending Class
     *
     * @param The Block to spawn
     * @param The World to spawn in
     * @param A Random object for retrieving random positions within the world to spawn the Block
     * @param An int for passing the X-Coordinate for the Generation method
     * @param An int for passing the Z-Coordinate for the Generation method
     * @param An int for setting the maximum X-Coordinate values for spawning on the X-Axis on a Per-Chunk basis
     * @param An int for setting the maximum Z-Coordinate values for spawning on the Z-Axis on a Per-Chunk basis
     * @param An int for setting the maximum size of a vein
     * @param An int for the Number of chances available for the Block to spawn per-chunk
     * @param An int for the minimum Y-Coordinate height at which this block may spawn
     * @param An int for the maximum Y-Coordinate height at which this block may spawn
     **/
    public void addOreSpawn(Block block, World world, Random random, int blockXPos, int blockZPos, int maxX, int maxZ, int maxVeinSize, int chancesToSpawn, int minY, int maxY)
    {
        assert maxY > minY : "The maximum Y must be greater than the Minimum Y";
        assert maxX > 0 && maxX <= 16 : "addOreSpawn: The Maximum X must be greater than 0 and less than 16";
        assert minY > 0 : "addOreSpawn: The Minimum Y must be greater than 0";
        assert maxY < 256 && maxY > 0 : "addOreSpawn: The Maximum Y must be less than 256 but greater than 0";
        assert maxZ > 0 && maxZ <= 16 : "addOreSpawn: The Maximum Z must be greater than 0 and less than 16";

        int diffBtwnMinMaxY = maxY - minY;
        for (int x = 0; x < chancesToSpawn; x++)
        {
            int posX = blockXPos + random.nextInt(maxX);
            int posY = minY + random.nextInt(diffBtwnMinMaxY);
            int posZ = blockZPos + random.nextInt(maxZ);
            (new WorldGenMinable(block, maxVeinSize)).generate(world, random, posX, posY, posZ);
        }
    }
}

 

tinVS, tinOC, tinSL, etc. are vein-size, occurrence, and spawn-levels, all gathered from a config.

Posted

Example:

 

//basic class stuff above
public static Block tutblock;

@EventHandler
public void preInit(FMLPreInitializationEvent event) {
tutblock = new TutBlock().setUnlocalizedName("tutBlock");
//other stuff
}

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.