top of page

Ore Generation

We've added our lead ore, but we cant get it in survial! It doesnt have a crafting recipe and doesnt generate in the world. Well not for long. In this tutorial we will be making our lead ore generate as an ore in the overworld. Awesome, so lets start! Lets start with a new class in a new package with the ".gen" and the class will be called WorldGenInit. We make a new static void method called init(). In that method, we call a GameRegistry method called: GameRegistry.registerWorldGenerator(IWorldGenerator worldgenerator, int weight)

 

Okay lets talk about those two parameters. The first one is the class that implements IWorldGenerator, which is responsible for world generation. The next parameter is the weight of the generation. Im not exactly sure what that means so please email me if you do know so I can update this. Okay cool, now we must create the world generator, ours for lead is called "LeadOreGen". Right click that error and click make class. Awesome, now we should have a class looking like this:

Looks pretty blank huh? Not for long. In this method, generate, we will put the code for world generation. Here in this generation method, here you can add code to make it generate blocks and stuff, pretty cool. I'll do another tutorial on custom structure gen, but for now it is ores. Lets get started. Add a switch statement taking the variable "world.provider.dimensionid" and add the following cases of -1 (nether), 0 (overworld) and 1 (end). We make 3 new methods, well we dont have to, but I like them there just in case. generateNether, generateOverWorld and GenerateEnd, all with the parameters: random, chunkX * 16, chunckZ * 16 and world. It should now look like this:

Make all of those into methods. As you can see, they take a random, which is for just random number gen, chunkX coords, ChunkZ coords and the world. Easy right? To make the ores spawn, we should probably write a method for that. Now this method is complex, so instead of explaining the parameters, I've got some comment to explain each parameter.

Its all pretty self explanitory as you can see. Awesome, now that we've done that, we just need to call this method in the generateOverWorld method and replace the block parameter with our ore, the minVeinSize to mimium ore per vein, maxVeinSize to maximium ore per vein, chance to spawn how likey your ore is to spawn, minY to the mimium Y level your ore can be found at and maxY to the maximum Y level your ore will spawn. And we're done! Just need to add WorldGenInit.init() to the init method of your mod file and we are done! This is what the LeadOreGen should look like (without generateNether and end) and here is a picture of lead spawning.

bottom of page