Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Tries to load a chunk from disk. If the chunk is not present,
- * it is created from scratch.
- *
- * @return True if a generation has been executed
- */
- public boolean generate() {
- if (isFresh()) {
- for (ChunkGenerator gen : _parent.getGeneratorManager().getChunkGenerators()) {
- gen.generate(this);
- }
- // Use a TeraArray here to test for integrity - how well the blocks are supported by the world
- TeraArray integrity = new TeraArray(CHUNK_DIMENSION_X, CHUNK_DIMENSION_Y, CHUNK_DIMENSION_Z);
- System.out.println("Generating chunk" + getPosition());
- // Fill the bottom layer (which should always be MantleStone) with the highest possible integrity value
- for (int x = 0; x < CHUNK_DIMENSION_X; x++) {
- for (int z = 0; z < CHUNK_DIMENSION_Z; z++) {
- integrity.set(x, 0, z, (byte) 255);
- }
- }
- // Now fill in values for all blocks that are immediately supported by the bottom layer (so we start at y = 1)
- for (int y = 1; y < CHUNK_DIMENSION_Y; y++) {
- for (int x = 0; x < CHUNK_DIMENSION_X; x++) {
- for (int z = 0; z < CHUNK_DIMENSION_Z; z++) {
- byte b = _blocks.get(x, y, z);
- //System.out.println("Block ID at " + x + ", " + y + ", " + z + " is " + _blocks.get(x, y, z));
- //Block myBlock = BlockManager.getInstance().getBlock(b);
- //System.out.println("That Block is: " + myBlock);
- //Block below = BlockManager.getInstance().getBlock(_blocks.get(x, y - 1, z));
- //System.out.println("The Block below it is: " + below);
- //Block above = BlockManager.getInstance().getBlock(_blocks.get(x, y + 1, z));
- //System.out.println("The Block above it is: " + above);
- //Block left = BlockManager.getInstance().getBlock(_blocks.get(x - 1, y, z));
- //System.out.println("The Block to the left of it is: " + left);
- //Block right = BlockManager.getInstance().getBlock(_blocks.get(x + 1, y, z));
- //System.out.println("The Block to the right of it is: " + right);
- //Block front = BlockManager.getInstance().getBlock(_blocks.get(x, y, z - 1));
- //System.out.println("The Block to its front is: " + front);
- //Block back = BlockManager.getInstance().getBlock(_blocks.get(x, y, z + 1));
- //System.out.println("The Block to its back is: " + back);
- // If the below block has non-zero integrity it is supported by the world. Propagate the support upwards
- byte targetIntegrity = integrity.get(x, y - 1, z);
- if ( targetIntegrity != 0 && b != 0) {
- integrity.set(x, y, z, targetIntegrity);
- //if (x == 5 && z == 5)
- //System.out.println("Assigning integrity of " + targetIntegrity + " to 5, " + y + ", 5");
- } else {
- _blocks.set(x, y, z, (byte) 0);
- //if (x == 5 && z == 5)
- //System.out.println("Erasing block at 5, " + y + ", 5");
- }
- //myIntegrity += below.getHardness() + left.getHardness() + right.getHardness() + front.getHardness() + back.getHardness();
- }
- }
- }
- generateSunlight();
- setFresh(false);
- return true;
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement