I'm working on a mod with ModLoader and I'm stuck at trying to replace stone generation with a different block. I want to generate the world so that stone from elevations 1 to 12 are replaced with a new block, elevations 13 to 24 are replaced with a different new block, etc. I have two different ways I've tried: the first one is generating the new block as an ore that replaces all of the stone like that. This method works for the most part but leaves the occasional stone block in the middle.
Here is the code:
public void generateSurface(World world, Random random, int i, int j) {
int height = 12;
for (int k = 0; k < 400; k++) {
int randPosX = i + random.nextInt(16);
int randPosY = random.nextInt(height) + 0 * height + 1;
int randPosZ = j + random.nextInt(16);
(new WorldGenMinable(stone6.blockID, 20)).generate(world, random, randPosX, randPosY, randPosZ);
} for (int k = 0; k < 400; k++) {
int randPosX = i + random.nextInt(16);
int randPosY = random.nextInt(height) + 1 * height + 1;
int randPosZ = j + random.nextInt(16);
(new WorldGenMinable(stone5.blockID, 20)).generate(world, random, randPosX, randPosY, randPosZ);
} for (int k = 0; k < 400; k++) {
int randPosX = i + random.nextInt(16);
int randPosY = random.nextInt(height) + 2 * height + 1;
int randPosZ = j + random.nextInt(16);
(new WorldGenMinable(stone4.blockID, 20)).generate(world, random, randPosX, randPosY, randPosZ);
} for (int k = 0; k < 400; k++) {
int randPosX = i + random.nextInt(16);
int randPosY = random.nextInt(height) + 3 * height + 1;
int randPosZ = j + random.nextInt(16);
(new WorldGenMinable(stone3.blockID, 20)).generate(world, random, randPosX, randPosY, randPosZ);
} for (int k = 0; k < 400; k++) {
int randPosX = i + random.nextInt(16);
int randPosY = random.nextInt(height) + 4 * height + 1;
int randPosZ = j + random.nextInt(16);
(new WorldGenMinable(stone2.blockID, 20)).generate(world, random, randPosX, randPosY, randPosZ);
} for (int k = 0; k < 400; k++) {
int randPosX = i + random.nextInt(16);
int randPosY = random.nextInt(height) + 5 * height + 1;
int randPosZ = j + random.nextInt(16);
(new WorldGenMinable(stone1.blockID, 20)).generate(world, random, randPosX, randPosY, randPosZ);
}
}
The other way I was trying to replace the blocks was with world.setBlock() and filtering it to only blocks with Block.stone.blockID. This way is very thorough but the world often crashes before it can finish pre-rendering because it is changing so many blocks. I was only able to do this on a few levels at a time.
Here is the code for the second method:
public void generateSurface(World world, Random random, int i, int j) {
int height = 12;
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
for (int y = 0 * height + 1; y <= 1 * height; y++) {
if (world.getBlockId(x + i, y, z + j) == Block.stone.blockID) world.setBlock(x + i, y, z + j, stone6.blockID);
} for (int y = 1 * height + 1; y <= 2 * height; y++) {
if (world.getBlockId(x + i, y, z + j) == Block.stone.blockID) world.setBlock(x + i, y, z + j, stone5.blockID);
} for (int y = 2 * height + 1; y <= 3 * height; y++) {
if (world.getBlockId(x + i, y, z + j) == Block.stone.blockID) world.setBlock(x + i, y, z + j, stone4.blockID);
} for (int y = 3 * height + 1; y <= 4 * height; y++) {
if (world.getBlockId(x + i, y, z + j) == Block.stone.blockID) world.setBlock(x + i, y, z + j, stone3.blockID);
} for (int y = 4 * height + 1; y <= 5 * height; y++) {
if (world.getBlockId(x + i, y, z + j) == Block.stone.blockID) world.setBlock(x + i, y, z + j, stone2.blockID);
} for (int y = 5 * height + 1; y <= 6 * height; y++) {
if (world.getBlockId(x + i, y, z + j) == Block.stone.blockID) world.setBlock(x + i, y, z + j, stone1.blockID);
}
}
}*/
}
Is there any other way I could modify world generation in levels like this? If not are there any improvements I could make?
I want to replace the stone, not ores. I would like the generation to replace all stone at the bottom with "Stone 6", the stone in the layers above that with "Stone 5", above that with "Stone 4" etc. My Goal is to make the stone change properties as the player gets lower into the ground.
Here is the code:
The other way I was trying to replace the blocks was with world.setBlock() and filtering it to only blocks with Block.stone.blockID. This way is very thorough but the world often crashes before it can finish pre-rendering because it is changing so many blocks. I was only able to do this on a few levels at a time.
Here is the code for the second method:
Is there any other way I could modify world generation in levels like this? If not are there any improvements I could make?
Thank you
I made that 20 a 10000, yes it works, and it makes EVERYTHING on the layers it is specified to generate the block you stated in there.
Try that out.