2015-08-29 14:33:25 +02:00
/ *
2016-05-16 22:52:27 +02:00
* This file ( " OreGen.java " ) is part of the Actually Additions mod for Minecraft .
2015-08-29 14:33:25 +02:00
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
2016-05-16 22:52:27 +02:00
* http : //ellpeck.de/actaddlicense
2015-08-29 14:33:25 +02:00
* View the source code at https : //github.com/Ellpeck/ActuallyAdditions
*
2016-05-16 22:54:42 +02:00
* © 2015 - 2016 Ellpeck
2015-08-29 14:33:25 +02:00
* /
2016-01-05 04:47:35 +01:00
package de.ellpeck.actuallyadditions.mod.gen ;
2014-11-10 16:47:04 +01:00
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks ;
import de.ellpeck.actuallyadditions.mod.blocks.metalists.TheMiscBlocks ;
import de.ellpeck.actuallyadditions.mod.config.ConfigValues ;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues ;
2016-05-18 19:34:57 +02:00
import de.ellpeck.actuallyadditions.mod.gen.cave.CaveWorldType ;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.util.ModUtil ;
import de.ellpeck.actuallyadditions.mod.util.Util ;
2015-02-17 16:15:16 +01:00
import net.minecraft.block.Block ;
2016-03-18 23:47:22 +01:00
import net.minecraft.block.state.pattern.BlockMatcher ;
2015-03-08 14:58:26 +01:00
import net.minecraft.init.Blocks ;
2016-03-18 23:47:22 +01:00
import net.minecraft.util.math.BlockPos ;
import net.minecraft.util.math.MathHelper ;
2014-11-10 16:47:04 +01:00
import net.minecraft.world.World ;
2015-08-02 06:55:32 +02:00
import net.minecraft.world.WorldType ;
2016-03-18 23:47:22 +01:00
import net.minecraft.world.chunk.IChunkGenerator ;
2014-11-10 16:47:04 +01:00
import net.minecraft.world.chunk.IChunkProvider ;
import net.minecraft.world.gen.feature.WorldGenMinable ;
2016-01-07 18:20:59 +01:00
import net.minecraftforge.fml.common.IWorldGenerator ;
import net.minecraftforge.fml.common.registry.GameRegistry ;
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-11-28 19:02:01 +01:00
public static final int QUARTZ_MIN = 0 ;
public static final int QUARTZ_MAX = 45 ;
2015-10-03 10:16:18 +02:00
public static void init ( ) {
ModUtil . LOGGER . info ( " Registering World Generator... " ) ;
GameRegistry . registerWorldGenerator ( new OreGen ( ) , 10 ) ;
}
2015-02-20 22:45:33 +01:00
@Override
2016-03-18 23:47:22 +01:00
public void generate ( Random random , int chunkX , int chunkZ , World world , IChunkGenerator chunkGenerator , IChunkProvider chunkProvider ) {
2016-05-18 19:34:57 +02:00
int dimension = world . provider . getDimension ( ) ;
if ( dimension ! = - 1 & & dimension ! = 1 ) {
if ( CaveWorldType . isCave ( world ) ) {
this . generateCave ( world , random , chunkX * 16 , chunkZ * 16 ) ;
}
else if ( world . getWorldType ( ) ! = WorldType . FLAT & & Util . arrayContains ( ConfigValues . oreGenDimensionBlacklist , world . provider . getDimension ( ) ) < 0 ) {
this . generateDefault ( world , random , chunkX * 16 , chunkZ * 16 ) ;
2015-11-20 20:52:03 +01:00
}
2014-11-10 16:47:04 +01:00
}
}
2016-05-18 19:34:57 +02:00
private void generateCave ( World world , Random random , int x , int z ) {
this . addOreSpawn ( InitBlocks . blockImpureIron , 0 , Blocks . STONE , world , random , x , z , MathHelper . getRandomIntegerInRange ( random , 5 , 10 ) , 60 , 0 , world . getHeight ( ) ) ;
2014-11-10 16:47:04 +01:00
}
2016-05-18 19:34:57 +02:00
private void generateDefault ( World world , Random random , int x , int z ) {
2015-12-20 23:38:24 +01:00
if ( ConfigBoolValues . GENERATE_QUARTZ . isEnabled ( ) ) {
2016-04-20 21:39:03 +02:00
this . addOreSpawn ( InitBlocks . blockMisc , TheMiscBlocks . ORE_QUARTZ . ordinal ( ) , Blocks . STONE , world , random , x , z , MathHelper . getRandomIntegerInRange ( random , 5 , 8 ) , 10 , QUARTZ_MIN , QUARTZ_MAX ) ;
2015-06-28 12:42:38 +02:00
}
2014-11-10 16:47:04 +01:00
}
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 ) {
2015-10-02 16:48:01 +02:00
int yDiff = maxY - minY ;
2015-03-08 14:58:26 +01:00
for ( int i = 0 ; i < chancesToSpawn ; i + + ) {
2015-10-02 16:48:01 +02:00
int posX = blockXPos + random . nextInt ( 16 ) ;
int posY = minY + random . nextInt ( yDiff ) ;
int posZ = blockZPos + random . nextInt ( 16 ) ;
2016-03-18 23:47:22 +01:00
new WorldGenMinable ( block . getStateFromMeta ( meta ) , maxVeinSize , BlockMatcher . forBlock ( blockIn ) ) . generate ( world , random , new BlockPos ( posX , posY , posZ ) ) ;
2015-03-08 14:58:26 +01:00
}
2014-11-10 16:47:04 +01:00
}
2015-10-02 16:48:01 +02:00
else {
ModUtil . LOGGER . 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! " ) ;
}
2015-03-08 14:58:26 +01:00
}
2014-11-10 16:47:04 +01:00
}