Modding: Adding the structure to the world
In this tutorial I will show you how to let the structure created in this tutorial generate in your world. This is done in the generator file. I will start with this one.
package Tutorial.common;
import java.util.Random;
import net.minecraft.src.IChunkProvider;
import net.minecraft.src.World;
import net.minecraft.src.WorldGenMinable;
import cpw.mods.fml.common.IWorldGenerator;
public class WorldgeneratorTutorial implements IWorldGenerator
{
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
{
switch (world.provider.dimensionId)
{
case -1: generateNether(world, random, chunkX*16, chunkZ*16);
case 0: generateSurface(world, random, chunkX*16, chunkZ*16);
}
}
private void generateSurface(World world, Random random, int blockX, int blockZ)
{
int Xcoord = blockX + random.nextInt(16);
int Ycoord = random.nextInt(60);
int Zcoord = blockZ + random.nextInt(16);
(new WorldGenMinable(Tutorial.oreblock.blockID, 10)).generate(world, random, Xcoord, Ycoord, Zcoord);
}
private void generateNether(World world, Random random, int blockX, int blockZ)
{
int Xcoord = blockX + random.nextInt(16);
int Ycoord = random.nextInt(60);
int Zcoord = blockZ + random.nextInt(16);
(new WorldGenMinableNether(Tutorial.oreblock.blockID, 1, 10)).generate(world, random, Xcoord, Ycoord, Zcoord);
}
}
To add the structure you have to add this code.
int Xcoord1 = blockX + random.nextInt(16);
int Ycoord1 = random.nextInt(80);
int Zcoord1 = blockZ + random.nextInt(16);
(new WorldGenStructureTutorial()).generate(world, random, Xcoord1, Ycoord1, Zcoord1);
The Xcoord1, Ycoord1, Zcoord1 are the coördinates of the strucure. They will need a 1 behind it if the one without the number is already taken. Make sure that you also change the X, Y and Z inside the .generate.
WorldGenStructureTutorial is the file where the structure is set.
This is how the file should look like.
package Tutorial.common;
import java.util.Random;
import net.minecraft.src.IChunkProvider;
import net.minecraft.src.World;
import net.minecraft.src.WorldGenMinable;
import cpw.mods.fml.common.IWorldGenerator;
public class WorldgeneratorTutorial implements IWorldGenerator
{
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
{
switch (world.provider.dimensionId)
{
case -1: generateNether(world, random, chunkX*16, chunkZ*16);
case 0: generateSurface(world, random, chunkX*16, chunkZ*16);
}
}
private void generateSurface(World world, Random random, int blockX, int blockZ)
{
int Xcoord = blockX + random.nextInt(16);
int Ycoord = random.nextInt(60);
int Zcoord = blockZ + random.nextInt(16);
(new WorldGenMinable(Tutorial.oreblock.blockID, 10)).generate(world, random, Xcoord, Ycoord, Zcoord);
int Xcoord1 = blockX + random.nextInt(16);
int Ycoord1 = random.nextInt(80);
int Zcoord1 = blockZ + random.nextInt(16);
(new WorldGenStructureTutorial()).generate(world, random, Xcoord1, Ycoord1, Zcoord1);
}
private void generateNether(World world, Random random, int blockX, int blockZ)
{
int Xcoord = blockX + random.nextInt(16);
int Ycoord = random.nextInt(60);
int Zcoord = blockZ + random.nextInt(16);
(new WorldGenMinableNether(Tutorial.oreblock.blockID, 1, 10)).generate(world, random, Xcoord, Ycoord, Zcoord);
}
}
Leave a Reply