2015-01-03 02:53:14 +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.Collection;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import net.minecraft.block.Block;
|
2015-06-16 02:44:59 +02:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
2015-01-03 02:53:14 +01:00
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.item.EntityItem;
|
|
|
|
import net.minecraft.init.Blocks;
|
|
|
|
import net.minecraft.inventory.IInventory;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.AxisAlignedBB;
|
2015-06-16 02:44:59 +02:00
|
|
|
import net.minecraft.util.BlockPos;
|
|
|
|
import net.minecraft.util.EnumFacing;
|
2015-01-03 02:53:14 +01:00
|
|
|
import net.minecraftforge.oredict.OreDictionary;
|
|
|
|
import appeng.api.AEApi;
|
|
|
|
import appeng.api.definitions.IBlockDefinition;
|
|
|
|
import appeng.api.definitions.IBlocks;
|
|
|
|
import appeng.api.definitions.IMaterials;
|
|
|
|
import appeng.core.AEConfig;
|
|
|
|
import appeng.core.WorldSettings;
|
|
|
|
import appeng.core.features.AEFeature;
|
2015-04-03 08:54:31 +02:00
|
|
|
import appeng.util.InventoryAdaptor;
|
|
|
|
import appeng.util.Platform;
|
2015-01-03 02:53:14 +01:00
|
|
|
import appeng.worldgen.meteorite.Fallout;
|
|
|
|
import appeng.worldgen.meteorite.FalloutCopy;
|
|
|
|
import appeng.worldgen.meteorite.FalloutSand;
|
|
|
|
import appeng.worldgen.meteorite.FalloutSnow;
|
|
|
|
import appeng.worldgen.meteorite.IMeteoriteWorld;
|
|
|
|
import appeng.worldgen.meteorite.MeteoriteBlockPutter;
|
|
|
|
|
|
|
|
|
|
|
|
public final class MeteoritePlacer
|
|
|
|
{
|
|
|
|
public static final double PRESSES_SPAWN_CHANCE = 0.7;
|
|
|
|
public static final int SKYSTONE_SPAWN_LIMIT = 12;
|
|
|
|
private final Collection<Block> validSpawn = new HashSet<Block>();
|
|
|
|
private final Collection<Block> invalidSpawn = new HashSet<Block>();
|
|
|
|
private final IBlockDefinition skyChestDefinition;
|
|
|
|
private final IBlockDefinition skyStoneDefinition;
|
|
|
|
private final MeteoriteBlockPutter putter = new MeteoriteBlockPutter();
|
|
|
|
private double meteoriteSize = ( Math.random() * 6.0 ) + 2;
|
|
|
|
private double realCrater = this.meteoriteSize * 2 + 5;
|
|
|
|
private double squaredMeteoriteSize = this.meteoriteSize * this.meteoriteSize;
|
|
|
|
private double crater = this.realCrater * this.realCrater;
|
|
|
|
private NBTTagCompound settings;
|
|
|
|
private Fallout type;
|
|
|
|
|
|
|
|
public MeteoritePlacer()
|
|
|
|
{
|
|
|
|
final IBlocks blocks = AEApi.instance().definitions().blocks();
|
|
|
|
|
|
|
|
this.skyChestDefinition = blocks.skyChest();
|
|
|
|
this.skyStoneDefinition = blocks.skyStone();
|
|
|
|
|
|
|
|
this.validSpawn.add( Blocks.stone );
|
|
|
|
this.validSpawn.add( Blocks.cobblestone );
|
|
|
|
this.validSpawn.add( Blocks.grass );
|
|
|
|
this.validSpawn.add( Blocks.sand );
|
|
|
|
this.validSpawn.add( Blocks.dirt );
|
|
|
|
this.validSpawn.add( Blocks.gravel );
|
|
|
|
this.validSpawn.add( Blocks.netherrack );
|
|
|
|
this.validSpawn.add( Blocks.iron_ore );
|
|
|
|
this.validSpawn.add( Blocks.gold_ore );
|
|
|
|
this.validSpawn.add( Blocks.diamond_ore );
|
|
|
|
this.validSpawn.add( Blocks.redstone_ore );
|
|
|
|
this.validSpawn.add( Blocks.hardened_clay );
|
|
|
|
this.validSpawn.add( Blocks.ice );
|
|
|
|
this.validSpawn.add( Blocks.snow );
|
2015-05-10 11:37:42 +02:00
|
|
|
this.validSpawn.add( Blocks.stained_hardened_clay );
|
2015-01-03 02:53:14 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( Block skyStoneBlock : this.skyStoneDefinition.maybeBlock().asSet() )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
this.invalidSpawn.add( skyStoneBlock );
|
|
|
|
}
|
|
|
|
this.invalidSpawn.add( Blocks.planks );
|
|
|
|
this.invalidSpawn.add( Blocks.iron_door );
|
|
|
|
this.invalidSpawn.add( Blocks.iron_bars );
|
2015-06-16 02:44:59 +02:00
|
|
|
this.invalidSpawn.add( Blocks.oak_door );
|
|
|
|
this.invalidSpawn.add( Blocks.acacia_door );
|
|
|
|
this.invalidSpawn.add( Blocks.birch_door );
|
|
|
|
this.invalidSpawn.add( Blocks.dark_oak_door );
|
|
|
|
this.invalidSpawn.add( Blocks.iron_door );
|
|
|
|
this.invalidSpawn.add( Blocks.jungle_door );
|
|
|
|
this.invalidSpawn.add( Blocks.spruce_door );
|
2015-01-03 02:53:14 +01:00
|
|
|
this.invalidSpawn.add( Blocks.brick_block );
|
|
|
|
this.invalidSpawn.add( Blocks.clay );
|
|
|
|
this.invalidSpawn.add( Blocks.water );
|
|
|
|
this.invalidSpawn.add( Blocks.log );
|
|
|
|
this.invalidSpawn.add( Blocks.log2 );
|
|
|
|
|
|
|
|
this.type = new Fallout( this.putter, this.skyStoneDefinition );
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean spawnMeteorite( IMeteoriteWorld w, NBTTagCompound meteoriteBlob )
|
|
|
|
{
|
|
|
|
this.settings = meteoriteBlob;
|
|
|
|
|
|
|
|
int x = this.settings.getInteger( "x" );
|
|
|
|
int y = this.settings.getInteger( "y" );
|
|
|
|
int z = this.settings.getInteger( "z" );
|
|
|
|
|
|
|
|
this.meteoriteSize = this.settings.getDouble( "real_sizeOfMeteorite" );
|
|
|
|
this.realCrater = this.settings.getDouble( "realCrater" );
|
|
|
|
this.squaredMeteoriteSize = this.settings.getDouble( "sizeOfMeteorite" );
|
|
|
|
this.crater = this.settings.getDouble( "crater" );
|
|
|
|
|
|
|
|
Block blk = Block.getBlockById( this.settings.getInteger( "blk" ) );
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( blk == Blocks.sand )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
this.type = new FalloutSand( w, x, y, z, this.putter, this.skyStoneDefinition );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( blk == Blocks.hardened_clay )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
this.type = new FalloutCopy( w, x, y, z, this.putter, this.skyStoneDefinition );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( blk == Blocks.ice || blk == Blocks.snow )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
this.type = new FalloutSnow( w, x, y, z, this.putter, this.skyStoneDefinition );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
|
|
|
|
int skyMode = this.settings.getInteger( "skyMode" );
|
|
|
|
|
|
|
|
// creator
|
2015-04-03 08:54:31 +02:00
|
|
|
if( skyMode > 10 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
this.placeCrater( w, x, y, z );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
|
|
|
|
this.placeMeteorite( w, x, y, z );
|
|
|
|
|
|
|
|
// collapse blocks...
|
2015-04-03 08:54:31 +02:00
|
|
|
if( skyMode > 3 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
this.decay( w, x, y, z );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
|
|
|
|
w.done();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void placeCrater( IMeteoriteWorld w, int x, int y, int z )
|
|
|
|
{
|
|
|
|
boolean lava = this.settings.getBoolean( "lava" );
|
|
|
|
|
|
|
|
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 );
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int j = y - 5; j < maxY; j++ )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
boolean changed = false;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int i = minX; i < maxX; i++ )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int k = minZ; k < maxZ; k++ )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
double dx = i - x;
|
|
|
|
double dz = k - z;
|
|
|
|
double h = y - this.meteoriteSize + 1 + this.type.adjustCrater();
|
|
|
|
|
|
|
|
double distanceFrom = dx * dx + dz * dz;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( j > h + distanceFrom * 0.02 )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2015-06-16 02:44:59 +02:00
|
|
|
if( lava && j < y && w.getBlock( x, y - 1, z ).isBlockSolid( w.getWorld(), new BlockPos( i, j, k ), EnumFacing.UP ) )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( j > h + distanceFrom * 0.02 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
this.putter.put( w, i, j, k, Blocks.lava );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
}
|
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-05-08 23:37:09 +02:00
|
|
|
changed = this.putter.put( w, i, j, k, Platform.AIR_BLOCK ) || changed;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
}
|
|
|
|
}
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
}
|
|
|
|
|
2015-06-16 02:44:59 +02:00
|
|
|
for( Object o : w.getWorld().getEntitiesWithinAABB( EntityItem.class, AxisAlignedBB.fromBounds( w.minX( x - 30 ), y - 5, w.minZ( z - 30 ), w.maxX( x + 30 ), y + 30, w.maxZ( z + 30 ) ) ) )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
Entity e = (Entity) o;
|
|
|
|
e.setDead();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void placeMeteorite( IMeteoriteWorld w, int x, int y, int z )
|
|
|
|
{
|
|
|
|
int meteorXLength = w.minX( x - 8 );
|
|
|
|
int meteorXHeight = w.maxX( x + 8 );
|
|
|
|
int meteorZLength = w.minZ( z - 8 );
|
|
|
|
int meteorZHeight = w.maxZ( z + 8 );
|
|
|
|
|
|
|
|
// spawn meteor
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int i = meteorXLength; i < meteorXHeight; i++ )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int j = y - 8; j < y + 8; j++ )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int k = meteorZLength; k < meteorZHeight; k++ )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
double dx = i - x;
|
|
|
|
double dy = j - y;
|
|
|
|
double dz = k - z;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( dx * dx * 0.7 + dy * dy * ( j > y ? 1.4 : 0.8 ) + dz * dz * 0.7 < this.squaredMeteoriteSize )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( Block skyStoneBlock : this.skyStoneDefinition.maybeBlock().asSet() )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
this.putter.put( w, i, j, k, skyStoneBlock );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( AEConfig.instance.isFeatureEnabled( AEFeature.SpawnPressesInMeteorites ) )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( Block skyChestBlock : this.skyChestDefinition.maybeBlock().asSet() )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
this.putter.put( w, x, y, z, skyChestBlock );
|
|
|
|
}
|
|
|
|
|
|
|
|
TileEntity te = w.getTileEntity( x, y, z );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( te instanceof IInventory )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2015-06-16 02:44:59 +02:00
|
|
|
InventoryAdaptor ap = InventoryAdaptor.getAdaptor( te, EnumFacing.UP );
|
2015-01-03 02:53:14 +01:00
|
|
|
|
|
|
|
int primary = Math.max( 1, (int) ( Math.random() * 4 ) );
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( primary > 3 ) // in case math breaks...
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
primary = 3;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int zz = 0; zz < primary; zz++ )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
int r = 0;
|
|
|
|
boolean duplicate = false;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
duplicate = false;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( Math.random() > PRESSES_SPAWN_CHANCE )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
r = WorldSettings.getInstance().getNextOrderedValue( "presses" );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
r = (int) ( Math.random() * 1000 );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
|
|
|
|
ItemStack toAdd = null;
|
|
|
|
final IMaterials materials = AEApi.instance().definitions().materials();
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
switch( r % 4 )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
case 0:
|
2015-04-03 08:54:31 +02:00
|
|
|
for( ItemStack calc : materials.calcProcessorPress().maybeStack( 1 ).asSet() )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
toAdd = calc;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
2015-04-03 08:54:31 +02:00
|
|
|
for( ItemStack calc : materials.engProcessorPress().maybeStack( 1 ).asSet() )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
toAdd = calc;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
2015-04-03 08:54:31 +02:00
|
|
|
for( ItemStack calc : materials.logicProcessorPress().maybeStack( 1 ).asSet() )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
toAdd = calc;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
2015-04-03 08:54:31 +02:00
|
|
|
for( ItemStack calc : materials.siliconPress().maybeStack( 1 ).asSet() )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
toAdd = calc;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( toAdd != null )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ap.simulateRemove( 1, toAdd, null ) == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
ap.addItems( toAdd );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
duplicate = true;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
}
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
while( duplicate );
|
2015-01-03 02:53:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int secondary = Math.max( 1, (int) ( Math.random() * 3 ) );
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int zz = 0; zz < secondary; zz++ )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
switch( (int) ( Math.random() * 1000 ) % 3 )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
final int amount = (int) ( ( Math.random() * SKYSTONE_SPAWN_LIMIT ) + 1 );
|
2015-04-03 08:54:31 +02:00
|
|
|
for( ItemStack skyStoneStack : this.skyStoneDefinition.maybeStack( amount ).asSet() )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
ap.addItems( skyStoneStack );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
List<ItemStack> possibles = new LinkedList<ItemStack>();
|
|
|
|
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 );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( nugget != null )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
nugget = nugget.copy();
|
|
|
|
nugget.stackSize = (int) ( Math.random() * 12 ) + 1;
|
|
|
|
ap.addItems( nugget );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void decay( IMeteoriteWorld w, int x, int y, int z )
|
|
|
|
{
|
|
|
|
double randomShit = 0;
|
|
|
|
|
|
|
|
int meteorXLength = w.minX( x - 30 );
|
|
|
|
int meteorXHeight = w.maxX( x + 30 );
|
|
|
|
int meteorZLength = w.minZ( z - 30 );
|
|
|
|
int meteorZHeight = w.maxZ( z + 30 );
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int i = meteorXLength; i < meteorXHeight; i++ )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int k = meteorZLength; k < meteorZHeight; k++ )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int j = y - 9; j < y + 30; j++ )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
Block blk = w.getBlock( i, j, k );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( blk == Blocks.lava )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
continue;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
|
2015-06-16 02:44:59 +02:00
|
|
|
if( blk.isReplaceable( w.getWorld(), new BlockPos( i, j, k ) ) )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2015-05-08 23:37:09 +02:00
|
|
|
blk = Platform.AIR_BLOCK;
|
2015-01-03 02:53:14 +01:00
|
|
|
Block blk_b = w.getBlock( i, j + 1, k );
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( blk_b != blk )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2015-06-16 02:44:59 +02:00
|
|
|
IBlockState meta_b = w.getBlockState( i, j + 1, k );
|
2015-01-03 02:53:14 +01:00
|
|
|
|
2015-06-16 02:44:59 +02:00
|
|
|
w.setBlock( i, j, k, meta_b, 3 );
|
2015-01-03 02:53:14 +01:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( randomShit < 100 * this.crater )
|
2015-01-03 02:53:14 +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 );
|
2015-06-16 02:44:59 +02:00
|
|
|
if( !xf.isReplaceable( w.getWorld(), new BlockPos(i, j - 1, k) ) )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
double extraRange = Math.random() * 0.6;
|
|
|
|
double height = this.crater * ( extraRange + 0.2 ) - Math.abs( dist - this.crater * 1.7 );
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( xf != blk && height > 0 && Math.random() > 0.6 )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
randomShit++;
|
|
|
|
this.type.getRandomFall( w, i, j, k );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// decay.
|
|
|
|
Block blk_b = w.getBlock( i, j + 1, k );
|
2015-05-08 23:37:09 +02:00
|
|
|
if( blk_b == Platform.AIR_BLOCK )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( Math.random() > 0.4 )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
double dx = i - x;
|
|
|
|
double dy = j - y;
|
|
|
|
double dz = k - z;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( dx * dx + dy * dy + dz * dz < this.crater * 1.6 )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
this.type.getRandomInset( w, i, j, k );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public double getSqDistance( int x, int z )
|
|
|
|
{
|
2015-05-08 23:34:24 +02:00
|
|
|
int chunkX = this.settings.getInteger( "x" ) - x;
|
|
|
|
int chunkZ = this.settings.getInteger( "z" ) - z;
|
2015-01-03 02:53:14 +01:00
|
|
|
|
2015-05-08 23:34:24 +02:00
|
|
|
return chunkX * chunkX + chunkZ * chunkZ;
|
2015-01-03 02:53:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean spawnMeteorite( IMeteoriteWorld w, int x, int y, int z )
|
|
|
|
{
|
|
|
|
int validBlocks = 0;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !w.hasNoSky() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
return false;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
|
|
|
|
Block blk = w.getBlock( x, y, z );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !this.validSpawn.contains( blk ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
return false; // must spawn on a valid block..
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
|
|
|
|
this.settings = new NBTTagCompound();
|
|
|
|
this.settings.setInteger( "x", x );
|
|
|
|
this.settings.setInteger( "y", y );
|
|
|
|
this.settings.setInteger( "z", z );
|
|
|
|
this.settings.setInteger( "blk", Block.getIdFromBlock( blk ) );
|
|
|
|
|
|
|
|
this.settings.setDouble( "real_sizeOfMeteorite", this.meteoriteSize );
|
|
|
|
this.settings.setDouble( "realCrater", this.realCrater );
|
|
|
|
this.settings.setDouble( "sizeOfMeteorite", this.squaredMeteoriteSize );
|
|
|
|
this.settings.setDouble( "crater", this.crater );
|
|
|
|
|
|
|
|
this.settings.setBoolean( "lava", Math.random() > 0.9 );
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( blk == Blocks.sand )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
this.type = new FalloutSand( w, x, y, z, this.putter, this.skyStoneDefinition );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( blk == Blocks.hardened_clay )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
this.type = new FalloutCopy( w, x, y, z, this.putter, this.skyStoneDefinition );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( blk == Blocks.ice || blk == Blocks.snow )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
this.type = new FalloutSnow( w, x, y, z, this.putter, this.skyStoneDefinition );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
|
|
|
|
int realValidBlocks = 0;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int i = x - 6; i < x + 6; i++ )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int j = y - 6; j < y + 6; j++ )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int k = z - 6; k < z + 6; k++ )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
blk = w.getBlock( i, j, k );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.validSpawn.contains( blk ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
realValidBlocks++;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
}
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int i = x - 15; i < x + 15; i++ )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int j = y - 15; j < y + 15; j++ )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int k = z - 15; k < z + 15; k++ )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
blk = w.getBlock( i, j, k );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.invalidSpawn.contains( blk ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
return false;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.validSpawn.contains( blk ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
validBlocks++;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
}
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
|
|
|
|
int minBLocks = 200;
|
2015-04-03 08:54:31 +02:00
|
|
|
if( validBlocks > minBLocks && realValidBlocks > 80 )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
// we can spawn here!
|
|
|
|
|
|
|
|
int skyMode = 0;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int i = x - 15; i < x + 15; i++ )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int j = y - 15; j < y + 11; j++ )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int k = z - 15; k < z + 15; k++ )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( w.canBlockSeeTheSky( i, j, k ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
skyMode++;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
}
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
|
|
|
|
boolean solid = true;
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int j = y - 15; j < y - 1; j++ )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2015-05-08 23:37:09 +02:00
|
|
|
if( w.getBlock( x, j, z ) == Platform.AIR_BLOCK )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
solid = false;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !solid )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
skyMode = 0;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
|
|
|
|
// creator
|
2015-04-03 08:54:31 +02:00
|
|
|
if( skyMode > 10 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
this.placeCrater( w, x, y, z );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
|
|
|
|
this.placeMeteorite( w, x, y, z );
|
|
|
|
|
|
|
|
// collapse blocks...
|
2015-04-03 08:54:31 +02:00
|
|
|
if( skyMode > 3 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
this.decay( w, x, y, z );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
|
|
|
|
this.settings.setInteger( "skyMode", skyMode );
|
|
|
|
w.done();
|
|
|
|
|
2015-06-16 02:44:59 +02:00
|
|
|
WorldSettings.getInstance().addNearByMeteorites( w.getWorld().provider.getDimensionId(), x >> 4, z >> 4, this.settings );
|
2015-01-03 02:53:14 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public NBTTagCompound getSettings()
|
|
|
|
{
|
|
|
|
return this.settings;
|
|
|
|
}
|
|
|
|
}
|