I wrote this simple set of nested for loops to replace all blocks except air in any given chunk with bedrock. It seems to hang the world generation. Can anyone help fix the code or suggest a better way to replace all blocks in a given chunk.
public boolean generate(World world, Random random, int posX, int posY, int posZ)
int replaceBlock = Block.bedrock.blockID;
for (int zN=0;zN<15;zN++)
for (int xN=0;xN<15;xN++)
for(int yN=0;yN < 128;yN++)
if (!world.isAirBlock(posX+xN, yN, posZ+zN))
world.setBlockWithNotify(posX+xN, yN, posZ+zN, replaceBlock);
world.setBlock(posX, 80, posZ, Block.bedrock.blockID);//adds a bedrock in the sky above each chunk origin
Without going into too much detail, I remember that setBlockWithNotify updates lighting... ugliness always ensues. Try "setBlock", and come back if it still doesn't work for you.
Also, iterating through every block in a chunk is harsh stuff. The times I've played with terrain (WoolWorld!! ... Lava! Run!) I've gone into the classes that generate ground and water and villages etc. and changed them to put (bedrock/wool) in from the start.
is there a better way than iterating through every X.Y,Z location? Are the block stored in a chunk container and I could do a "for each" loop?
I replaced with setBlock and it works sometimes. I found one seed it works on every time so my guess is that its crashing somewhere during all the loops or throwing an error. If i remove one layer of iteration it works flawlessly and just does every block in the X and Z axis.
How would I do this with the biome/terrain generation? I'm not sure when the biome selection is called but if I found that I would have it select a different biome on a per chunk basis.
My guess is, if it works fine with just two layers of iteration, you're too ambitious for your own computer: it's too slow. As an alternative, you could try any number of things:
- Edit parts of the terrain generator to put bedrock in place from the get-go
If you wanted to get creative, and achieve a similar effect without making slag out of your computer, you could:
- Only replace, say, grass, sand, and water with the bedrock (near the surface)
- Replace blocks in a 10-block area around the player as it moves, letting him "paint the town gray", so to speak
- Only replace blocks from y=50 (?) to y=128 or even less: basically only what the player will see on the surface.
- Only replace the chunk the player is in and the 9 adjacent ones; turn the fog up way high and mysical, and convert chunks as the player walks.
And my personal favorite:
- Hack texture.png to be all-bedrock, replace only water and lava (since they disobey the texturepack until 1.5), and set all blocks' hardness to -1. I think you can create and activate texture packs by code...
The best part about this one is that stairs and fences will look like carved bedrock stairs and fences.
New terrain is always fun: good luck, and have pity on your hard-working computer
EDIT: Check to see how long a chunk takes to replace by putting this code into your replacer:
AT TOP OF LOOP:
long startTime = System.currentTimeMillis();
System.out.println ("Started Bedrock-o-Matic on a chunk.");
I think it would be better if you change the generation code in the ChunkProvider or if you dont want to edit Basefiles you can make a new WorldType which use your custom ChunkProvider.
Here's a Tutorial about How to make a new WorldType. SOme Parts maybe will not work in the actual version. But I think you can just copy the original Minecraft code and you only have to chabge the generateTerrain in the ChunkProvider file.
In this tutorial is a pretty good explanation about simple Chunk generation. ( Which still works )
caagr98: This is exactly what I wanted! That will help immensly. Yeah I had noticed the 15-16 thing as I had unconverted lines running through the whole world.
Also one bug also made skyhigh walls of bedrock running in the Z axis down the whole world. It might make an interesting game mode (World is only one chunk wide. spawn point is at one end).
Im working on a bedrockVirus biome to implement at the moment, complete with special structures. Now I need to figure out how to change the color hues, and if they effect all blocks or just grass/leaves.
The reason your method was so expensive is because it's not using buffers...
The chunks in minecraft are created by 3 nested loops creating points, and then stored in a buffer which spits them all out into 3D space at the same time.
This is the same way that a video card work compared to an on-board graphics processor.
Your method is basically doing ^3 the work as the minecraft chunkloader.
(this can add up quickly as 100 is the normal height of a chunk, and they're 16x16...that would be 16384^3 which is 4,398,046,511,104 iterations...not only is that a lot of iterations, each iteration has loads of work to do with storing 8 sets of 3 doubles to your RAM and using LWJGL to process the points and draw cubes...so you can see now why your computer might be huffing a puffing a little bit? haha)
In order to change all of the blocks effectively and efficiently, you would need to go into the world generation and basically just disable all biomes, etc. and change the generation block to bedrock.
the get top block method caagr98 suggested is a great alternative