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>.
|
|
|
|
*/
|
|
|
|
|
2014-03-03 00:18:15 +01:00
|
|
|
package appeng.hooks;
|
|
|
|
|
2014-08-07 08:47:42 +02:00
|
|
|
import java.util.Collection;
|
2014-03-03 00:18:15 +01:00
|
|
|
import java.util.Random;
|
2014-08-07 08:47:42 +02:00
|
|
|
import java.util.concurrent.Callable;
|
2014-03-03 00:18:15 +01:00
|
|
|
|
2014-08-07 08:47:42 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2014-03-03 00:18:15 +01:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraft.world.chunk.IChunkProvider;
|
2014-12-29 21:59:05 +01:00
|
|
|
|
|
|
|
import cpw.mods.fml.common.IWorldGenerator;
|
|
|
|
|
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-03-03 00:18:15 +01:00
|
|
|
import appeng.core.WorldSettings;
|
2014-08-06 04:03:30 +02:00
|
|
|
import appeng.core.features.registries.WorldGenRegistry;
|
2014-03-03 00:18:15 +01:00
|
|
|
import appeng.helpers.MeteoritePlacer;
|
|
|
|
import appeng.services.helpers.ICompassCallback;
|
2014-08-07 08:47:42 +02:00
|
|
|
import appeng.util.Platform;
|
2014-03-03 00:18:15 +01:00
|
|
|
|
|
|
|
final public class MeteoriteWorldGen implements IWorldGenerator
|
|
|
|
{
|
|
|
|
|
2014-09-30 22:59:49 +02:00
|
|
|
static class MyGen implements ICompassCallback
|
2014-03-03 00:18:15 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
double distance = 0;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void calculatedDirection(boolean hasResult, boolean spin, double radians, double dist)
|
|
|
|
{
|
|
|
|
if ( hasResult )
|
2014-12-29 15:13:47 +01:00
|
|
|
this.distance = dist;
|
2014-03-03 00:18:15 +01:00
|
|
|
else
|
2014-12-29 15:13:47 +01:00
|
|
|
this.distance = Double.MAX_VALUE;
|
2014-03-03 00:18:15 +01:00
|
|
|
}
|
|
|
|
|
2014-09-28 00:50:06 +02:00
|
|
|
}
|
2014-03-03 00:18:15 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void generate(Random r, int chunkX, int chunkZ, World w, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
|
|
|
|
{
|
2014-09-20 22:47:08 +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?
|
2014-09-20 23:33:44 +02:00
|
|
|
if ( r.nextFloat() < AEConfig.instance.meteoriteSpawnChance )
|
2014-08-07 08:47:42 +02:00
|
|
|
{
|
|
|
|
int x = r.nextInt( 16 ) + (chunkX << 4);
|
|
|
|
int z = r.nextInt( 16 ) + (chunkZ << 4);
|
2014-03-03 00:18:15 +01:00
|
|
|
|
2014-08-07 08:47:42 +02:00
|
|
|
int depth = 180 + r.nextInt( 20 );
|
2014-09-21 02:22:07 +02:00
|
|
|
TickHandler.instance.addCallable( w, new MeteoriteSpawn( x, depth, z, w ) );
|
2014-08-07 08:47:42 +02:00
|
|
|
}
|
|
|
|
else
|
2014-09-21 02:22:07 +02:00
|
|
|
TickHandler.instance.addCallable( w, new MeteoriteSpawn( chunkX << 4, 128, chunkZ << 4, w ) );
|
2014-08-07 08:47:42 +02:00
|
|
|
}
|
2014-08-09 03:45:31 +02:00
|
|
|
else
|
|
|
|
WorldSettings.getInstance().getCompass().updateArea( w, chunkX, chunkZ );
|
2014-08-07 08:47:42 +02:00
|
|
|
}
|
2014-03-03 00:18:15 +01:00
|
|
|
|
2014-09-21 02:22:07 +02:00
|
|
|
class MeteoriteSpawn implements Callable
|
2014-08-07 08:47:42 +02:00
|
|
|
{
|
2014-03-03 00:18:15 +01:00
|
|
|
|
2014-08-07 08:47:42 +02:00
|
|
|
final int x;
|
|
|
|
final int z;
|
|
|
|
final World w;
|
2014-09-29 09:54:34 +02:00
|
|
|
final int depth;
|
2014-03-03 00:18:15 +01:00
|
|
|
|
2014-09-21 02:22:07 +02:00
|
|
|
public MeteoriteSpawn(int x, int depth, int z, World w) {
|
2014-08-07 08:47:42 +02:00
|
|
|
this.x = x;
|
|
|
|
this.z = z;
|
|
|
|
this.w = w;
|
|
|
|
this.depth = depth;
|
|
|
|
}
|
2014-03-03 00:18:15 +01:00
|
|
|
|
2014-08-07 08:47:42 +02:00
|
|
|
@Override
|
|
|
|
public Object call() throws Exception
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
int chunkX = this.x >> 4;
|
|
|
|
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!
|
2014-12-29 15:13:47 +01:00
|
|
|
for (NBTTagCompound data : MeteoriteWorldGen.this.getNearByMeteorites( this.w, chunkX, chunkZ ))
|
2014-08-07 08:47:42 +02:00
|
|
|
{
|
|
|
|
MeteoritePlacer mp = new MeteoritePlacer();
|
2014-12-29 15:13:47 +01:00
|
|
|
mp.spawnMeteorite( new MeteoritePlacer.ChunkOnly( this.w, 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
|
|
|
|
2014-09-20 23:33:21 +02:00
|
|
|
boolean isCluster = (minSqDist < 30 * 30) && Platform.getRandomFloat() < AEConfig.instance.meteoriteClusterChance;
|
2014-08-07 08:47:42 +02:00
|
|
|
|
|
|
|
if ( minSqDist > AEConfig.instance.minMeteoriteDistanceSq || isCluster )
|
2014-12-29 15:13:47 +01:00
|
|
|
MeteoriteWorldGen.this.tryMeteorite( this.w, this.depth, this.x, this.z );
|
2014-08-07 08:47:42 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
WorldSettings.getInstance().setGenerated( this.w.provider.dimensionId, chunkX, chunkZ );
|
|
|
|
WorldSettings.getInstance().getCompass().updateArea( this.w, chunkX, chunkZ );
|
2014-08-09 03:45:31 +02:00
|
|
|
|
2014-08-07 08:47:42 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-21 02:41:05 +02:00
|
|
|
private boolean tryMeteorite(World w, int depth, int x, int z)
|
2014-08-07 08:47:42 +02:00
|
|
|
{
|
2014-09-21 02:42:00 +02:00
|
|
|
for (int tries = 0; tries < 20; tries++)
|
2014-08-07 08:47:42 +02:00
|
|
|
{
|
|
|
|
MeteoritePlacer mp = new MeteoritePlacer();
|
|
|
|
|
|
|
|
if ( mp.spawnMeteorite( new MeteoritePlacer.ChunkOnly( w, x >> 4, z >> 4 ), x, depth, z ) )
|
2014-03-11 05:33:55 +01:00
|
|
|
{
|
2014-08-07 08:47:42 +02:00
|
|
|
int px = x >> 4;
|
|
|
|
int pz = z >> 4;
|
|
|
|
|
|
|
|
for (int cx = px - 6; cx < px + 6; cx++)
|
|
|
|
for (int cz = pz - 6; cz < pz + 6; cz++)
|
|
|
|
{
|
|
|
|
if ( w.getChunkProvider().chunkExists( cx, cz ) )
|
|
|
|
{
|
|
|
|
if ( px == cx && pz == cz )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ( WorldSettings.getInstance().hasGenerated( w.provider.dimensionId, cx, cz ) )
|
|
|
|
{
|
|
|
|
MeteoritePlacer mp2 = new MeteoritePlacer();
|
|
|
|
mp2.spawnMeteorite( new MeteoritePlacer.ChunkOnly( w, cx, cz ), mp.getSettings() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2014-03-03 00:18:15 +01:00
|
|
|
}
|
|
|
|
|
2014-08-07 08:47:42 +02:00
|
|
|
depth -= 15;
|
|
|
|
if ( depth < 40 )
|
|
|
|
return false;
|
2014-03-03 00:18:15 +01:00
|
|
|
}
|
2014-08-07 08:47:42 +02:00
|
|
|
|
|
|
|
return false;
|
2014-03-03 00:18:15 +01:00
|
|
|
}
|
2014-08-07 08:47:42 +02:00
|
|
|
|
2014-09-21 01:31:39 +02:00
|
|
|
private Collection<NBTTagCompound> getNearByMeteorites(World w, int chunkX, int chunkZ)
|
2014-08-07 08:47:42 +02:00
|
|
|
{
|
2014-09-21 00:31:18 +02:00
|
|
|
return WorldSettings.getInstance().getNearByMeteorites( w.provider.dimensionId, chunkX, chunkZ );
|
2014-08-07 08:47:42 +02:00
|
|
|
}
|
|
|
|
|
2014-03-03 00:18:15 +01:00
|
|
|
}
|