2014-11-14 12:02:52 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Applied Energistics 2.
|
2015-05-28 20:01:21 +02:00
|
|
|
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
|
2014-11-14 12:02:52 +01:00
|
|
|
*
|
|
|
|
* 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>.
|
|
|
|
*/
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
package appeng.worldgen;
|
|
|
|
|
2014-03-03 00:18:15 +01:00
|
|
|
|
2014-08-06 04:03:30 +02:00
|
|
|
import appeng.api.features.IWorldGen.WorldGenType;
|
2014-03-15 07:58:21 +01:00
|
|
|
import appeng.core.AEConfig;
|
2014-08-06 04:03:30 +02:00
|
|
|
import appeng.core.features.registries.WorldGenRegistry;
|
2015-05-28 20:01:21 +02:00
|
|
|
import appeng.core.worlddata.WorldData;
|
2015-01-03 02:53:14 +01:00
|
|
|
import appeng.hooks.TickHandler;
|
2015-08-06 23:30:26 +02:00
|
|
|
import appeng.util.IWorldCallable;
|
2014-08-07 08:47:42 +02:00
|
|
|
import appeng.util.Platform;
|
2015-01-03 02:53:14 +01:00
|
|
|
import appeng.worldgen.meteorite.ChunkOnly;
|
2017-04-12 16:10:13 +02:00
|
|
|
import cpw.mods.fml.common.IWorldGenerator;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraft.world.chunk.IChunkProvider;
|
|
|
|
|
|
|
|
import java.util.Random;
|
2014-03-03 00:18:15 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2015-04-06 00:35:42 +02:00
|
|
|
public final class MeteoriteWorldGen implements IWorldGenerator
|
2014-03-03 00:18:15 +01:00
|
|
|
{
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public void generate( final Random r, final int chunkX, final int chunkZ, final World w, final IChunkProvider chunkGenerator, final IChunkProvider chunkProvider )
|
2014-03-03 00:18:15 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( WorldGenRegistry.INSTANCE.isWorldGenEnabled( WorldGenType.Meteorites, w ) )
|
2014-03-03 00:18:15 +01:00
|
|
|
{
|
2014-09-21 02:41:05 +02:00
|
|
|
// add new meteorites?
|
2015-04-03 08:54:31 +02:00
|
|
|
if( r.nextFloat() < AEConfig.instance.meteoriteSpawnChance )
|
2014-08-07 08:47:42 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final int x = r.nextInt( 16 ) + ( chunkX << 4 );
|
|
|
|
final int z = r.nextInt( 16 ) + ( chunkZ << 4 );
|
2014-03-03 00:18:15 +01:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final int depth = 180 + r.nextInt( 20 );
|
2015-08-06 23:30:26 +02:00
|
|
|
TickHandler.INSTANCE.addCallable( w, new MeteoriteSpawn( x, depth, z ) );
|
2014-08-07 08:47:42 +02:00
|
|
|
}
|
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-08-06 23:30:26 +02:00
|
|
|
TickHandler.INSTANCE.addCallable( w, new MeteoriteSpawn( chunkX << 4, 128, chunkZ << 4 ) );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-08-07 08:47:42 +02:00
|
|
|
}
|
2014-08-09 03:45:31 +02:00
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-05-28 20:01:21 +02:00
|
|
|
WorldData.instance().compassData().service().updateArea( w, chunkX, chunkZ );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-08-07 08:47:42 +02:00
|
|
|
}
|
2014-03-03 00:18:15 +01:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
private boolean tryMeteorite( final World w, int depth, final int x, final int z )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
|
|
|
for( int tries = 0; tries < 20; tries++ )
|
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final MeteoritePlacer mp = new MeteoritePlacer();
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
if( mp.spawnMeteorite( new ChunkOnly( w, x >> 4, z >> 4 ), x, depth, z ) )
|
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final int px = x >> 4;
|
|
|
|
final int pz = z >> 4;
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
for( int cx = px - 6; cx < px + 6; cx++ )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int cz = pz - 6; cz < pz + 6; cz++ )
|
|
|
|
{
|
|
|
|
if( w.getChunkProvider().chunkExists( cx, cz ) )
|
|
|
|
{
|
|
|
|
if( px == cx && pz == cz )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
continue;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2015-05-28 20:01:21 +02:00
|
|
|
if( WorldData.instance().spawnData().hasGenerated( w.provider.dimensionId, cx, cz ) )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final MeteoritePlacer mp2 = new MeteoritePlacer();
|
2015-04-03 08:54:31 +02:00
|
|
|
mp2.spawnMeteorite( new ChunkOnly( w, cx, cz ), mp.getSettings() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
depth -= 15;
|
|
|
|
if( depth < 40 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return false;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
private Iterable<NBTTagCompound> getNearByMeteorites( final World w, final int chunkX, final int chunkZ )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
2015-05-28 20:01:21 +02:00
|
|
|
return WorldData.instance().spawnData().getNearByMeteorites( w.provider.dimensionId, chunkX, chunkZ );
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
private class MeteoriteSpawn implements IWorldCallable<Object>
|
2014-08-07 08:47:42 +02:00
|
|
|
{
|
2014-03-03 00:18:15 +01:00
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
private final int x;
|
|
|
|
private final int z;
|
|
|
|
private final int depth;
|
2014-03-03 00:18:15 +01:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
public MeteoriteSpawn( final int x, final int depth, final int z )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
2014-08-07 08:47:42 +02:00
|
|
|
this.x = x;
|
|
|
|
this.z = z;
|
|
|
|
this.depth = depth;
|
|
|
|
}
|
2014-03-03 00:18:15 +01:00
|
|
|
|
2014-08-07 08:47:42 +02:00
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public Object call( final World world ) throws Exception
|
2014-08-07 08:47:42 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final int chunkX = this.x >> 4;
|
|
|
|
final int chunkZ = this.z >> 4;
|
2014-03-03 00:18:15 +01:00
|
|
|
|
2014-08-07 08:47:42 +02:00
|
|
|
double minSqDist = Double.MAX_VALUE;
|
2014-03-11 05:33:55 +01:00
|
|
|
|
2014-08-07 08:47:42 +02:00
|
|
|
// near by meteorites!
|
2015-09-25 23:10:56 +02:00
|
|
|
for( final NBTTagCompound data : MeteoriteWorldGen.this.getNearByMeteorites( world, chunkX, chunkZ ) )
|
2014-08-07 08:47:42 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final MeteoritePlacer mp = new MeteoritePlacer();
|
2015-08-06 23:30:26 +02:00
|
|
|
mp.spawnMeteorite( new ChunkOnly( world, chunkX, chunkZ ), data );
|
2014-08-07 08:47:42 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
minSqDist = Math.min( minSqDist, mp.getSqDistance( this.x, this.z ) );
|
2014-03-11 05:33:55 +01:00
|
|
|
}
|
2014-08-07 08:47:42 +02:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final boolean isCluster = ( minSqDist < 30 * 30 ) && Platform.getRandomFloat() < AEConfig.instance.meteoriteClusterChance;
|
2014-08-07 08:47:42 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( minSqDist > AEConfig.instance.minMeteoriteDistanceSq || isCluster )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-08-06 23:30:26 +02:00
|
|
|
MeteoriteWorldGen.this.tryMeteorite( world, this.depth, this.x, this.z );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-08-07 08:47:42 +02:00
|
|
|
|
2015-08-06 23:30:26 +02:00
|
|
|
WorldData.instance().spawnData().setGenerated( world.provider.dimensionId, chunkX, chunkZ );
|
|
|
|
WorldData.instance().compassData().service().updateArea( world, chunkX, chunkZ );
|
2014-08-09 03:45:31 +02:00
|
|
|
|
2014-08-07 08:47:42 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2014-03-03 00:18:15 +01:00
|
|
|
}
|