Modding: Custom Structure generation

In this tutorial I will show you how to create your own world generation file that you can use to make a custom structure. This tutorial doesn’t show you how to actually let it generate, but just how to add blocks inside of it. There will be 2 different tutorials on how to add this world generation file. 1 for the custom dimension and one for the normal game.
To get your world gen file started just right click on your common mod package and click create a class. Name it WorldGen[YourStructureName]. Now make sure that it looks something like this.


package Tutorial.common;

import java.util.Random;

import net.minecraft.src.World;
import net.minecraft.src.WorldGenerator;

public class WorldGenStructureTutorial extends WorldGenerator
{
    public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5)
    {
        while (par1World.isAirBlock(par3, par4, par5) && par4 > 2)
        {
            –par4;
        }
        
        return true;
    }
}


The generate method is the method used to place all the blocks etc.
The while loop inside of the generate method is used to make sure that the generation doesn’t start in the air, but on a block.
To place blocks in your world have to use a line like this.


par1World.setBlock(par3, par4, par5, Block.blockDiamond.blockID);


The first 3 parameters are the X, Y and Z. The last one is the block id you want to be placed. If you want to add a block with metadata you have to add this code.


par1World.setBlockAndMetadata(par3, par4 – 1, par5, Block.stoneBrick.blockID, 1);


The forth parameter in here is the metadata.
You can change the location of the blocks by adding a + number or – number behind the x, y or z.
If you want to generate water or lava you need to make sure you select the Moving version or the block will not spread out like normal water or lava does.
The whole file should now look something like this.


package Tutorial.common;

import java.util.Random;

import net.minecraft.src.Block;
import net.minecraft.src.World;
import net.minecraft.src.WorldGenerator;

public class WorldGenStructureTutorial extends WorldGenerator
{
    public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5)
    {
        while (par1World.isAirBlock(par3, par4, par5) && par4 > 2)
        {
            –par4;
        }
        
        par1World.setBlock(par3, par4, par5, Block.blockDiamond.blockID);
        par1World.setBlockAndMetadata(par3, par4 – 1, par5, Block.stoneBrick.blockID, 1);
        
        return true;
    }
}


 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">