11package  com .khorn .terraincontrol .bukkit .generator ;
22
3- import  com .google .common .base .Preconditions ;
43import  com .khorn .terraincontrol .bukkit .BukkitWorld ;
4+ import  com .khorn .terraincontrol .bukkit .TCPlugin ;
55import  com .khorn .terraincontrol .configuration .WorldConfig ;
66import  com .khorn .terraincontrol .generator .ChunkProviderTC ;
77import  com .khorn .terraincontrol .util .ChunkCoordinate ;
88import  org .bukkit .Material ;
99import  org .bukkit .World ;
10+ import  org .bukkit .generator .BlockPopulator ;
1011import  org .bukkit .generator .ChunkGenerator ;
1112
13+ import  java .util .ArrayList ;
14+ import  java .util .List ;
1215import  java .util .Random ;
1316
1417public  class  TCChunkGenerator  extends  ChunkGenerator 
1518{
1619    private  ChunkProviderTC  chunkProviderTC ;
20+     private  ArrayList <BlockPopulator > BlockPopulator  = new  ArrayList <BlockPopulator >();
1721    private  boolean  NotGenerate  = false ;
18-     private  boolean  initialized  = false ;
22+     private  TCPlugin  plugin ;
23+ 
24+     public  TCChunkGenerator (TCPlugin  _plugin )
25+     {
26+         this .plugin  = _plugin ;
27+     }
28+ 
29+     /** 
30+      * Initializes the world if it hasn't already been initialized. 
31+      *  
32+      * @param world 
33+      *            The world of this generator. 
34+      */ 
35+     private  void  makeSureWorldIsInitialized (World  world )
36+     {
37+         if  (this .chunkProviderTC  == null )
38+         {
39+             // Not yet initialized, do it now 
40+             this .plugin .onWorldInit (world );
41+         }
42+     }
1943
2044    /** 
2145     * Called whenever a BukkitWorld instance becomes available. 
@@ -25,28 +49,39 @@ public class TCChunkGenerator extends ChunkGenerator
2549     */ 
2650    public  void  onInitialize (BukkitWorld  _world )
2751    {
28-         Preconditions .checkState (!this .initialized , "Already initialized" );
29- 
3052        this .chunkProviderTC  = new  ChunkProviderTC (_world .getConfigs (), _world );
3153
3254        WorldConfig .TerrainMode  mode  = _world .getConfigs ().getWorldConfig ().ModeTerrain ;
3355
56+         if  (mode  == WorldConfig .TerrainMode .Normal  || mode  == WorldConfig .TerrainMode .OldGenerator )
57+             this .BlockPopulator .add (new  TCBlockPopulator (_world ));
58+ 
3459        if  (mode  == WorldConfig .TerrainMode .NotGenerate )
3560            this .NotGenerate  = true ;
61+     }
62+ 
63+     @ Override 
64+     public  List <BlockPopulator > getDefaultPopulators (World  world )
65+     {
66+         makeSureWorldIsInitialized (world );
3667
37-         this .initialized  =  true ;
68+         return   this .BlockPopulator ;
3869    }
3970
4071    @ Override 
4172    public  boolean  canSpawn (World  world , int  x , int  z )
4273    {
74+         makeSureWorldIsInitialized (world );
75+ 
4376        Material  material  = world .getHighestBlockAt (x , z ).getType ();
4477        return  material .isSolid ();
4578    }
4679
4780    @ Override 
4881    public  short [][] generateExtBlockSections (World  world , Random  random , int  chunkX , int  chunkZ , BiomeGrid  biomes )
4982    {
83+         makeSureWorldIsInitialized (world );
84+ 
5085        if  (this .NotGenerate )
5186            return  new  short [16 ][];
5287        ChunkCoordinate  chunkCoord  = ChunkCoordinate .fromChunkCoords (chunkX , chunkZ );
0 commit comments