package com.berkeren.astrotech.worldgen; import com.berkeren.astrotech.init.ModBlocks; import net.minecraft.block.state.pattern.BlockMatcher; import net.minecraft.init.Blocks; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.world.gen.IChunkGenerator; import net.minecraft.world.gen.feature.WorldGenMinable; import net.minecraft.world.gen.feature.WorldGenerator; import net.minecraftforge.fml.common.IWorldGenerator; import java.util.Random; public class OreGen implements IWorldGenerator { private WorldGenerator bauxite_ore; private WorldGenerator titanium_ore; public void WorldGenCustomOres() { //bauxite_ore_nether = new WorldGenMinable(BlockInit.COPPER_ORE_NETHER.getDefaultState(), 9, BlockMatcher.forBlock(Blocks.NETHERRACK)); bauxite_ore = new WorldGenMinable(ModBlocks.bauxite_ore.getDefaultState(), 9, BlockMatcher.forBlock(Blocks.STONE)); //bauxite_ore_end = new WorldGenMinable(BlockInit.COPPER_ORE_END.getDefaultState(), 9, BlockMatcher.forBlock(Blocks.END_STONE)); } @Override public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) { switch(world.provider.getDimension()) { case -1: //runGenerator(bauxite_ore_nether, world, random, chunkX, chunkZ, 50, 0, 100); break; case 0: runGenerator(bauxite_ore, world, random, chunkX, chunkZ, 100, 0, 100); break; case 1: //runGenerator(bauxite_ore_end, world, random, chunkX, chunkZ, 50, 0, 256); } } private void runGenerator(WorldGenerator gen, World world, Random rand, int chunkX, int chunkZ, int chance, int minHeight, int maxHeight) { if(minHeight > maxHeight || minHeight < 0 || maxHeight > 256) throw new IllegalArgumentException("Ore generated out of bounds"); int heightDiff = maxHeight - minHeight + 1; for(int i = 0; i < chance; i++) { int x = chunkX * 16 + rand.nextInt(16); int y = minHeight + rand.nextInt(heightDiff); int z = chunkZ * 16 + rand.nextInt(16); gen.generate(world, rand, new BlockPos(x,y,z)); } } }