demdem2

worldgen

Oct 26th, 2016
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. package dem.tutorialmod.init.worldgen;
  2.  
  3. import java.util.Random;
  4.  
  5. import com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationException;
  6.  
  7. import dem.tutorialmod.init.TutorialBlocks;
  8. import net.minecraft.util.math.BlockPos;
  9. import net.minecraft.world.World;
  10. import net.minecraft.world.chunk.IChunkGenerator;
  11. import net.minecraft.world.chunk.IChunkProvider;
  12. import net.minecraft.world.gen.feature.WorldGenerator;
  13. import net.minecraftforge.fml.common.IWorldGenerator;
  14.  
  15. public class TutorialWorldGen implements IWorldGenerator
  16. {
  17. //OverWorldOres
  18. private WorldGenerator platinum_ore;
  19. private WorldGenerator tarium_ore;
  20. private WorldGenerator demium_ore;
  21. private WorldGenerator norite_ore;
  22. private WorldGenerator ollium_ore;
  23. private WorldGenerator tcb_ore;
  24. private WorldGenerator walrusite_ore;
  25. private WorldGenerator nether_diamond_ore;
  26.  
  27.  
  28.  
  29. public TutorialWorldGen()
  30. {
  31. this.platinum_ore = new TutorialWorldGenMineable(TutorialBlocks.platinum_ore.getDefaultState(), 5); //3+ works best apparently (blocks together (vein))
  32. this.tarium_ore = new TutorialWorldGenMineable(TutorialBlocks.tarium_ore.getDefaultState(), 5);
  33. this.demium_ore = new TutorialWorldGenMineable(TutorialBlocks.demium_ore.getDefaultState(), 3);
  34. this.norite_ore = new TutorialWorldGenMineable(TutorialBlocks.norite_ore.getDefaultState(), 6);
  35. this.ollium_ore = new TutorialWorldGenMineable(TutorialBlocks.ollium_ore.getDefaultState(), 4);
  36. this.tcb_ore = new TutorialWorldGenMineable(TutorialBlocks.tcb_ore.getDefaultState(), 3);
  37. this.walrusite_ore = new TutorialWorldGenMineable(TutorialBlocks.walrusite_ore.getDefaultState(), 4);
  38. this.nether_diamond_ore = new TutorialWorldGenMineable(TutorialBlocks.nether_diamond_ore.getDefaultState(), 6);
  39. }
  40.  
  41. @Override
  42. public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider)
  43. {
  44.  
  45. switch(world.provider.getDimension())
  46. {
  47. case 0: //OverWorld
  48.  
  49. this.runGenerator(this.platinum_ore, world, random, chunkX, chunkZ, 40, 0, 120);
  50. this.runGenerator(this.tarium_ore, world, random, chunkX, chunkZ, 60, 0, 256);
  51. this.runGenerator(this.demium_ore, world, random, chunkX, chunkZ, 45, 5, 40);
  52. this.runGenerator(this.norite_ore, world, random, chunkX, chunkZ, 50, 0, 120);
  53. this.runGenerator(this.ollium_ore, world, random, chunkX, chunkZ, 40, 0, 256);
  54. this.runGenerator(this.tcb_ore, world, random, chunkX, chunkZ, 35, 10, 20);
  55. this.runGenerator(this.walrusite_ore, world, random, chunkX, chunkZ, 65, 10, 256);
  56.  
  57. break;
  58.  
  59. case -1: //Nether
  60.  
  61. this.runGenerator(this.nether_diamond_ore, world, random, chunkX, chunkZ, 70, 10, 256);
  62.  
  63. break;
  64.  
  65. case 1: //EndWorld
  66.  
  67. break;
  68.  
  69. }
  70. }
  71.  
  72. private void runGenerator(WorldGenerator generator, World world, Random random, int chunkX, int chunkZ, int chanceToSpawn, int minHeight, int maxHeight)
  73. {
  74. if(minHeight < 0 || maxHeight > 256 || minHeight > maxHeight)
  75. {
  76. throw new IllegalArgumentException("Minimum or Maximum Height out of bounds");
  77. }
  78.  
  79. int heightDiff = maxHeight - minHeight +1;
  80.  
  81. for(int i = 0; i < chanceToSpawn; i++)
  82. {
  83. int x = chunkX * 16 + random.nextInt(16);
  84. int y = minHeight + random.nextInt(heightDiff);
  85. int z = chunkZ * 16 + random.nextInt(16);
  86. generator.generate(world, random, new BlockPos(x, y, z));
  87. }
  88. }
  89.  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment