In this tutorial I will describe how the map generation works and how to create your own custom map generation. What I mean by map generation is when a new world is created or new chunks are created that terrain that appears is generated terrain - this tutorial will show you how to customise how this happens. I have made quite a few map generation mods now and in my opinion I would have to say they are the most fun. Here are some examples:
Forests
Tall Tree Forests
Ruins
Infinite Track
So as you can see there is a nice variety of map generation available. In this tutorial I will show you how to create a map generator to place random quantities of TNT on the map (a bit of fun =D).
To begin with you will need to create a new WorldGen class, the naming convention is as follows WorldGen[NAME] so for this example I will create a class called WorldGenExample. The bare bones class requires a constructor and generate method. Here it is below:
package net.minecraft.src;
import java.util.Random;
public class WorldGenExample extends WorldGenerator
{
public WorldGenExample()
{
}
public boolean generate(World world, Random random, int i, int j, int k)
{
}
}
Within the generate method we want to put all the logic of the generator. The i, j, k parameters are the block coordinate within minecraft, in general not every block is called and only one block per chunk is called - so keep in mind that each time the generate method is called it is (generally) the only time it will be called for that chunk.
To create the random TNT I am going to add this code to the generate method:
// Gives this a 1 in 10 chance of generating
if (random.nextInt(10) == 0)
{
// Loops 64 times, this could create up to 64 TNT
for (int z = 0; z < 64; z++)
{
int i1 = i + random.nextInt(8) - random.nextInt(8);
int j1 = j + random.nextInt(8) - random.nextInt(8);
int k1 = k + random.nextInt(8) - random.nextInt(8);
// Checks that there is nothing in the current location and there is grass beneath.
if(world.getBlockId(i1, j1, k1) == 0 && world.getBlockId(i1, j1 - 1, k1) == Block.grass.blockID && Block.tnt.canPlaceBlockAt(world, i1, j1, k1))
{
world.setBlockAndMetadata(i1, j1, k1, Block.tnt.blockID, random.nextInt(4));
}
}
}
After coding the logic of your terrain generation you need to let minecraft know about it so that it can generate the terrain. To do this you need to edit ChunkProviderGenerate, specifically the populate method. This method should be pretty self explanatory - it generates Lakes then Dungeons then Clay, etc etc. You need to add your class to this method - where you put it in this list is very important. If you put it at the top of the method, it is a lot more likely to be generated than having it at the bottom of the method - the choice is yours, I am putting this towards the bottom of the method, specifically below the WorldGenLiquids calls.
(new WorldGenExample()).generate(worldObj, rand, k + rand.nextInt(16), rand.nextInt(112) + 16, l + rand.nextInt(16));
Finally after compiling and generating a new world or exploring new areas in a current world you should be able to find TNT spawns. You may want to configure the randomness and quantity per request to be more to your liking.
Here I will be telling you how to make your mod compatible with modloader. If you are using MCP, you have ran into this bump of sadness. If you have noticed, these tutorials require editing main Minecraft class files. No more doing that with modloader!
EDIT: I have deleted the download for modloader MCP source because Risugami's epicness has finally made it compatible if you just decompile modloader! Just put the modloader files in your minecraft.jar inside of the MCP jars folder, decompile, and you got yourself a working modloader.
It includes every function on the newest modloader, seeing as you're decompiling the current one.
Anyways, this includes some great functions! First of all, you will have to put mod_ at the front of your mod's name, and put this at the top of the code:
public class mod_MyMod extends BaseMod
Now in Beta 1.2_02, there's something you have to do like this:
public String Version()
{
return "1.2_02";
}
If you want to register a block from there, use this inside your public class:
public static final Block example;
static
{
example = (new BlockExample(92, 1)).setHardness(1.5F).setStepSound(Block.soundStoneFootstep);
}
Notice "Block" in front of soundStoneFootstep. This is required as it is being defined in an outside class.
And for the other functions :happy.gif:
public void AddRecipes(CraftingManager recipes)
public int AddSmelting(int id)
public int AddFuel(int id)
public void AddEntityID()
public void GenerateNether(World world, Random random, int chunkX, int chunkZ)
public void GenerateSurface(World world, Random random, int chunkX, int chunkZ)
Soon to come: How to use those functions with tutorials explained above!
In BaseMod, you will find a lot of functions to prevent your mod from overwriting the classes that most mods would use if it weren't for modloader. Here is how to use them.
public void AddEntityID() This tutorial has modloader code for NPC making that includes this function used in it.
public int AddFuel(int id)
Here is an example code I got from an example mod I made. Since there is no fuel tutorial, the number is how long it will take to smelt. Wood is 300, sticks are 100, coal is 1600, and lava buckets are 20000.
public int AddFuel(int id)
{
if(id == Item.flint.shiftedIndex)
{
return 2400;
}
return 0;
}
public void AddRecipes(CraftingManager recipes)
Read the crafting tutorial on this. An example code:
public void AddRecipes(CraftingManager recipes)
{
recipes.addRecipe(new ItemStack(Item.diamond), new Object[] {
"#", Character.valueOf('#'), Block.dirt
});
}
public int AddSmelting(int id)
Read up on the smelting tutorial for more information.
public int AddSmelting(int id)
{
if(id == Block.dirt.blockID)
{
return Item.diamond.shiftedIndex;
}
}
I still have to have explanations for the following:
public void GenerateNether(World world, Random random, int chunkX, int chunkZ)
{
}
public void GenerateSurface(World world, Random random, int chunkX, int chunkZ)
{
}
Until then, have fun with your new modloader mod!
Coming soon:
Part 2 - ModLoader functions
World generation explanations...
I'm trying to create a new recipe. I did what it said here, but it didn't work. I've also tried with an item that isn't custom, and it still didn't work.
The recipe given in this example should never fail if you have the BlockExample class; try this standard recipe:
addRecipe(new ItemStack(Block.stone, 1), new Object[] {"##", "##", Character.valueOf('#'), Block.dirt});
Make sure you recompile and make sure that there are no compile errors, read my original post regarding compiling and debugging.
**edit**
As an afterthought, view the console window while minecraft is open, load a world and press the escape key. The console window should output "100 recipes".
[parsing started sources\minecraft\net\minecraft\src\SimpleMap.java]
sources\minecraft\net\minecraft\src\SimpleMap.java:49: not a statement
this;
^
sources\minecraft\net\minecraft\src\SimpleMap.java:50: ';' expected
JVM INSTR dup_x1 ;
^
sources\minecraft\net\minecraft\src\SimpleMap.java:50: not a statement
JVM INSTR dup_x1 ;
^
sources\minecraft\net\minecraft\src\SimpleMap.java:51: not a statement
field_15039_listenerVelocity;
^
sources\minecraft\net\minecraft\src\SimpleMap.java:53: not a statement
field_15030_normalChannelSourceNames;
^
sources\minecraft\net\minecraft\src\SimpleMap.java:55: not a statement
"mods";
^
sources\minecraft\net\minecraft\src\SimpleMap.java:57: not a statement
field_15030_normalChannelSourceNames;
^
sources\minecraft\net\minecraft\src\SimpleMap.java:59: not a statement
"SimpleMap";
^
sources\minecraft\net\minecraft\src\SimpleMap.java:61: not a statement
field_15030_normalChannelSourceNames;
^
sources\minecraft\net\minecraft\src\SimpleMap.java:64: not a statement
field_15039_listenerVelocity;
^
it is bugging me so much
Edit-
Fixed it but now when i run the reobf.bat and i put the files in the minecraft.jar, i log in and it just goes to a blank screen :sad.gif:
Hi,
I have a request for a tut, and maybe it goes beyond the scope of this thread, but could someone make a tut showing how to merge two class files together to make mods work together (example: hand held torch and higher clouds both use the f class). And maybe one showing how to change block ids of mods so people could get all the mods they want working together is joyous rapture.
[parsing started sources\minecraft\net\minecraft\src\SimpleMap.java]
sources\minecraft\net\minecraft\src\SimpleMap.java:49: not a statement
this;
^
sources\minecraft\net\minecraft\src\SimpleMap.java:50: ';' expected
JVM INSTR dup_x1 ;
^
sources\minecraft\net\minecraft\src\SimpleMap.java:50: not a statement
JVM INSTR dup_x1 ;
^
sources\minecraft\net\minecraft\src\SimpleMap.java:51: not a statement
field_15039_listenerVelocity;
^
sources\minecraft\net\minecraft\src\SimpleMap.java:53: not a statement
field_15030_normalChannelSourceNames;
^
sources\minecraft\net\minecraft\src\SimpleMap.java:55: not a statement
"mods";
^
sources\minecraft\net\minecraft\src\SimpleMap.java:57: not a statement
field_15030_normalChannelSourceNames;
^
sources\minecraft\net\minecraft\src\SimpleMap.java:59: not a statement
"SimpleMap";
^
sources\minecraft\net\minecraft\src\SimpleMap.java:61: not a statement
field_15030_normalChannelSourceNames;
^
sources\minecraft\net\minecraft\src\SimpleMap.java:64: not a statement
field_15039_listenerVelocity;
^
it is bugging me so much
Edit-
Fixed it but now when i run the reobf.bat and i put the files in the minecraft.jar, i log in and it just goes to a blank screen :sad.gif:
Blank screen means that the META-INF folder wasn't deleted or there is map corruption in on or more of your maps or you are playing in browser mode.
[parsing started sources\minecraft\net\minecraft\src\WorldGenExample.java]
sources\minecraft\net\minecraft\src\WorldGenExample.java:17: class, interface, or enum expected
if (random.nextInt(10) == 0)
^
sources\minecraft\net\minecraft\src\WorldGenExample.java:20: class, interface, or enum expected
for (int z = 0; z < 64; z++)
^
sources\minecraft\net\minecraft\src\WorldGenExample.java:20: class, interface, or enum expected
for (int z = 0; z < 64; z++)
^
sources\minecraft\net\minecraft\src\WorldGenExample.java:23: class, interface, or enum expected
int j1 = j + random.nextInt(8) - random.nextInt(8);
^
sources\minecraft\net\minecraft\src\WorldGenExample.java:24: class, interface, or enum expected
int k1 = k + random.nextInt(8) - random.nextInt(8);
^
sources\minecraft\net\minecraft\src\WorldGenExample.java:26: class, interface, or enum expected
if(world.getBlockId(i1, j1, k1) == 0 && world.getBlockId(i1, j1 - 1, k1) == Block.sand.blockID && Block.example.canPlaceBlockAt(world, i1, j1, k1))
^
sources\minecraft\net\minecraft\src\WorldGenExample.java:29: class, interface, or enum expected
}
^
i copyed the code for the WorldGen exacty and got this
So you put that code in the generate method, right? Those errors are due to the code not falling in a code block, which means that there are braces missing somewhere.
Hi,
I have a request for a tut, and maybe it goes beyond the scope of this thread, but could someone make a tut showing how to merge two class files together to make mods work together (example: hand held torch and higher clouds both use the f class). And maybe one showing how to change block ids of mods so people could get all the mods they want working together is joyous rapture.
Yeah I suppose that is relevant to this thread.. It isn't too hard, involves using a decompiler and a little bit of patience. As for changing the block ids I would imagine that the mod loader should handle this? If it doesn't that's silly, though I am willing to show you how to do that as well... quite simple, actually it is basically covered in my block tutorial.
There should be examples of this on risugami's thread.
In this tutorial I will describe how the map generation works and how to create your own custom map generation. What I mean by map generation is when a new world is created or new chunks are created that terrain that appears is generated terrain - this tutorial will show you how to customise how this happens. I have made quite a few map generation mods now and in my opinion I would have to say they are the most fun. Here are some examples:
Forests
Tall Tree Forests
Ruins
Infinite Track
So as you can see there is a nice variety of map generation available. In this tutorial I will show you how to create a map generator to place random quantities of TNT on the map (a bit of fun =D).
To begin with you will need to create a new WorldGen class, the naming convention is as follows WorldGen[NAME] so for this example I will create a class called WorldGenExample. The bare bones class requires a constructor and generate method. Here it is below:
Within the generate method we want to put all the logic of the generator. The i, j, k parameters are the block coordinate within minecraft, in general not every block is called and only one block per chunk is called - so keep in mind that each time the generate method is called it is (generally) the only time it will be called for that chunk.
To create the random TNT I am going to add this code to the generate method:
After coding the logic of your terrain generation you need to let minecraft know about it so that it can generate the terrain. To do this you need to edit ChunkProviderGenerate, specifically the populate method. This method should be pretty self explanatory - it generates Lakes then Dungeons then Clay, etc etc. You need to add your class to this method - where you put it in this list is very important. If you put it at the top of the method, it is a lot more likely to be generated than having it at the bottom of the method - the choice is yours, I am putting this towards the bottom of the method, specifically below the WorldGenLiquids calls.
Finally after compiling and generating a new world or exploring new areas in a current world you should be able to find TNT spawns. You may want to configure the randomness and quantity per request to be more to your liking.
Now can you make armor tutorial after?
Sure, I will probably do it tomorrow morning.
<PLACEHOLDER FOR ARMOUR TUTORIAL>
Hey guys
Here I will be telling you how to make your mod compatible with modloader. If you are using MCP, you have ran into this bump of sadness. If you have noticed, these tutorials require editing main Minecraft class files. No more doing that with modloader!
EDIT: I have deleted the download for modloader MCP source because Risugami's epicness has finally made it compatible if you just decompile modloader! Just put the modloader files in your minecraft.jar inside of the MCP jars folder, decompile, and you got yourself a working modloader.
It includes every function on the newest modloader, seeing as you're decompiling the current one.
Anyways, this includes some great functions! First of all, you will have to put mod_ at the front of your mod's name, and put this at the top of the code:
Now in Beta 1.2_02, there's something you have to do like this:
If you want to register a block from there, use this inside your public class:
Notice "Block" in front of soundStoneFootstep. This is required as it is being defined in an outside class.
And for the other functions :happy.gif:
public void AddRecipes(CraftingManager recipes)
public int AddSmelting(int id)
public int AddFuel(int id)
public void AddEntityID()
public void GenerateNether(World world, Random random, int chunkX, int chunkZ)
public void GenerateSurface(World world, Random random, int chunkX, int chunkZ)
Soon to come: How to use those functions with tutorials explained above!
In BaseMod, you will find a lot of functions to prevent your mod from overwriting the classes that most mods would use if it weren't for modloader. Here is how to use them.
public void AddEntityID()
This tutorial has modloader code for NPC making that includes this function used in it.
public int AddFuel(int id)
Here is an example code I got from an example mod I made. Since there is no fuel tutorial, the number is how long it will take to smelt. Wood is 300, sticks are 100, coal is 1600, and lava buckets are 20000.
public void AddRecipes(CraftingManager recipes)
Read the crafting tutorial on this. An example code:
public int AddSmelting(int id)
Read up on the smelting tutorial for more information.
I still have to have explanations for the following:
Until then, have fun with your new modloader mod!
Coming soon:
Part 2 - ModLoader functions
World generation explanations...
sweet, thanks! I will add it to the original post.
The recipe given in this example should never fail if you have the BlockExample class; try this standard recipe:
Make sure you recompile and make sure that there are no compile errors, read my original post regarding compiling and debugging.
**edit**
As an afterthought, view the console window while minecraft is open, load a world and press the escape key. The console window should output "100 recipes".
Are you adding the recipes before this line of code at the bottom of the method?
If on Windows XP: %appdata%
If on Windows 7: %appdata%\roaming
Other OS's I am not sure, sorry. There are plenty of threads and websites which would tell you though - just search.
it is bugging me so much
Edit-
Fixed it but now when i run the reobf.bat and i put the files in the minecraft.jar, i log in and it just goes to a blank screen :sad.gif:
i copyed the code for the WorldGen exacty and got this
Support Kimba in getting him back on air!
http://www.minerwars.com/?aid=938
I have a request for a tut, and maybe it goes beyond the scope of this thread, but could someone make a tut showing how to merge two class files together to make mods work together (example: hand held torch and higher clouds both use the f class). And maybe one showing how to change block ids of mods so people could get all the mods they want working together is joyous rapture.
Blank screen means that the META-INF folder wasn't deleted or there is map corruption in on or more of your maps or you are playing in browser mode.
So you put that code in the generate method, right? Those errors are due to the code not falling in a code block, which means that there are braces missing somewhere.
Yeah I am busy the next few days but when I get a chance I will find it and upload it
Yeah I suppose that is relevant to this thread.. It isn't too hard, involves using a decompiler and a little bit of patience. As for changing the block ids I would imagine that the mod loader should handle this? If it doesn't that's silly, though I am willing to show you how to do that as well... quite simple, actually it is basically covered in my block tutorial.