Block Generation
A simple tutorial. First, declare this in your init section of your main file:
GameRegistry.registerWorldGenerator(new WorldGenTutBlock ());
To make the WorldGenTutBlock class, copy this inside it:
package tutorial.package;
import java.util.Random;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.feature.WorldGenMinable;
import cpw.mods.fml.common.IWorldGenerator;
public class WorldGenTutBlock implements IWorldGenerator
{
@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
{
switch(world.provider.dimensionId)
{
case 0:
generateSurface(world, random, chunkX*16, chunkZ*16);
break;
}
}
public void generateSurface(World world, Random rand, int chunkX, int chunkZ)
{
for (int i = 0; i < 16; i++)
{
int randPosX = chunkX + rand.nextInt(16);
int randPosY = rand.nextInt(48);
int randPosZ = chunkZ + rand.nextInt(16);
(new WorldGenMinable(TutorialMain.TutBlock.blockID, 10)).generate(world, rand, randPosX, randPosY, randPosZ);
}
}
}
Let's skip right to the generateSurface method. for (int = 0; i<16; i++) determines the frequency of your ore. The larger the number, the more likely it will be to find.
Under that, randPosX = chunkX + rand.nexInt(16) and int randPosZ = chunkZ + rand.newInt(16) should stay this way. This keeps the blocks inside the chunk. The one that you should mess with is the randPosY. 48 is the level that this block will be and everything below it. For example, diamond is 18, while coal is 256.
This also works for flowers and plants.
That's it for an block gen tutorial, time to look at some unique items.
GameRegistry.registerWorldGenerator(new WorldGenTutBlock ());
To make the WorldGenTutBlock class, copy this inside it:
package tutorial.package;
import java.util.Random;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.feature.WorldGenMinable;
import cpw.mods.fml.common.IWorldGenerator;
public class WorldGenTutBlock implements IWorldGenerator
{
@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
{
switch(world.provider.dimensionId)
{
case 0:
generateSurface(world, random, chunkX*16, chunkZ*16);
break;
}
}
public void generateSurface(World world, Random rand, int chunkX, int chunkZ)
{
for (int i = 0; i < 16; i++)
{
int randPosX = chunkX + rand.nextInt(16);
int randPosY = rand.nextInt(48);
int randPosZ = chunkZ + rand.nextInt(16);
(new WorldGenMinable(TutorialMain.TutBlock.blockID, 10)).generate(world, rand, randPosX, randPosY, randPosZ);
}
}
}
Let's skip right to the generateSurface method. for (int = 0; i<16; i++) determines the frequency of your ore. The larger the number, the more likely it will be to find.
Under that, randPosX = chunkX + rand.nexInt(16) and int randPosZ = chunkZ + rand.newInt(16) should stay this way. This keeps the blocks inside the chunk. The one that you should mess with is the randPosY. 48 is the level that this block will be and everything below it. For example, diamond is 18, while coal is 256.
This also works for flowers and plants.
That's it for an block gen tutorial, time to look at some unique items.