[World Generation Problem] Invisible Blocks

Discussion in 'Plugin Development' started by Bench3, Sep 2, 2012.

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

    Bench3

    Hi, i'm attempting to make my first world generation plugin and I would like it to be very simple and generate a flat land. Unfortunately, its not working :p

    It is floating on on invisible blocks and generates a perimeter around them and in other seemingly random places.

    Snapshot: [​IMG]

    This is my code so far for my world generator:

    Code:
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Random;
     
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.generator.BlockPopulator;
    import org.bukkit.generator.ChunkGenerator;
     
    import com.TheBCBroz.Bench3.Houses.Main.Houses;
     
    public class FlatLandGenerator extends ChunkGenerator {
     
        Houses plugin;
     
        public FlatLandGenerator(Houses instance) {
        plugin = instance;
        }
     
        public Location getFixedSpawnLocation(World world, Random random) {
        return new Location(world, -26, 50, -127);
        }
     
        public byte[] generate(World world, Random rand, int cX, int cZ) {
        byte[] blocks = new byte[65536];
        int x, y, z;
     
        for (x = 0; x < 16; ++x) {
            for (z = 0; z < 16; ++z) {
            blocks[coordsToInt(x, 0, z)] = (byte) Material.BEDROCK.getId();
     
            for (y = 1; y < 49; ++y) {
                blocks[coordsToInt(x, y, z)] = (byte) Material.DIRT.getId();
            }
     
            blocks[coordsToInt(x, 50, z)] = (byte) Material.GRASS.getId();
            }
        }
        return blocks;
        }
     
        public List<BlockPopulator> getDefaultPopulators(World world) {
        return new ArrayList<BlockPopulator>();
        }
     
        private int coordsToInt(int x, int y, int z) {
        return (x * 16 + z) * [SIZE=13px][FONT=sans-serif][COLOR=#000000]256[/COLOR][/FONT][/SIZE] + y;
        }
    }
    I am generating this code with multiverse; the command I use is:

    /mv create flatworld normal -g Houses
    /mv tp flatworld

    Thanks in advance,
    ~Ben :D

    And also, when I fly onto the 'invisible' blocks; I don't get taken out of the flying mode.

    And also again :p:
    When I leave the randomly placed chunks of grass and dirt, it makes everything black and not lighted.

    :D

    EDITED

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  2. Offline

    tommycake50

    well im not 100% sure about world generation but i would say you would have to generate air above it.
     
  3. Offline

    MrFigg

    I have the exact same problem. Interesting thing is that the chunks are getting generated correctly, just not being sent to the client. Or getting missed by the client. If you restart the server and log in again all the chunks are sent to the client correctly and everything is fine. At least for me.

    Here's my code:
    Code:JAVA
    1. import java.util.Arrays;
    2. import java.util.List;
    3. import java.util.Random;
    4.  
    5. import org.bukkit.Location;
    6. import org.bukkit.Material;
    7. import org.bukkit.World;
    8. import org.bukkit.generator.BlockPopulator;
    9. import org.bukkit.generator.ChunkGenerator;
    10.  
    11. public class StoneChunkGenerator extends ChunkGenerator {
    12. private byte[] chunk = new byte[65536];
    13. private byte[] spawnchunk = new byte[65536];
    14.  
    15. public StoneChunkGenerator(String worldname, String uid) {
    16. byte[] layer = new byte[256];
    17. layer[0] = (byte)Material.BEDROCK.getId();
    18. Arrays.fill(layer, 1, 64, (byte)Material.STONE.getId());
    19. Arrays.fill(layer, 65, 256, (byte)Material.AIR.getId());
    20.  
    21. for(int x = 0; x < 16; x++) {
    22. for(int z = 0; z < 16; z++) {
    23. for(int y = 0; y < 256; y++) {
    24. chunk[(x*16+z)*256+y] = layer[y];
    25. }
    26. }
    27. }
    28.  
    29. spawnchunk = chunk.clone();
    30. /*for(int x = 3; x < 12; x++) {
    31. for(int z = 3; z < 12; z++) {
    32. spawnchunk[(x*16+z)*256+63] = (byte)Material.GRAVEL.getId();
    33. }
    34. }*/
    35. }
    36.  
    37. public byte[] generate(World world, Random random, int cx, int cz) {
    38. if(cx == 0 && cz == 0) return spawnchunk.clone();
    39. return chunk.clone();
    40. }
    41.  
    42. @Override
    43. public List<BlockPopulator> getDefaultPopulators(World world) {
    44. return Arrays.asList((BlockPopulator) new SpawnPlatformPopulator());
    45. }
    46.  
    47. @Override
    48. public Location getFixedSpawnLocation(World world, Random random) {
    49. if(!world.isChunkLoaded(0, 0)) {
    50. world.loadChunk(0,0);
    51. }
    52. if((world.getHighestBlockYAt(0,0)<=0) && (world.getBlockAt(0,0,0).getType()==Material.AIR)) {
    53. return new Location(world, 0, 64, 0);
    54. }
    55. return new Location(world, 0, world.getHighestBlockYAt(0,0),0);
    56. }
    57. }


    Notice I am filling in the air, so apparently that's not the problem. Thanks for any help.
     
  4. Offline

    Bench3

    EDIT: I changed the amount that the coordsToInt method * by. (now 256) Still dosent work :p

    EDIT: Now With Image! :D

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  5. Offline

    tommycake50

    aahh so thats what you meant xD
     
  6. Offline

    Bench3

    Any idea how to fix it? :rolleyes:
     
  7. Offline

    MrFigg

    Oh wow, yours is a lot worse. It actually might be the missing air for yours. Try this for your generate function:

    Code:
        public byte[] generate(World world, Random rand, int cX, int cZ) {
            byte[] blocks = new byte[65536];
            int x, y, z;
       
            for (x = 0; x < 16; ++x) {
                for (z = 0; z < 16; ++z) {
                    blocks[coordsToInt(x, 0, z)] = (byte) Material.BEDROCK.getId();
               
                    for(y = 1; y < 50; ++y) {
                        blocks[coordsToInt(x, y, z)] = (byte) Material.DIRT.getId();
                    }
               
                    blocks[coordsToInt(x, 50, z)] = (byte) Material.GRASS.getId();
               
                    for(y = 51: y < 256; ++y) {
                        blocks[coordsToInt(x, y, z)] = (byte) Material.AIR.getId();
                    }
                }
            }
            return blocks;
        }
    If that doesn't work then I have no idea.

    EDIT:
    Mine looks list this...

    When first generated:
    [​IMG]

    After server restart:
    [​IMG]
     
  8. Offline

    Bench3

    Thanks, i'll look into it and tell you what happens
     
Thread Status:
Not open for further replies.

Share This Page