Applied-Energistics-2-tiler.../src/main/java/appeng/worldgen/QuartzWorldGen.java

93 lines
3.4 KiB
Java
Raw Normal View History

2014-11-14 12:02:52 +01:00
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.worldgen;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkGenerator;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.feature.WorldGenMinable;
2015-06-16 02:44:59 +02:00
import net.minecraftforge.fml.common.IWorldGenerator;
2015-12-24 02:07:03 +01:00
import appeng.api.AEApi;
import appeng.api.definitions.IBlockDefinition;
import appeng.api.definitions.IBlocks;
import appeng.api.features.IWorldGen.WorldGenType;
import appeng.core.AEConfig;
import appeng.core.features.registries.WorldGenRegistry;
public final class QuartzWorldGen implements IWorldGenerator
{
private final WorldGenMinable oreNormal;
private final WorldGenMinable oreCharged;
public QuartzWorldGen()
{
final IBlocks blocks = AEApi.instance().definitions().blocks();
final IBlockDefinition oreDefinition = blocks.quartzOre();
final IBlockDefinition chargedDefinition = blocks.quartzOreCharged();
final Block ore = oreDefinition.maybeBlock().orElse( null );
final Block charged = chargedDefinition.maybeBlock().orElse( null );
2015-06-16 02:44:59 +02:00
this.oreNormal = new WorldGenMinable( ore.getDefaultState(), AEConfig.instance.quartzOresPerCluster );
this.oreCharged = new WorldGenMinable( charged.getDefaultState(), AEConfig.instance.quartzOresPerCluster );
2014-09-28 00:50:06 +02:00
}
@Override
public void generate( final Random r, final int chunkX, final int chunkZ, final World w, final IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider )
{
int seaLevel = w.provider.getAverageGroundLevel() + 1;
if( seaLevel < 20 )
2014-08-16 03:26:16 +02:00
{
2015-09-30 14:24:40 +02:00
final int x = ( chunkX << 4 ) + 8;
final int z = ( chunkZ << 4 ) + 8;
2015-09-29 15:47:55 +02:00
seaLevel = (int) w.getHorizon();
2014-08-16 03:26:16 +02:00
}
if( this.oreNormal == null || this.oreCharged == null )
2015-04-29 02:30:53 +02:00
{
return;
2015-04-29 02:30:53 +02:00
}
2015-09-30 14:24:40 +02:00
final double oreDepthMultiplier = AEConfig.instance.quartzOresClusterAmount * seaLevel / 64;
final int scale = (int) Math.round( r.nextGaussian() * Math.sqrt( oreDepthMultiplier ) + oreDepthMultiplier );
for( int x = 0; x < ( r.nextBoolean() ? scale * 2 : scale ) / 2; ++x )
{
2015-09-30 14:24:40 +02:00
final boolean isCharged = r.nextFloat() > AEConfig.instance.spawnChargedChance;
final WorldGenMinable whichOre = isCharged ? this.oreCharged : this.oreNormal;
2016-09-17 15:02:51 +02:00
if( WorldGenRegistry.INSTANCE.isWorldGenEnabled( isCharged ? WorldGenType.CHARGED_CERTUS_QUARTZ : WorldGenType.CERTUS_QUARTZ, w ) )
{
2015-09-30 14:24:40 +02:00
final int cx = chunkX * 16 + r.nextInt( 22 );
final int cy = r.nextInt( 40 * seaLevel / 64 ) + r.nextInt( 22 * seaLevel / 64 ) + 12 * seaLevel / 64;
final int cz = chunkZ * 16 + r.nextInt( 22 );
2015-06-16 02:44:59 +02:00
whichOre.generate( w, r, new BlockPos( cx, cy, cz ) );
}
}
}
}