Advertisement
jtjj222

Basic flatland with biomes world generator bukkit/minecraft

Dec 15th, 2012
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.48 KB | None | 0 0
  1. package me.jtjj222.BasicTerrain;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Random;
  6.  
  7. import org.bukkit.Material;
  8. import org.bukkit.World;
  9. import org.bukkit.block.Biome;
  10. import org.bukkit.generator.*;
  11.  
  12. public class BasicChunkGenerator extends ChunkGenerator {
  13.  
  14.     void setBlock(int x, int y, int z, byte[][] chunk, Material material) {
  15.         try {
  16.             chunk[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = (byte) material
  17.                     .getId();
  18.         } catch (Exception e) {
  19.             // do nothing
  20.         }
  21.     }
  22.    
  23.     @Override
  24.     public byte[][] generateBlockSections(World world, Random rand, int chunkXlocationInWorld,
  25.             int chunkZLocationInWorld, BiomeGrid biomeGrid) {
  26.        
  27.         byte[][] chunk = new byte[world.getMaxHeight()/16][16*16*16];
  28.        
  29.         for (int inChunkX = 0; inChunkX < 16; inChunkX++) {        
  30.             for (int inChunkZ = 0; inChunkZ < 16; inChunkZ++) {
  31.                
  32.                 //in-chunk to world co-ordinates; Used for the noise generator
  33.                 int worldX = chunkXlocationInWorld * 16 + inChunkX;
  34.                 int worldZ = chunkZLocationInWorld * 16 + inChunkZ;
  35.                
  36.                 /*
  37.                  * Get the PROPOSED biome for this location.
  38.                  * If you want to control biome generation, update the biomes here using setBiome(x,z);
  39.                  *
  40.                  * These values will be sent to the client to control weather and whatnot.
  41.                  */
  42.                 Biome currentBiome = biomeGrid.getBiome(inChunkX, inChunkZ);
  43.                
  44.                 Material topBlockType = getTopBlockType(currentBiome);
  45.                
  46.                 setBlock(inChunkX, 64, inChunkZ, chunk, topBlockType);
  47.                 for (int y = 0; y < 64; y++) setBlock(inChunkX, y, inChunkZ, chunk, Material.STONE);
  48.             }          
  49.         }
  50.        
  51.         return chunk;
  52.     }
  53.    
  54.     public Material getTopBlockType(Biome b) {
  55.         Material topBlockType;
  56.  
  57.         switch (b) {
  58.         case BEACH: topBlockType = Material.SAND;
  59.             break;
  60.            
  61.         case DESERT: topBlockType = Material.SAND;
  62.             break;
  63.            
  64.         case DESERT_HILLS: topBlockType = Material.SAND;
  65.             break;
  66.            
  67.         case EXTREME_HILLS: topBlockType = Material.GRAVEL;
  68.             break;
  69.            
  70.         case FOREST: topBlockType = Material.GRASS;
  71.             break;
  72.            
  73.         case FOREST_HILLS: topBlockType = Material.GRASS;
  74.             break;
  75.            
  76.         case FROZEN_OCEAN: topBlockType = Material.ICE;
  77.             break;
  78.            
  79.         case FROZEN_RIVER: topBlockType = Material.ICE;
  80.             break;
  81.            
  82.         case HELL: topBlockType = Material.NETHERRACK;
  83.             break;
  84.            
  85.         case ICE_MOUNTAINS: topBlockType = Material.SNOW_BLOCK;
  86.             break;
  87.            
  88.         case ICE_PLAINS: topBlockType = Material.SNOW_BLOCK;
  89.             break;
  90.            
  91.         case JUNGLE: topBlockType = Material.GRASS;
  92.             break;
  93.            
  94.         case JUNGLE_HILLS: topBlockType = Material.GRASS;
  95.             break;
  96.            
  97.         case MUSHROOM_ISLAND: topBlockType = Material.MYCEL;
  98.             break;
  99.            
  100.         case MUSHROOM_SHORE: topBlockType = Material.MYCEL;
  101.             break;
  102.            
  103.         case OCEAN: topBlockType = Material.WATER;
  104.             break;
  105.            
  106.         case PLAINS: topBlockType = Material.GRASS;
  107.             break;
  108.            
  109.         case RIVER: topBlockType = Material.WATER;
  110.             break;
  111.            
  112.         case SKY: topBlockType = Material.AIR;
  113.             break;
  114.            
  115.         case SMALL_MOUNTAINS: topBlockType = Material.WATER;
  116.             break;
  117.            
  118.         case SWAMPLAND: topBlockType = Material.MYCEL;
  119.             break;
  120.            
  121.         case TAIGA: topBlockType = Material.GRASS;
  122.             break;
  123.            
  124.         case TAIGA_HILLS: topBlockType = Material.GRASS;
  125.             break;
  126.            
  127.         default: topBlockType = Material.GRASS;
  128.         }
  129.         return topBlockType;
  130.     }
  131.  
  132.    
  133.     @Override
  134.     public List<BlockPopulator> getDefaultPopulators(World world) {
  135.         ArrayList<BlockPopulator> pops = new ArrayList<BlockPopulator>();
  136.         //Add Block populators here
  137.         return pops;
  138.     }
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement