I've seen lots of tutorials on making ores spawn but none on making my own plants spawn in new worlds and chunks. I don't care which biome (since I'll eventually have plants for all the biomes). I am very intuitive, or so I thought, as I never ask for help. I normally figure things out, but this has got me lost. I have no code to post to start out with but I'll start trying things after picking modloader apart.
Any generation is basically the same in that respect. Put the code below into your mod_** file and add the name of your plant in.
public void GenerateSurface(World world, Random rand, int chunkX, int chunkZ)
{
for (int i = 0; i< 25; i++)
{
int randPosX = chunkX + rand.nextInt(16);
int randPosY = rand.nextInt(128); //128 makes the block generate on the surface
int randPosZ = chunkZ + rand.nextInt(16);
(new WorldGenMinable(PlantBlockName.blockID, 50)).generate(world, rand, randPosX, randPosY, randPosZ);
}
}
“Computers are incredibly fast, accurate and stupid; humans are incredibly slow, inaccurate and brilliant; together they are powerful beyond imagination."
I was toying with that before and verified that mine was like yours. It seemed to work after I knocked the 50 down to 16, but before that it wouldn't load. Even now that it's 16 it lags A LOT. So much that the game is unplayable. I am going to keep tweaking things until it works a bit smoother.
Using WorldGenMinable means it will spawn inside of stone, and I dont think you want your plant to do that. Try using this code.
public void GenerateSurface(World var1, Random var2, int var3, int var4)
{
int var5;
int var6;
int var7;
int var8;
for(var5 = 0; var5 < 2; ++var5)
{
var6 = var3 + var2.nextInt(16) + 8;
var7 = var2.nextInt(128);
var8 = var4 + var2.nextInt(16) + 8;
(new WorldGenFlowers(MyPlant.blockID)).generate(var1, var2, var6, var7, var8);
}
}
I understand what you mean, and its a good point. This has been something I have been trying to figure out for a while. I gave him that WorldGenMinable code because the 128 will spawn on the surface layer no matter what the actual layer is.
EDIT: I just tested your code, and it crashes the game when generating new world
“Computers are incredibly fast, accurate and stupid; humans are incredibly slow, inaccurate and brilliant; together they are powerful beyond imagination."
Why is this not working???!? I have a feeling that is has something to do with the variables
public void GenerateSurface(World world, Random random, int i, int j, int k)
{
for(int l = 0; l < 64; l++)
{
int i1 = (i + random.nextInt(8)) - random.nextInt(8); // I think there is
int j1 = (j + random.nextInt(4)) - random.nextInt(4); // something wrong
int k1 = (k + random.nextInt(8)) - random.nextInt(8); // with this part
(new WorldGenFlowers(mod_BuffFood.ChilliPepper.blockID)).generate(world, random, i1, j1, k1);
}
}
public void GenerateSurface(World world, Random rand, int chunkX, int chunkZ)
{
for(int i = 0; i < 18; i++)
{
int randPosX = chunkX + rand.nextInt(16);
int randPosY = rand.nextInt(128);
int randPosZ = chunkZ + rand.nextInt(16);
(new WorldGenMinable(mod_BuffFood.ChilliPepper.blockID, 10)).generate(world, rand, randPosX, randPosY, randPosZ);
}
}
together they are powerful beyond imagination."
I understand what you mean, and its a good point. This has been something I have been trying to figure out for a while. I gave him that WorldGenMinable code because the 128 will spawn on the surface layer no matter what the actual layer is.
EDIT: I just tested your code, and it crashes the game when generating new world
together they are powerful beyond imagination."
That meants it can spawn anywhere from 0 to 127. If you wanted it to be above say 60, but still random you could do this:
Works for me. :smile.gif:
Me too :sad.gif:
!! And has anyone figured out why I am lagging so badly while playing with the generate code? I comment it out and everything is fine. wtf?
j1 is the y axis coordinate
You are only spawning it between -4 and 4...
That must be why it's not lagging my game anymore either. I'll change that and get back to everyone.