jtjj222

For codename_b

Aug 17th, 2012
108
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //for codename_b
  2. public class BasicChunkGenerator extends ChunkGenerator {
  3.  
  4.     /**
  5.      *
  6.      * @param x
  7.      * X co-ordinate of the block to be set in the array
  8.      * @param y
  9.      * Y co-ordinate of the block to be set in the array
  10.      * @param z
  11.      * Z co-ordinate of the block to be set in the array
  12.      * @param chunk
  13.      * An array containing the Block id's of all the blocks in the chunk. The first offset
  14.      * is the block section number. There are 16 block sections, stacked vertically, each of which
  15.      * 16 by 16 by 16 blocks.
  16.      * @param material
  17.      * The material to set the block to.
  18.      */
  19.     void setBlock(int x, int y, int z, byte[][] chunk, Material material) {
  20.         //if the Block section the block is in hasn't been used yet, allocate it
  21.         if (chunk[y >> 4] == null)
  22.             chunk[y >> 4] = new byte[16 * 16 * 16];
  23.         if (!(y <= 256 && y >= 0 && x <= 16 && x >= 0 && z <= 16 && z >= 0))
  24.             return;
  25.         try {
  26.             chunk[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = (byte) material
  27.                     .getId();
  28.         } catch (Exception e) {
  29.             // do nothing
  30.         }
  31.     }
  32.  
  33.     @Override
  34.     /**
  35.      * @param world
  36.      * The world the chunk belongs to
  37.      * @param rand
  38.      * Don't use this, make a new random object using the world seed (world.getSeed())
  39.      * @param biome
  40.      * Use this to set/get the current biome
  41.      * @param ChunkX and ChunkZ
  42.      * The x and z co-ordinates of the current chunk.
  43.      */
  44.     public byte[][] generateBlockSections(World world, Random rand, int ChunkX,
  45.             int ChunkZ, BiomeGrid biome) {
  46.        
  47.         SimplexOctaveGenerator gen1 = new SimplexOctaveGenerator(world,8);
  48.         gen1.setScale(1/64.0); //how "scaled" the noise generator should be.
  49.        
  50.        
  51.         byte[][] chunk = new byte[world.getMaxHeight() / 16][];
  52.        
  53.         for (int x=0; x<16; x++) {
  54.             for (int z=0; z<16; z++) {
  55.                
  56.                 int realX = x + ChunkX * 16; //used so that the noise function gives us
  57.                 int realZ = z + ChunkZ * 16; //different values each chunk
  58.  
  59.                 int maxHeight = (int) (gen1.noise(realX, realZ, 0.5, 0.5) * 16 + 128);
  60.                 for (int y=64;y<maxHeight;y++) {
  61.                     double density = gen1.noise(realX,y, realZ, 0.5, 0.5);
  62.                    
  63.                     if (density >0.5) {
  64.                         setBlock(x,y,z,chunk,Material.STONE);
  65.                     }else if (density <= 0.5 && density >= 0.4) {
  66.                         setBlock(x,y,z,chunk,Material.DIRT);
  67.                     }
  68.                      
  69.                 }
  70.             }
  71.         }
  72.         return chunk;
  73.     }
  74.     /**
  75.      * Returns a list of all of the block populators (that do "little" features)
  76.      * to be called after the chunk generator
  77.      */
  78.     @Override
  79.     public List<BlockPopulator> getDefaultPopulators(World world) {
  80.         ArrayList<BlockPopulator> pops = new ArrayList<BlockPopulator>();
  81.         //Add Block populators here
  82.         return pops;
  83.     }
  84. }
RAW Paste Data