Advertisement
feandrad

WorldGeneratorManager class

Dec 12th, 2013
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.69 KB | None | 0 0
  1. package blacksmith.world.gen;
  2.  
  3. import java.util.Random;
  4.  
  5. import net.minecraft.block.Block;
  6. import net.minecraft.world.World;
  7. import net.minecraft.world.chunk.IChunkProvider;
  8. import net.minecraft.world.gen.feature.WorldGenMinable;
  9. import blacksmith.BlacksmithMod;
  10. import blacksmith.block.Ore;
  11. import cpw.mods.fml.common.IWorldGenerator;
  12.  
  13. public class WorldGeneratorManager implements IWorldGenerator {
  14.    
  15.     @Override
  16.     public void generate(Random random, int chunkX, int chunkZ, World world,
  17.             IChunkProvider chunkGenerator, IChunkProvider chunkProvider) {
  18.        
  19.         switch (world.provider.dimensionId) {
  20.             case -1:
  21.                 generateNether(world, random, chunkX * 16, chunkZ * 16);
  22.             case 0:
  23.                 generateOverworld(world, random, chunkX * 16, chunkZ * 16);
  24.             case 1:
  25.                 generateEnd(world, random, chunkX * 16, chunkZ * 16);
  26.         }
  27.        
  28.     }
  29.    
  30.     private void generateEnd(World world, Random random, int chunkX, int chunkZ) {
  31.         // TODO Auto-generated method stub
  32.        
  33.     }
  34.    
  35.     private void generateNether(World world, Random random, int chunkX, int chunkZ) {
  36.         // TODO Auto-generated method stub
  37.        
  38.     }
  39.    
  40.     private void generateOverworld(World world, Random random, int chunkX, int chunkZ) {
  41.        
  42.         this.addOreSpawn(BlacksmithMod.ores, 5, world, random, chunkX, chunkZ, 16, 16,
  43.                 4 + random.nextInt(3), 5, 15, 50);
  44.        
  45.     }
  46.    
  47.     public void addOreSpawn(Block block, World world, Random random, int blockXPos,
  48.             int blockZPos, int maxX, int maxZ, int maxVeinSize, int chancesToSpawn,
  49.             int minY, int maxY) {
  50.        
  51.         int maxPosY = minY + (maxY - 1);
  52.        
  53.         assert maxY > minY : "The maximum Y must be greater than the Minimum Y";
  54.         assert maxX > 0 && maxX <= 16 : "addOreSpawn: The Maximum X must be greater than 0 and less than 16";
  55.         assert minY > 0 : "addOreSpawn: The Minimum Y must be greater than 0";
  56.         assert maxY < 256 && maxY > 0 : "addOreSpawn: The Maximum Y must be less than 256 but greater than 0";
  57.         assert maxZ > 0 && maxZ <= 16 : "addOreSpawn: The Maximum Z must be greater than 0 and less than 16";
  58.        
  59.         for (int x = 0; x < chancesToSpawn; x++) {
  60.            
  61.             int posX = blockXPos + random.nextInt(maxX);
  62.             int posY = minY + random.nextInt(maxY - minY);
  63.             int posZ = blockZPos + random.nextInt(maxZ);
  64.            
  65.             (new WorldGenMinable(block.blockID, maxVeinSize)).generate(world, random,
  66.                     posX, posY, posZ);
  67.            
  68.         }
  69.        
  70.     }
  71.    
  72.     public void addOreSpawn(Block multiBlock, int subBlockId, World world, Random random,
  73.             int blockXPos, int blockZPos, int maxX, int maxZ, int maxVeinSize,
  74.             int chancesToSpawn, int minY, int maxY) {
  75.        
  76.         Block subBlock = BlacksmithMod.ores;
  77.        
  78.         addOreSpawn(subBlock, world, random, blockXPos, blockZPos, maxX, maxZ, maxVeinSize,
  79.                 chancesToSpawn, minY, maxY);
  80.        
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement