World Generator trees are kind of messed up

Discussion in 'Plugin Development' started by Skionz, Jul 17, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Skionz

    So im working on this world generator and i decided to add some custom trees (they look kind of lame) just to see if it would work and it pretty much does work except once in a while you get half a tree or random leaves. Here is a picture of what im talking about and the code.
    [​IMG]

    and heres my populator
    Code:
        public void populate(World world, Random random, Chunk chunk) {
            int x, y, z;
           
            for (x = 0; x < 16; ++x) {
                for (z = 0; z < 16; ++z) {
                    if(random.nextInt(100) < 1) {
                        for (y = 75; chunk.getBlock(x, y, z).getType() == Material.AIR || chunk.getBlock(x, y, z).getType() == Material.LEAVES; --y);
                       
                        chunk.getBlock(x, y + 1, z).setType(Material.WOOD);
                        chunk.getBlock(x, y + 2, z).setType(Material.WOOD);
                        chunk.getBlock(x, y + 3, z).setType(Material.WOOD);
                        chunk.getBlock(x, y + 4, z).setType(Material.WOOD);
                        chunk.getBlock(x, y + 5, z).setType(Material.WOOD);
                        chunk.getBlock(x, y + 6, z).setType(Material.WOOD);
                       
                        chunk.getBlock(x, y + 6, z + 1).setType(Material.LEAVES);
                        chunk.getBlock(x + 1, y + 6, z).setType(Material.LEAVES);
                        chunk.getBlock(x + 1, y + 6, z + 1).setType(Material.LEAVES);
                        chunk.getBlock(x - 1, y + 6, z - 1).setType(Material.LEAVES);
                        chunk.getBlock(x + 1, y + 6, z - 1).setType(Material.LEAVES);
                        chunk.getBlock(x - 1, y + 6, z + 1).setType(Material.LEAVES);
                        chunk.getBlock(x - 1, y + 6, z + 1).setType(Material.LEAVES);
                        chunk.getBlock(x, y + 7, z).setType(Material.LEAVES);
                        chunk.getBlock(x - 1, y + 6, z).setType(Material.LEAVES);
                        chunk.getBlock(x, y + 6, z - 1).setType(Material.LEAVES);
     
     
     
                    }
                }
            }
     
        }
     
    }
     
  2. Offline

    nickpowns

    srsly, hacked client?! D:
     
  3. Offline

    TeeePeee

    You probably get the issues occurring at chunk boundaries (ie. where chunk A ends and chunk B begins) since you're iterating through x and z but using x/z coordinates +/- 1.
     
  4. Offline

    Skionz

    nickpowns I got it to check my ore populator lol
    TeeePeee
    thats what I thought but I wasn't sure is there anyway to turn chunk coords into like world coords?
     
  5. Offline

    _LB

    What Vanilla MC does to avoid the chunk border issue is mark chunks at the very edge of generation as 'unpopulated' - that is, they have the basics (terrain/landscape) but nothing like ores, trees, or grass has been added yet. Then, once more chunks generate past the unpopulated chunks, the game goes back and populates them, adding ores, trees, grass, etc. that way there is always a neighboring chunk to add blocks to.
     
  6. Offline

    nickpowns

  7. Offline

    TeeePeee

    Multiply each coordinate value by 16 (ie. chunk coordinate 2, 2 would correspond to 32, 32). Alternatively, use the left shift operator (<<) by 4 (same as multiplying by 2^4 ie. 16 ie. same effect).

    Use
    Code:java
    1. int realX = (chunk.getX() << 4) + x;
    2. int realZ = (chunk.getZ() << 4) + z;
    3.  
    4. int y = world.getHighestBlockYAt(realX, realZ);
    5.  
    6. // Now to modify blocks...
    7. world.getBlockAt(realX, y, realZ).setTypeIdAndData(...);

    instead of
    Code:java
    1. chunk.getBlock(x, y, z).setType(...);


    World manipulation sucks :p
     
Thread Status:
Not open for further replies.

Share This Page