2014-03-03 00:18:15 +01:00
|
|
|
package appeng.hooks;
|
|
|
|
|
|
|
|
import java.util.Random;
|
2014-03-11 05:33:55 +01:00
|
|
|
import java.util.concurrent.Future;
|
2014-03-03 00:18:15 +01:00
|
|
|
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraft.world.chunk.IChunkProvider;
|
|
|
|
import appeng.api.util.DimensionalCoord;
|
2014-03-15 07:58:21 +01:00
|
|
|
import appeng.core.AEConfig;
|
2014-03-11 05:33:55 +01:00
|
|
|
import appeng.core.AELog;
|
2014-03-03 00:18:15 +01:00
|
|
|
import appeng.core.WorldSettings;
|
|
|
|
import appeng.helpers.MeteoritePlacer;
|
|
|
|
import appeng.services.helpers.ICompassCallback;
|
|
|
|
import cpw.mods.fml.common.IWorldGenerator;
|
|
|
|
|
|
|
|
final public class MeteoriteWorldGen implements IWorldGenerator
|
|
|
|
{
|
|
|
|
|
|
|
|
class myGen implements ICompassCallback
|
|
|
|
{
|
|
|
|
|
|
|
|
double distance = 0;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void calculatedDirection(boolean hasResult, boolean spin, double radians, double dist)
|
|
|
|
{
|
|
|
|
if ( hasResult )
|
|
|
|
distance = dist;
|
|
|
|
else
|
|
|
|
distance = Double.MAX_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void generate(Random r, int chunkX, int chunkZ, World w, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
|
|
|
|
{
|
|
|
|
if ( r.nextFloat() > 0.9 )
|
|
|
|
{
|
|
|
|
int x = r.nextInt( 16 ) + (chunkX << 4);
|
|
|
|
int z = r.nextInt( 16 ) + (chunkZ << 4);
|
|
|
|
|
|
|
|
myGen obj = new myGen();
|
2014-03-11 05:33:55 +01:00
|
|
|
Future<?> future = WorldSettings.getInstance().getCompass().getCompassDirection( new DimensionalCoord( w, x, 128, z ), 70, obj );
|
2014-03-03 00:18:15 +01:00
|
|
|
|
2014-03-11 05:33:55 +01:00
|
|
|
try
|
2014-03-03 00:18:15 +01:00
|
|
|
{
|
2014-03-11 05:33:55 +01:00
|
|
|
future.get();
|
2014-03-03 00:18:15 +01:00
|
|
|
|
2014-03-15 07:58:21 +01:00
|
|
|
if ( obj.distance > AEConfig.instance.minMeteoriteDistanceSq )
|
2014-03-03 00:18:15 +01:00
|
|
|
{
|
2014-03-11 05:33:55 +01:00
|
|
|
int depth = 180 + r.nextInt( 20 );
|
|
|
|
for (int trys = 0; trys < 20; trys++)
|
|
|
|
{
|
|
|
|
MeteoritePlacer mp = new MeteoritePlacer();
|
2014-03-03 00:18:15 +01:00
|
|
|
|
2014-03-11 05:33:55 +01:00
|
|
|
if ( mp.spawnMeteorite( w, x, depth, z ) )
|
|
|
|
return;
|
2014-03-03 00:18:15 +01:00
|
|
|
|
2014-03-11 05:33:55 +01:00
|
|
|
depth -= 15;
|
|
|
|
if ( depth < 40 )
|
|
|
|
return;
|
2014-03-03 00:18:15 +01:00
|
|
|
|
2014-03-11 05:33:55 +01:00
|
|
|
}
|
2014-03-03 00:18:15 +01:00
|
|
|
}
|
2014-03-11 05:33:55 +01:00
|
|
|
|
|
|
|
}
|
2014-03-30 01:23:11 +01:00
|
|
|
catch (Throwable e)
|
2014-03-11 05:33:55 +01:00
|
|
|
{
|
|
|
|
AELog.error( e );
|
2014-03-03 00:18:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|