Camellias_

WorldGenCustomOres

Apr 12th, 2018
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.60 KB | None | 0 0
  1. package com.camellias.blight.world.gen;
  2.  
  3. import java.util.Random;
  4.  
  5. import com.camellias.blight.init.ModBlocks;
  6.  
  7. import net.minecraft.block.state.pattern.BlockMatcher;
  8. import net.minecraft.init.Blocks;
  9. import net.minecraft.util.math.BlockPos;
  10. import net.minecraft.world.World;
  11. import net.minecraft.world.chunk.IChunkProvider;
  12. import net.minecraft.world.gen.IChunkGenerator;
  13. import net.minecraft.world.gen.feature.WorldGenMinable;
  14. import net.minecraft.world.gen.feature.WorldGenerator;
  15. import net.minecraftforge.fml.common.IWorldGenerator;
  16.  
  17. public class WorldGenCustomOres implements IWorldGenerator
  18. {
  19.     private WorldGenerator blighted_dirt;
  20.    
  21.     public WorldGenCustomOres()
  22.     {
  23.         blighted_dirt = new WorldGenMinable(ModBlocks.BLIGHTEDDIRT.getDefaultState(), 1, BlockMatcher.forBlock(Blocks.DIRT));
  24.     }
  25.    
  26.     @Override
  27.     public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider)
  28.     {
  29.         runGenerator(blighted_dirt, world, random, chunkX, chunkZ, 1, 0, 128);
  30.     }
  31.    
  32.     private void runGenerator(WorldGenerator gen, World world, Random random, int chunkX, int chunkZ, int chance, int minHeight, int maxHeight)
  33.     {
  34.         if(minHeight > maxHeight || minHeight > 0 || maxHeight > 256) throw new IllegalArgumentException("Generated out of bounds");
  35.        
  36.         int heightDiff = maxHeight - minHeight + 1;
  37.         for(int i = 0; i < chance; i++)
  38.         {
  39.             int x = chunkX * 16 + random.nextInt(16);
  40.             int y = minHeight + random.nextInt(heightDiff);
  41.             int z = chunkZ * 16 + random.nextInt(16);
  42.            
  43.             gen.generate(world, random, new BlockPos(x, y, z));
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment