Advertisement
Guest User

Untitled

a guest
Feb 18th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. package will11690.mechanicraft.world.gen;
  2.  
  3. import java.util.Random;
  4.  
  5. import net.minecraft.util.math.BlockPos;
  6. import net.minecraft.world.World;
  7. import net.minecraft.world.chunk.IChunkProvider;
  8. import net.minecraft.world.gen.IChunkGenerator;
  9. import net.minecraft.world.gen.feature.WorldGenerator;
  10. import net.minecraftforge.fml.common.IWorldGenerator;
  11.  
  12. public class WorldGenCustomOres implements IWorldGenerator{
  13.  
  14. private WorldGenerator RUBY_ORE, SAPPHIRE_ORE, COPPER_ORE, LEAD_ORE, SILVER_ORE, TIN_ORE;
  15.  
  16. RUBY_ORE = new WorldGenMineable(ModBlock.RUBY_ORE, 3, BlockMatcher.forBlock(Blocks.STONE));
  17. SAPPHIRE_ORE = new WorldGenMineable(ModBlock.SAPPHIRE_ORE, 3, BlockMatcher.forBlock(Blocks.STONE));
  18. COPPER_ORE = new WorldGenMineable(ModBlock.COPPER_ORE, 6, BlockMatcher.forBlock(Blocks.STONE));
  19. LEAD_ORE = new WorldGenMineable(ModBlock.LEAD_ORE, 6, BlockMatcher.forBlock(Blocks.STONE));
  20. SILVER_ORE = new WorldGenMineable(ModBlock.SILVER_ORE, 6, BlockMatcher.forBlock(Blocks.STONE));
  21. TIN_ORE = new WorldGenMineable(ModBlock.TIN_ORE, 6, BlockMatcher.forBlock(Blocks.STONE));
  22.  
  23. @Override
  24. public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider){
  25.  
  26. switch(world.provider.getDimension()){
  27.  
  28. case 0:
  29.  
  30. runGenerator(RUBY_ORE, world, random, chunkX, chunkZ, 20, 0, 15);
  31. runGenerator(SAPPHIRE_ORE, world, random, chunkX, chunkZ, 20, 0, 15);
  32. runGenerator(COPPER_ORE, world, random, chunkX, chunkZ, 40, 5, 67);
  33. runGenerator(LEAD_ORE, world, random, chunkX, chunkZ, 40, 5, 67);
  34. runGenerator(SILVER_ORE, world, random, chunkX, chunkZ, 30, 5, 33);
  35. runGenerator(TIN_ORE, world, random, chunkX, chunkZ, 40, 5, 67);
  36.  
  37. break;
  38.  
  39. }
  40.  
  41. }
  42.  
  43. private void runGenerator(WorldGenerator gen, World world, Random rand, int chunkX, int chunkY, int chunkZ, int chance, int minHeight, int maxHeight) {
  44.  
  45. if(minHeight > maxHeight || minHeight < 0 || maxHeight > 256) throw new IllegalArgumentException("Ore generated out of bounds");
  46.  
  47. int heightDiff = maxHeight - minHeight + 1;
  48.  
  49. for(int i = 0; i < chance; i++){
  50.  
  51. int x = chunkX * 16 + rand.nextInt(16);
  52. int y = minHeight + rand.nextInt(heightDiff);
  53. int z = chunkZ * 16 + rand.nextInt(16);
  54.  
  55. gen.generate(world, rand, new BlockPos(x,y,z));
  56. }
  57.  
  58. }
  59.  
  60. }
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement