2015-03-07 12:51:28 +01:00
package ellpeck.actuallyadditions.gen ;
2014-11-10 16:47:04 +01:00
2015-02-17 16:15:16 +01:00
import cpw.mods.fml.common.IWorldGenerator ;
import cpw.mods.fml.common.registry.GameRegistry ;
2015-03-08 14:58:26 +01:00
import ellpeck.actuallyadditions.blocks.InitBlocks ;
import ellpeck.actuallyadditions.blocks.metalists.TheMiscBlocks ;
import ellpeck.actuallyadditions.config.ConfigValues ;
2015-03-07 12:51:28 +01:00
import ellpeck.actuallyadditions.util.Util ;
2015-02-17 16:15:16 +01:00
import net.minecraft.block.Block ;
2015-03-08 14:58:26 +01:00
import net.minecraft.init.Blocks ;
2014-11-10 16:47:04 +01:00
import net.minecraft.world.World ;
import net.minecraft.world.chunk.IChunkProvider ;
import net.minecraft.world.gen.feature.WorldGenMinable ;
2015-03-08 14:58:26 +01:00
import org.apache.logging.log4j.Level ;
2014-11-10 16:47:04 +01:00
import java.util.Random ;
2015-02-09 17:25:05 +01:00
public class OreGen implements IWorldGenerator {
2014-11-10 16:47:04 +01:00
2015-02-20 22:45:33 +01:00
@Override
2014-11-10 16:47:04 +01:00
public void generate ( Random random , int chunkX , int chunkZ , World world , IChunkProvider chunkGenerator , IChunkProvider chunkProvider ) {
2015-02-17 16:15:16 +01:00
switch ( world . provider . dimensionId ) {
2014-11-10 16:47:04 +01:00
case - 1 :
2014-11-19 18:01:44 +01:00
generateNether ( world , random , chunkX * 16 , chunkZ * 16 ) ;
2014-11-10 16:47:04 +01:00
case 0 :
2014-11-19 18:01:44 +01:00
generateSurface ( world , random , chunkX * 16 , chunkZ * 16 ) ;
2014-11-10 16:47:04 +01:00
case 1 :
2014-11-19 18:01:44 +01:00
generateEnd ( world , random , chunkX * 16 , chunkZ * 16 ) ;
2014-11-10 16:47:04 +01:00
}
}
@SuppressWarnings ( " unused " )
private void generateEnd ( World world , Random random , int x , int z ) {
}
private void generateSurface ( World world , Random random , int x , int z ) {
2015-03-08 14:58:26 +01:00
if ( ConfigValues . generateBlackQuartz ) this . addOreSpawn ( InitBlocks . blockMisc , TheMiscBlocks . ORE_QUARTZ . ordinal ( ) , Blocks . stone , world , random , x , z , this . getRandom ( ConfigValues . blackQuartzBaseAmount , ConfigValues . blackQuartzAdditionalChance , random ) , ConfigValues . blackQuartzChance , ConfigValues . blackQuartzMinHeight , ConfigValues . blackQuartzMaxHeight ) ;
2014-11-10 16:47:04 +01:00
}
@SuppressWarnings ( " unused " )
private void generateNether ( World world , Random random , int x , int z ) {
}
2015-03-08 14:58:26 +01:00
public void addOreSpawn ( Block block , int meta , Block blockIn , World world , Random random , int blockXPos , int blockZPos , int maxVeinSize , int chancesToSpawn , int minY , int maxY ) {
if ( maxY > minY ) {
int yDiff = maxY - minY ;
for ( int i = 0 ; i < chancesToSpawn ; i + + ) {
int posX = blockXPos + random . nextInt ( 16 ) ;
int posY = minY + random . nextInt ( yDiff ) ;
int posZ = blockZPos + random . nextInt ( 16 ) ;
new WorldGenMinable ( block , meta , maxVeinSize , blockIn ) . generate ( world , random , posX , posY , posZ ) ;
}
2014-11-10 16:47:04 +01:00
}
2015-03-08 14:58:26 +01:00
else Util . AA_LOGGER . log ( Level . FATAL , " Couldn't generate ' " + block . getUnlocalizedName ( ) + " ' into the world because the Min Y coordinate is bigger than the Max! This is definitely a Config Error! Check the Files! " ) ;
}
public int getRandom ( int base , int extra , Random rand ) {
return extra > 0 ? base + rand . nextInt ( extra + 1 ) : base ;
2014-11-10 16:47:04 +01:00
}
2014-12-18 19:24:06 +01:00
public static void init ( ) {
2015-02-09 17:25:05 +01:00
Util . logInfo ( " Registering World Generator... " ) ;
2014-12-18 19:24:06 +01:00
GameRegistry . registerWorldGenerator ( new OreGen ( ) , 0 ) ;
}
2014-11-10 16:47:04 +01:00
}