2014-03-02 09:35:11 +01:00
|
|
|
package appeng.helpers;
|
|
|
|
|
|
|
|
import java.util.HashSet;
|
2014-04-28 06:49:14 +02:00
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
2014-03-02 09:35:11 +01:00
|
|
|
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.item.EntityItem;
|
|
|
|
import net.minecraft.init.Blocks;
|
2014-03-05 04:29:03 +01:00
|
|
|
import net.minecraft.inventory.IInventory;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2014-08-07 08:47:42 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2014-03-05 04:29:03 +01:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2014-03-02 09:35:11 +01:00
|
|
|
import net.minecraft.util.AxisAlignedBB;
|
|
|
|
import net.minecraft.world.World;
|
2014-08-07 08:47:42 +02:00
|
|
|
import net.minecraft.world.chunk.Chunk;
|
2014-03-09 00:31:09 +01:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2014-04-28 06:49:14 +02:00
|
|
|
import net.minecraftforge.oredict.OreDictionary;
|
2014-03-02 09:35:11 +01:00
|
|
|
import appeng.api.AEApi;
|
2014-08-24 08:50:22 +02:00
|
|
|
import appeng.core.AEConfig;
|
2014-05-16 04:18:30 +02:00
|
|
|
import appeng.core.WorldSettings;
|
2014-08-24 08:50:22 +02:00
|
|
|
import appeng.core.features.AEFeature;
|
2014-03-09 00:31:09 +01:00
|
|
|
import appeng.util.InventoryAdaptor;
|
2014-03-02 09:35:11 +01:00
|
|
|
import appeng.util.Platform;
|
|
|
|
|
|
|
|
public class MeteoritePlacer
|
|
|
|
{
|
|
|
|
|
|
|
|
private class Fallout
|
|
|
|
{
|
|
|
|
|
|
|
|
public int adjustCrator()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-08-07 08:47:42 +02:00
|
|
|
public void getRandomFall(IMetroiteWorld w, int x, int y, int z)
|
2014-03-02 09:35:11 +01:00
|
|
|
{
|
|
|
|
double a = Math.random();
|
|
|
|
if ( a > 0.9 )
|
|
|
|
put( w, x, y, z, Blocks.stone );
|
|
|
|
else if ( a > 0.8 )
|
|
|
|
put( w, x, y, z, Blocks.cobblestone );
|
|
|
|
else if ( a > 0.7 )
|
|
|
|
put( w, x, y, z, Blocks.dirt );
|
|
|
|
else if ( a > 0.7 )
|
|
|
|
put( w, x, y, z, Blocks.gravel );
|
|
|
|
}
|
|
|
|
|
2014-08-07 08:47:42 +02:00
|
|
|
public void getRandomInset(IMetroiteWorld w, int x, int y, int z)
|
2014-03-02 09:35:11 +01:00
|
|
|
{
|
|
|
|
double a = Math.random();
|
|
|
|
if ( a > 0.9 )
|
|
|
|
put( w, x, y, z, Blocks.cobblestone );
|
|
|
|
else if ( a > 0.8 )
|
|
|
|
put( w, x, y, z, Blocks.stone );
|
|
|
|
else if ( a > 0.7 )
|
2014-03-03 00:18:15 +01:00
|
|
|
put( w, x, y, z, Blocks.grass );
|
2014-03-02 09:35:11 +01:00
|
|
|
else if ( a > 0.6 )
|
|
|
|
put( w, x, y, z, skystone );
|
|
|
|
else if ( a > 0.5 )
|
|
|
|
put( w, x, y, z, Blocks.gravel );
|
|
|
|
else if ( a > 0.5 )
|
|
|
|
put( w, x, y, z, Platform.air );
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
private class FalloutCopy extends Fallout
|
|
|
|
{
|
|
|
|
|
|
|
|
Block blk;
|
|
|
|
int meta;
|
|
|
|
|
2014-08-07 08:47:42 +02:00
|
|
|
public FalloutCopy(IMetroiteWorld w, int x, int y, int z) {
|
2014-03-02 09:35:11 +01:00
|
|
|
blk = w.getBlock( x, y, z );
|
|
|
|
meta = w.getBlockMetadata( x, y, z );
|
|
|
|
}
|
|
|
|
|
2014-08-07 08:47:42 +02:00
|
|
|
public void getOther(IMetroiteWorld w, int x, int y, int z, double a)
|
2014-03-02 09:35:11 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-08-07 08:47:42 +02:00
|
|
|
public void getRandomFall(IMetroiteWorld w, int x, int y, int z)
|
2014-03-02 09:35:11 +01:00
|
|
|
{
|
|
|
|
double a = Math.random();
|
|
|
|
if ( a > 0.9 )
|
|
|
|
put( w, x, y, z, blk, meta );
|
|
|
|
else
|
|
|
|
getOther( w, x, y, z, a );
|
|
|
|
}
|
|
|
|
|
2014-08-07 08:47:42 +02:00
|
|
|
public void getRandomInset(IMetroiteWorld w, int x, int y, int z)
|
2014-03-02 09:35:11 +01:00
|
|
|
{
|
|
|
|
double a = Math.random();
|
|
|
|
if ( a > 0.9 )
|
|
|
|
put( w, x, y, z, blk, meta );
|
|
|
|
else if ( a > 0.8 )
|
|
|
|
put( w, x, y, z, Platform.air );
|
|
|
|
else
|
|
|
|
getOther( w, x, y, z, a - 0.1 );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
private class FalloutSand extends FalloutCopy
|
|
|
|
{
|
|
|
|
|
2014-08-07 08:47:42 +02:00
|
|
|
public FalloutSand(IMetroiteWorld w, int x, int y, int z) {
|
2014-03-02 09:35:11 +01:00
|
|
|
super( w, x, y, z );
|
|
|
|
}
|
|
|
|
|
|
|
|
public int adjustCrator()
|
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2014-08-07 08:47:42 +02:00
|
|
|
public void getOther(IMetroiteWorld w, int x, int y, int z, double a)
|
2014-03-02 09:35:11 +01:00
|
|
|
{
|
2014-03-03 00:18:15 +01:00
|
|
|
if ( a > 0.66 )
|
2014-03-02 09:35:11 +01:00
|
|
|
put( w, x, y, z, Blocks.glass );
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2014-03-04 05:56:08 +01:00
|
|
|
private class FalloutSnow extends FalloutCopy
|
|
|
|
{
|
|
|
|
|
2014-08-07 08:47:42 +02:00
|
|
|
public FalloutSnow(IMetroiteWorld w, int x, int y, int z) {
|
2014-03-04 05:56:08 +01:00
|
|
|
super( w, x, y, z );
|
|
|
|
}
|
|
|
|
|
|
|
|
public int adjustCrator()
|
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2014-08-07 08:47:42 +02:00
|
|
|
public void getOther(IMetroiteWorld w, int x, int y, int z, double a)
|
2014-03-04 05:56:08 +01:00
|
|
|
{
|
|
|
|
if ( a > 0.7 )
|
|
|
|
put( w, x, y, z, Blocks.snow );
|
|
|
|
else if ( a > 0.5 )
|
|
|
|
put( w, x, y, z, Blocks.ice );
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2014-08-07 08:47:42 +02:00
|
|
|
public interface IMetroiteWorld
|
|
|
|
{
|
|
|
|
|
|
|
|
int minX(int in);
|
|
|
|
|
|
|
|
int minZ(int in);
|
|
|
|
|
|
|
|
int maxX(int in);
|
|
|
|
|
|
|
|
int maxZ(int in);
|
|
|
|
|
|
|
|
boolean hasNoSky();
|
|
|
|
|
|
|
|
int getBlockMetadata(int x, int y, int z);
|
|
|
|
|
|
|
|
Block getBlock(int x, int y, int z);
|
|
|
|
|
|
|
|
boolean canBlockSeeTheSky(int i, int j, int k);
|
|
|
|
|
|
|
|
TileEntity getTileEntity(int x, int y, int z);
|
|
|
|
|
|
|
|
World getWorld();
|
|
|
|
|
|
|
|
void setBlock(int i, int j, int k, Block blk);
|
|
|
|
|
|
|
|
void setBlock(int i, int j, int k, Block blk_b, int meta_b, int l);
|
|
|
|
|
|
|
|
void done();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
static public class StandardWorld implements IMetroiteWorld
|
|
|
|
{
|
|
|
|
|
|
|
|
protected World w;
|
|
|
|
|
|
|
|
public StandardWorld(World w) {
|
|
|
|
this.w = w;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasNoSky()
|
|
|
|
{
|
|
|
|
return !w.provider.hasNoSky;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getBlockMetadata(int x, int y, int z)
|
|
|
|
{
|
|
|
|
if ( range( x, y, z ) )
|
|
|
|
return w.getBlockMetadata( x, y, z );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Block getBlock(int x, int y, int z)
|
|
|
|
{
|
|
|
|
if ( range( x, y, z ) )
|
|
|
|
return w.getBlock( x, y, z );
|
|
|
|
return Platform.air;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canBlockSeeTheSky(int x, int y, int z)
|
|
|
|
{
|
|
|
|
if ( range( x, y, z ) )
|
|
|
|
return w.canBlockSeeTheSky( x, y, z );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public TileEntity getTileEntity(int x, int y, int z)
|
|
|
|
{
|
|
|
|
if ( range( x, y, z ) )
|
|
|
|
return w.getTileEntity( x, y, z );
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public World getWorld()
|
|
|
|
{
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setBlock(int x, int y, int z, Block blk)
|
|
|
|
{
|
|
|
|
if ( range( x, y, z ) )
|
|
|
|
w.setBlock( x, y, z, blk );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setBlock(int x, int y, int z, Block blk, int metadata, int flags)
|
|
|
|
{
|
|
|
|
if ( range( x, y, z ) )
|
|
|
|
w.setBlock( x, y, z, blk, metadata, flags );
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean range(int x, int y, int z)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int minX(int in)
|
|
|
|
{
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int minZ(int in)
|
|
|
|
{
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int maxX(int in)
|
|
|
|
{
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int maxZ(int in)
|
|
|
|
{
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void done()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static public class ChunkOnly extends StandardWorld
|
|
|
|
{
|
|
|
|
|
|
|
|
Chunk target;
|
|
|
|
|
|
|
|
int verticalBits = 0;
|
|
|
|
|
|
|
|
final int cx, cz;
|
|
|
|
|
|
|
|
public ChunkOnly(World w, int cx, int cz) {
|
|
|
|
super( w );
|
|
|
|
target = w.getChunkFromChunkCoords( cx, cz );
|
|
|
|
this.cx = cx;
|
|
|
|
this.cz = cz;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void done()
|
|
|
|
{
|
|
|
|
if ( verticalBits != 0 )
|
|
|
|
Platform.sendChunk( target, verticalBits );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setBlock(int x, int y, int z, Block blk)
|
|
|
|
{
|
|
|
|
if ( range( x, y, z ) )
|
|
|
|
{
|
|
|
|
verticalBits |= 1 << (y >> 4);
|
|
|
|
w.setBlock( x, y, z, blk, 0, 1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setBlock(int x, int y, int z, Block blk, int metadata, int flags)
|
|
|
|
{
|
|
|
|
if ( range( x, y, z ) )
|
|
|
|
{
|
|
|
|
verticalBits |= 1 << (y >> 4);
|
|
|
|
w.setBlock( x, y, z, blk, metadata, flags & (~2) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Block getBlock(int x, int y, int z)
|
|
|
|
{
|
|
|
|
if ( range( x, y, z ) )
|
|
|
|
return target.getBlock( x & 0xF, y, z & 0xF );
|
|
|
|
return Platform.air;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getBlockMetadata(int x, int y, int z)
|
|
|
|
{
|
|
|
|
if ( range( x, y, z ) )
|
|
|
|
return target.getBlockMetadata( x & 0xF, y, z & 0xF );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean range(int x, int y, int z)
|
|
|
|
{
|
|
|
|
return cx == (x >> 4) && cz == (z >> 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int minX(int in)
|
|
|
|
{
|
|
|
|
return Math.max( in, cx << 4 );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int minZ(int in)
|
|
|
|
{
|
|
|
|
return Math.max( in, cz << 4 );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int maxX(int in)
|
|
|
|
{
|
|
|
|
return Math.min( in, (cx + 1) << 4 );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int maxZ(int in)
|
|
|
|
{
|
|
|
|
return Math.min( in, (cz + 1) << 4 );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-03-02 09:35:11 +01:00
|
|
|
int minBLocks = 200;
|
|
|
|
HashSet<Block> validSpawn = new HashSet();
|
|
|
|
HashSet<Block> invalidSpawn = new HashSet();
|
|
|
|
|
|
|
|
Fallout type = new Fallout();
|
|
|
|
|
|
|
|
Block skystone = AEApi.instance().blocks().blockSkyStone.block();
|
2014-03-09 00:31:09 +01:00
|
|
|
Block skychest;
|
2014-03-02 09:35:11 +01:00
|
|
|
|
|
|
|
double real_sizeOfMetorite = (Math.random() * 6.0) + 2;
|
|
|
|
double real_crator = real_sizeOfMetorite * 2 + 5;
|
|
|
|
|
|
|
|
double sizeOfMetorite = real_sizeOfMetorite * real_sizeOfMetorite;
|
|
|
|
double crator = real_crator * real_crator;
|
|
|
|
|
|
|
|
public MeteoritePlacer() {
|
|
|
|
|
2014-03-09 00:31:09 +01:00
|
|
|
if ( AEApi.instance().blocks().blockSkyChest.block() == null )
|
|
|
|
skychest = Blocks.chest;
|
|
|
|
else
|
|
|
|
skychest = AEApi.instance().blocks().blockSkyChest.block();
|
|
|
|
|
2014-03-02 09:35:11 +01:00
|
|
|
validSpawn.add( Blocks.stone );
|
|
|
|
validSpawn.add( Blocks.cobblestone );
|
|
|
|
validSpawn.add( Blocks.grass );
|
|
|
|
validSpawn.add( Blocks.sand );
|
|
|
|
validSpawn.add( Blocks.dirt );
|
|
|
|
validSpawn.add( Blocks.gravel );
|
|
|
|
validSpawn.add( Blocks.netherrack );
|
|
|
|
validSpawn.add( Blocks.iron_ore );
|
|
|
|
validSpawn.add( Blocks.gold_ore );
|
|
|
|
validSpawn.add( Blocks.diamond_ore );
|
|
|
|
validSpawn.add( Blocks.redstone_ore );
|
|
|
|
validSpawn.add( Blocks.hardened_clay );
|
2014-03-04 05:56:08 +01:00
|
|
|
validSpawn.add( Blocks.ice );
|
|
|
|
validSpawn.add( Blocks.snow );
|
2014-03-02 09:35:11 +01:00
|
|
|
|
|
|
|
invalidSpawn.add( skystone );
|
|
|
|
invalidSpawn.add( Blocks.planks );
|
|
|
|
invalidSpawn.add( Blocks.iron_door );
|
|
|
|
invalidSpawn.add( Blocks.iron_bars );
|
|
|
|
invalidSpawn.add( Blocks.wooden_door );
|
|
|
|
invalidSpawn.add( Blocks.brick_block );
|
|
|
|
invalidSpawn.add( Blocks.clay );
|
|
|
|
invalidSpawn.add( Blocks.water );
|
|
|
|
invalidSpawn.add( Blocks.log );
|
|
|
|
invalidSpawn.add( Blocks.log2 );
|
|
|
|
}
|
|
|
|
|
2014-08-07 08:47:42 +02:00
|
|
|
NBTTagCompound settings;
|
|
|
|
|
|
|
|
public boolean spawnMeteorite(IMetroiteWorld w, NBTTagCompound metoriteBlob)
|
|
|
|
{
|
|
|
|
settings = metoriteBlob;
|
|
|
|
|
|
|
|
int x = settings.getInteger( "x" );
|
|
|
|
int y = settings.getInteger( "y" );
|
|
|
|
int z = settings.getInteger( "z" );
|
|
|
|
|
|
|
|
real_sizeOfMetorite = settings.getDouble( "real_sizeOfMetorite" );
|
|
|
|
real_crator = settings.getDouble( "real_crator" );
|
|
|
|
sizeOfMetorite = settings.getDouble( "sizeOfMetorite" );
|
|
|
|
crator = settings.getDouble( "crator" );
|
|
|
|
|
|
|
|
Block blk = Block.getBlockById( settings.getInteger( "blk" ) );
|
|
|
|
|
|
|
|
if ( blk == Blocks.sand )
|
|
|
|
type = new FalloutSand( w, x, y, z );
|
|
|
|
else if ( blk == Blocks.hardened_clay )
|
|
|
|
type = new FalloutCopy( w, x, y, z );
|
|
|
|
else if ( blk == Blocks.ice || blk == Blocks.snow )
|
|
|
|
type = new FalloutSnow( w, x, y, z );
|
|
|
|
|
|
|
|
int skyMode = settings.getInteger( "skyMode" );
|
|
|
|
|
|
|
|
// creator
|
|
|
|
if ( skyMode > 10 )
|
|
|
|
placeCrator( w, x, y, z );
|
|
|
|
|
|
|
|
placeMetor( w, x, y, z );
|
|
|
|
|
|
|
|
// collapse blocks...
|
|
|
|
if ( skyMode > 3 )
|
|
|
|
Decay( w, x, y, z );
|
|
|
|
|
|
|
|
w.done();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public double getSqDistance(int x, int z)
|
|
|
|
{
|
|
|
|
int Cx = settings.getInteger( "x" ) - x;
|
|
|
|
int Cz = settings.getInteger( "z" ) - z;
|
|
|
|
|
|
|
|
return Cx * Cx + Cz * Cz;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean spawnMeteorite(IMetroiteWorld w, int x, int y, int z)
|
2014-03-02 09:35:11 +01:00
|
|
|
{
|
|
|
|
int validBlocks = 0;
|
|
|
|
|
2014-08-07 08:47:42 +02:00
|
|
|
if ( !w.hasNoSky() )
|
2014-03-02 09:35:11 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
Block blk = w.getBlock( x, y, z );
|
|
|
|
if ( !validSpawn.contains( blk ) )
|
|
|
|
return false; // must spawn on a valid block..
|
|
|
|
|
2014-08-07 08:47:42 +02:00
|
|
|
settings = new NBTTagCompound();
|
|
|
|
settings.setInteger( "x", x );
|
|
|
|
settings.setInteger( "y", y );
|
|
|
|
settings.setInteger( "z", z );
|
|
|
|
settings.setInteger( "blk", Block.getIdFromBlock( blk ) );
|
|
|
|
|
|
|
|
settings.setDouble( "real_sizeOfMetorite", real_sizeOfMetorite );
|
|
|
|
settings.setDouble( "real_crator", real_crator );
|
|
|
|
settings.setDouble( "sizeOfMetorite", sizeOfMetorite );
|
|
|
|
settings.setDouble( "crator", crator );
|
|
|
|
|
|
|
|
settings.setBoolean( "lava", Math.random() > 0.9 );
|
|
|
|
|
2014-03-02 09:35:11 +01:00
|
|
|
if ( blk == Blocks.sand )
|
|
|
|
type = new FalloutSand( w, x, y, z );
|
|
|
|
else if ( blk == Blocks.hardened_clay )
|
|
|
|
type = new FalloutCopy( w, x, y, z );
|
2014-03-04 05:56:08 +01:00
|
|
|
else if ( blk == Blocks.ice || blk == Blocks.snow )
|
|
|
|
type = new FalloutSnow( w, x, y, z );
|
2014-03-02 09:35:11 +01:00
|
|
|
|
|
|
|
int realValidBlocks = 0;
|
|
|
|
|
|
|
|
for (int i = x - 6; i < x + 6; i++)
|
|
|
|
for (int j = y - 6; j < y + 6; j++)
|
|
|
|
for (int k = z - 6; k < z + 6; k++)
|
|
|
|
{
|
|
|
|
blk = w.getBlock( i, j, k );
|
|
|
|
if ( validSpawn.contains( blk ) )
|
|
|
|
realValidBlocks++;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = x - 15; i < x + 15; i++)
|
|
|
|
for (int j = y - 15; j < y + 15; j++)
|
|
|
|
for (int k = z - 15; k < z + 15; k++)
|
|
|
|
{
|
|
|
|
blk = w.getBlock( i, j, k );
|
|
|
|
if ( invalidSpawn.contains( blk ) )
|
|
|
|
return false;
|
|
|
|
if ( validSpawn.contains( blk ) )
|
|
|
|
validBlocks++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( validBlocks > minBLocks && realValidBlocks > 80 )
|
|
|
|
{
|
|
|
|
// we can spawn here!
|
|
|
|
|
|
|
|
int skyMode = 0;
|
|
|
|
|
|
|
|
for (int i = x - 15; i < x + 15; i++)
|
|
|
|
for (int j = y - 15; j < y + 11; j++)
|
|
|
|
for (int k = z - 15; k < z + 15; k++)
|
|
|
|
{
|
|
|
|
if ( w.canBlockSeeTheSky( i, j, k ) )
|
|
|
|
skyMode++;
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean solid = true;
|
|
|
|
for (int j = y - 15; j < y - 1; j++)
|
|
|
|
{
|
|
|
|
if ( w.getBlock( x, j, z ) == Platform.air )
|
|
|
|
solid = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !solid )
|
|
|
|
skyMode = 0;
|
|
|
|
|
|
|
|
// creator
|
|
|
|
if ( skyMode > 10 )
|
|
|
|
placeCrator( w, x, y, z );
|
|
|
|
|
|
|
|
placeMetor( w, x, y, z );
|
|
|
|
|
|
|
|
// collapse blocks...
|
|
|
|
if ( skyMode > 3 )
|
|
|
|
Decay( w, x, y, z );
|
|
|
|
|
2014-08-07 08:47:42 +02:00
|
|
|
settings.setInteger( "skyMode", skyMode );
|
|
|
|
w.done();
|
|
|
|
|
|
|
|
WorldSettings.getInstance().addNearByMetetorites( w.getWorld().provider.dimensionId, x >> 4, z >> 4, settings );
|
2014-03-02 09:35:11 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-08-07 08:47:42 +02:00
|
|
|
private void placeCrator(IMetroiteWorld w, int x, int y, int z)
|
2014-03-02 09:35:11 +01:00
|
|
|
{
|
2014-08-07 08:47:42 +02:00
|
|
|
boolean lava = settings.getBoolean( "lava" );
|
2014-03-02 09:35:11 +01:00
|
|
|
|
2014-08-07 08:47:42 +02:00
|
|
|
int maxY = 255;
|
|
|
|
int minX = w.minX( x - 200 );
|
|
|
|
int maxX = w.maxX( x + 200 );
|
|
|
|
int minZ = w.minZ( z - 200 );
|
|
|
|
int maxZ = w.maxZ( z + 200 );
|
2014-06-08 02:51:08 +02:00
|
|
|
|
|
|
|
for (int j = y - 5; j < maxY; j++)
|
|
|
|
{
|
|
|
|
boolean changed = false;
|
|
|
|
|
|
|
|
for (int i = minX; i < maxX; i++)
|
|
|
|
for (int k = minZ; k < maxZ; k++)
|
2014-03-02 09:35:11 +01:00
|
|
|
{
|
|
|
|
double dx = i - x;
|
|
|
|
double dz = k - z;
|
|
|
|
double h = y - real_sizeOfMetorite + 1 + type.adjustCrator();
|
|
|
|
|
|
|
|
double distanceFrom = dx * dx + dz * dz;
|
|
|
|
|
|
|
|
if ( j > h + distanceFrom * 0.02 )
|
|
|
|
{
|
2014-08-07 08:47:42 +02:00
|
|
|
if ( lava && j < y && w.getBlock( x, y - 1, z ).isBlockSolid( w.getWorld(), i, j, k, 0 ) )
|
2014-03-02 09:35:11 +01:00
|
|
|
{
|
|
|
|
if ( j > h + distanceFrom * 0.02 )
|
|
|
|
put( w, i, j, k, Blocks.lava );
|
|
|
|
}
|
|
|
|
else
|
2014-06-08 02:51:08 +02:00
|
|
|
changed = put( w, i, j, k, Platform.air ) || changed;
|
2014-03-02 09:35:11 +01:00
|
|
|
}
|
|
|
|
}
|
2014-06-08 02:51:08 +02:00
|
|
|
}
|
|
|
|
|
2014-08-07 08:47:42 +02:00
|
|
|
for (Object o : w.getWorld().getEntitiesWithinAABB( EntityItem.class,
|
|
|
|
AxisAlignedBB.getBoundingBox( w.minX( x - 30 ), y - 5, w.minZ( z - 30 ), w.maxX( x + 30 ), y + 30, w.maxZ( z + 30 ) ) ))
|
2014-03-02 09:35:11 +01:00
|
|
|
{
|
|
|
|
Entity e = (Entity) o;
|
|
|
|
e.setDead();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-07 08:47:42 +02:00
|
|
|
private void placeMetor(IMetroiteWorld w, int x, int y, int z)
|
2014-03-02 09:35:11 +01:00
|
|
|
{
|
2014-08-07 08:47:42 +02:00
|
|
|
int Xmeteor_l = w.minX( x - 8 );
|
|
|
|
int Xmeteor_h = w.maxX( x + 8 );
|
|
|
|
int Zmeteor_l = w.minZ( z - 8 );
|
|
|
|
int Zmeteor_h = w.maxZ( z + 8 );
|
|
|
|
|
2014-03-02 09:35:11 +01:00
|
|
|
// spawn metor
|
2014-08-07 08:47:42 +02:00
|
|
|
for (int i = Xmeteor_l; i < Xmeteor_h; i++)
|
2014-03-02 09:35:11 +01:00
|
|
|
for (int j = y - 8; j < y + 8; j++)
|
2014-08-07 08:47:42 +02:00
|
|
|
for (int k = Zmeteor_l; k < Zmeteor_h; k++)
|
2014-03-02 09:35:11 +01:00
|
|
|
{
|
|
|
|
double dx = i - x;
|
|
|
|
double dy = j - y;
|
|
|
|
double dz = k - z;
|
|
|
|
|
|
|
|
if ( dx * dx * 0.7 + dy * dy * (j > y ? 1.4 : 0.8) + dz * dz * 0.7 < sizeOfMetorite )
|
|
|
|
put( w, i, j, k, skystone );
|
|
|
|
}
|
2014-03-03 00:18:15 +01:00
|
|
|
|
2014-08-24 08:50:22 +02:00
|
|
|
if ( AEConfig.instance.isFeatureEnabled( AEFeature.SpawnPressesInMeteorites ) )
|
2014-03-05 04:29:03 +01:00
|
|
|
{
|
2014-08-24 08:50:22 +02:00
|
|
|
put( w, x, y, z, skychest );
|
|
|
|
TileEntity te = w.getTileEntity( x, y, z );
|
|
|
|
if ( te != null && te instanceof IInventory )
|
2014-03-05 04:29:03 +01:00
|
|
|
{
|
2014-08-24 08:50:22 +02:00
|
|
|
InventoryAdaptor ap = InventoryAdaptor.getAdaptor( te, ForgeDirection.UP );
|
2014-05-16 04:18:30 +02:00
|
|
|
|
2014-08-24 08:50:22 +02:00
|
|
|
int primary = Math.max( 1, (int) (Math.random() * 4) );
|
2014-06-06 06:51:37 +02:00
|
|
|
|
2014-08-24 08:50:22 +02:00
|
|
|
if ( primary > 3 ) // in case math breaks...
|
|
|
|
primary = 3;
|
2014-06-06 06:51:37 +02:00
|
|
|
|
2014-08-24 08:50:22 +02:00
|
|
|
for (int zz = 0; zz < primary; zz++)
|
|
|
|
{
|
|
|
|
int r = 0;
|
|
|
|
boolean duplicate = false;
|
2014-06-06 06:51:37 +02:00
|
|
|
|
2014-08-24 08:50:22 +02:00
|
|
|
do
|
2014-06-06 06:51:37 +02:00
|
|
|
{
|
2014-08-24 08:50:22 +02:00
|
|
|
duplicate = false;
|
2014-06-06 06:51:37 +02:00
|
|
|
|
2014-08-24 08:50:22 +02:00
|
|
|
if ( Math.random() > 0.7 )
|
|
|
|
r = WorldSettings.getInstance().getNextOrderedValue( "presses" );
|
2014-06-06 06:51:37 +02:00
|
|
|
else
|
2014-08-24 08:50:22 +02:00
|
|
|
r = (int) (Math.random() * 1000);
|
|
|
|
|
|
|
|
ItemStack toAdd = null;
|
|
|
|
|
|
|
|
switch (r % 4)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
toAdd = AEApi.instance().materials().materialCalcProcessorPress.stack( 1 );
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
toAdd = AEApi.instance().materials().materialEngProcessorPress.stack( 1 );
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
toAdd = AEApi.instance().materials().materialLogicProcessorPress.stack( 1 );
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
toAdd = AEApi.instance().materials().materialSiliconPress.stack( 1 );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( toAdd != null )
|
|
|
|
{
|
|
|
|
if ( ap.simulateRemove( 1, toAdd, null ) == null )
|
|
|
|
ap.addItems( toAdd );
|
|
|
|
else
|
|
|
|
duplicate = true;
|
|
|
|
}
|
2014-06-06 06:51:37 +02:00
|
|
|
}
|
2014-08-24 08:50:22 +02:00
|
|
|
while (duplicate);
|
2014-03-09 00:31:09 +01:00
|
|
|
}
|
2014-03-05 04:29:03 +01:00
|
|
|
|
2014-08-24 08:50:22 +02:00
|
|
|
int secondary = Math.max( 1, (int) (Math.random() * 3) );
|
|
|
|
for (int zz = 0; zz < secondary; zz++)
|
2014-03-09 00:31:09 +01:00
|
|
|
{
|
2014-08-24 08:50:22 +02:00
|
|
|
switch ((int) (Math.random() * 1000) % 3)
|
2014-04-28 06:49:14 +02:00
|
|
|
{
|
2014-08-24 08:50:22 +02:00
|
|
|
case 0:
|
|
|
|
ap.addItems( AEApi.instance().blocks().blockSkyStone.stack( (int) (Math.random() * 12) + 1 ) );
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
List<ItemStack> possibles = new LinkedList();
|
|
|
|
possibles.addAll( OreDictionary.getOres( "nuggetIron" ) );
|
|
|
|
possibles.addAll( OreDictionary.getOres( "nuggetCopper" ) );
|
|
|
|
possibles.addAll( OreDictionary.getOres( "nuggetTin" ) );
|
|
|
|
possibles.addAll( OreDictionary.getOres( "nuggetSilver" ) );
|
|
|
|
possibles.addAll( OreDictionary.getOres( "nuggetLead" ) );
|
|
|
|
possibles.addAll( OreDictionary.getOres( "nuggetPlatinum" ) );
|
|
|
|
possibles.addAll( OreDictionary.getOres( "nuggetNickel" ) );
|
|
|
|
possibles.addAll( OreDictionary.getOres( "nuggetAluminium" ) );
|
|
|
|
possibles.addAll( OreDictionary.getOres( "nuggetElectrum" ) );
|
|
|
|
possibles.add( new ItemStack( net.minecraft.init.Items.gold_nugget ) );
|
|
|
|
|
|
|
|
ItemStack nugget = Platform.pickRandom( possibles );
|
|
|
|
if ( nugget != null )
|
|
|
|
{
|
|
|
|
nugget = nugget.copy();
|
|
|
|
nugget.stackSize = (int) (Math.random() * 12) + 1;
|
|
|
|
ap.addItems( nugget );
|
|
|
|
}
|
|
|
|
break;
|
2014-04-28 06:49:14 +02:00
|
|
|
}
|
2014-03-09 00:31:09 +01:00
|
|
|
}
|
2014-03-05 04:29:03 +01:00
|
|
|
}
|
|
|
|
}
|
2014-03-02 09:35:11 +01:00
|
|
|
}
|
|
|
|
|
2014-08-07 08:47:42 +02:00
|
|
|
private void Decay(IMetroiteWorld w, int x, int y, int z)
|
2014-03-02 09:35:11 +01:00
|
|
|
{
|
2014-03-04 05:56:08 +01:00
|
|
|
double randomShit = 0;
|
2014-03-02 09:35:11 +01:00
|
|
|
|
2014-08-07 08:47:42 +02:00
|
|
|
int Xmeteor_l = w.minX( x - 30 );
|
|
|
|
int Xmeteor_h = w.maxX( x + 30 );
|
|
|
|
int Zmeteor_l = w.minZ( z - 30 );
|
|
|
|
int Zmeteor_h = w.maxZ( z + 30 );
|
|
|
|
|
|
|
|
for (int i = Xmeteor_l; i < Xmeteor_h; i++)
|
|
|
|
for (int k = Zmeteor_l; k < Zmeteor_h; k++)
|
2014-03-04 05:56:08 +01:00
|
|
|
for (int j = y - 9; j < y + 30; j++)
|
2014-03-02 09:35:11 +01:00
|
|
|
{
|
|
|
|
Block blk = w.getBlock( i, j, k );
|
|
|
|
if ( blk == Blocks.lava )
|
|
|
|
continue;
|
|
|
|
|
2014-08-07 08:47:42 +02:00
|
|
|
if ( blk.isReplaceable( w.getWorld(), i, j, k ) )
|
2014-03-02 09:35:11 +01:00
|
|
|
{
|
|
|
|
blk = Platform.air;
|
|
|
|
Block blk_b = w.getBlock( i, j + 1, k );
|
|
|
|
|
|
|
|
if ( blk_b != blk )
|
|
|
|
{
|
|
|
|
int meta_b = w.getBlockMetadata( i, j + 1, k );
|
|
|
|
|
|
|
|
w.setBlock( i, j, k, blk_b, meta_b, 3 );
|
|
|
|
w.setBlock( i, j + 1, k, blk );
|
|
|
|
}
|
2014-03-04 05:56:08 +01:00
|
|
|
else if ( randomShit < 100 * crator )
|
2014-03-02 09:35:11 +01:00
|
|
|
{
|
|
|
|
double dx = i - x;
|
|
|
|
double dy = j - y;
|
|
|
|
double dz = k - z;
|
|
|
|
double dist = dx * dx + dy * dy + dz * dz;
|
|
|
|
|
|
|
|
Block xf = w.getBlock( i, j - 1, k );
|
2014-08-07 08:47:42 +02:00
|
|
|
if ( !xf.isReplaceable( w.getWorld(), i, j - 1, k ) )
|
2014-03-02 09:35:11 +01:00
|
|
|
{
|
2014-03-04 05:56:08 +01:00
|
|
|
double extrRange = Math.random() * 0.6;
|
|
|
|
double height = crator * (extrRange + 0.2) - Math.abs( dist - crator * 1.7 );
|
2014-03-03 00:18:15 +01:00
|
|
|
|
2014-03-04 05:56:08 +01:00
|
|
|
if ( xf != blk && height > 0 && Math.random() > 0.6 )
|
2014-03-03 00:18:15 +01:00
|
|
|
{
|
2014-03-04 05:56:08 +01:00
|
|
|
randomShit++;
|
2014-03-03 00:18:15 +01:00
|
|
|
type.getRandomFall( w, i, j, k );
|
|
|
|
}
|
2014-03-02 09:35:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// decay.
|
|
|
|
Block blk_b = w.getBlock( i, j + 1, k );
|
|
|
|
if ( blk_b == Platform.air )
|
|
|
|
{
|
|
|
|
if ( Math.random() > 0.4 )
|
|
|
|
{
|
|
|
|
double dx = i - x;
|
|
|
|
double dy = j - y;
|
|
|
|
double dz = k - z;
|
|
|
|
|
|
|
|
if ( dx * dx + dy * dy + dz * dz < crator * 1.6 )
|
|
|
|
{
|
|
|
|
type.getRandomInset( w, i, j, k );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-07 08:47:42 +02:00
|
|
|
private boolean put(IMetroiteWorld w, int i, int j, int k, Block blk)
|
2014-03-02 09:35:11 +01:00
|
|
|
{
|
2014-06-08 02:51:08 +02:00
|
|
|
Block original = w.getBlock( i, j, k );
|
|
|
|
|
|
|
|
if ( original == Blocks.bedrock || original == blk )
|
|
|
|
return false;
|
2014-03-02 09:35:11 +01:00
|
|
|
|
2014-03-05 04:29:03 +01:00
|
|
|
w.setBlock( i, j, k, blk );
|
2014-06-08 02:51:08 +02:00
|
|
|
return true;
|
2014-03-02 09:35:11 +01:00
|
|
|
}
|
|
|
|
|
2014-08-07 08:47:42 +02:00
|
|
|
private void put(IMetroiteWorld w, int i, int j, int k, Block blk, int meta)
|
2014-03-02 09:35:11 +01:00
|
|
|
{
|
|
|
|
if ( w.getBlock( i, j, k ) == Blocks.bedrock )
|
|
|
|
return;
|
|
|
|
|
2014-03-05 04:29:03 +01:00
|
|
|
w.setBlock( i, j, k, blk, meta, 3 );
|
2014-03-02 09:35:11 +01:00
|
|
|
}
|
2014-08-07 08:47:42 +02:00
|
|
|
|
|
|
|
public NBTTagCompound getSettings()
|
|
|
|
{
|
|
|
|
return settings;
|
|
|
|
}
|
2014-03-02 09:35:11 +01:00
|
|
|
}
|