@@ -0,0 +1,32 @@
|
||||
package appeng.worldgen;
|
||||
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.util.math.MutableBoundingBox;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.gen.ChunkGenerator;
|
||||
import net.minecraft.world.gen.feature.structure.IStructurePieceType;
|
||||
import net.minecraft.world.gen.feature.structure.ScatteredStructurePiece;
|
||||
import net.minecraft.world.gen.feature.structure.StructurePiece;
|
||||
import net.minecraft.world.gen.feature.template.TemplateManager;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class MeteoritePiece extends ScatteredStructurePiece {
|
||||
|
||||
public static IStructurePieceType TYPE = IStructurePieceType.register(MeteoritePiece::new, "AE2M");
|
||||
|
||||
public MeteoritePiece(Random random, int x, int z) {
|
||||
super(TYPE, random, x, 64, z, 7, 7, 9);
|
||||
}
|
||||
|
||||
public MeteoritePiece(TemplateManager p_i51340_1_, CompoundNBT p_i51340_2_) {
|
||||
super(TYPE, p_i51340_2_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean create(IWorld worldIn, ChunkGenerator<?> chunkGeneratorIn, Random randomIn, MutableBoundingBox mutableBoundingBoxIn, ChunkPos chunkPosIn) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,20 +19,18 @@
|
||||
package appeng.worldgen;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.ItemEntity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
@@ -51,128 +49,102 @@ import appeng.worldgen.meteorite.FalloutSand;
|
||||
import appeng.worldgen.meteorite.FalloutSnow;
|
||||
import appeng.worldgen.meteorite.IMeteoriteWorld;
|
||||
import appeng.worldgen.meteorite.MeteoriteBlockPutter;
|
||||
import net.minecraft.world.IWorld;
|
||||
|
||||
|
||||
public final class MeteoritePlacer
|
||||
{
|
||||
private static final double PRESSES_SPAWN_CHANCE = 0.7;
|
||||
private static final int SKYSTONE_SPAWN_LIMIT = 12;
|
||||
private final Collection<Block> validSpawn = new HashSet<>();
|
||||
private final Collection<Block> invalidSpawn = new HashSet<>();
|
||||
private final IBlockDefinition skyChestDefinition;
|
||||
private final IBlockDefinition skyStoneDefinition;
|
||||
private final BlockState skyStone;
|
||||
private final Item skyStoneItem;
|
||||
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 CompoundNBT settings;
|
||||
private Fallout type;
|
||||
private final IWorld world;
|
||||
private final Fallout type;
|
||||
private final BlockPos pos;
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
private final double meteoriteSize;
|
||||
private final double realCrater;
|
||||
private final double squaredMeteoriteSize;
|
||||
private final double crater;
|
||||
private final int skyMode;
|
||||
private final boolean lava;
|
||||
|
||||
public MeteoritePlacer()
|
||||
public MeteoritePlacer(IWorld world, PlacedMeteoriteSettings settings)
|
||||
{
|
||||
this.world = world;
|
||||
this.pos = settings.getPos();
|
||||
this.x = settings.getPos().getX();
|
||||
this.y = settings.getPos().getY();
|
||||
this.z = settings.getPos().getZ();
|
||||
this.meteoriteSize = settings.getMeteoriteRadius();
|
||||
this.realCrater = settings.getCraterRadius();
|
||||
this.skyMode = settings.getSkyMode();
|
||||
this.lava = settings.isLava();
|
||||
this.squaredMeteoriteSize = this.meteoriteSize * this.meteoriteSize;
|
||||
this.crater = this.realCrater * this.realCrater;
|
||||
|
||||
final IBlocks blocks = AEApi.instance().definitions().blocks();
|
||||
|
||||
this.skyChestDefinition = blocks.skyStoneChest();
|
||||
this.skyStoneDefinition = blocks.skyStoneBlock();
|
||||
this.skyStone = blocks.skyStoneBlock().block().getDefaultState();
|
||||
this.skyStoneItem = blocks.skyStoneBlock().item();
|
||||
|
||||
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.ICE );
|
||||
this.validSpawn.add( Blocks.SNOW );
|
||||
|
||||
this.skyStoneDefinition.maybeBlock().ifPresent( this.invalidSpawn::add );
|
||||
this.invalidSpawn.add( Blocks.IRON_DOOR );
|
||||
this.invalidSpawn.add( Blocks.IRON_BARS );
|
||||
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 );
|
||||
this.invalidSpawn.add( Blocks.BRICKS );
|
||||
this.invalidSpawn.add( Blocks.CLAY );
|
||||
this.invalidSpawn.add( Blocks.WATER );
|
||||
|
||||
this.type = new Fallout( this.putter, this.skyStoneDefinition );
|
||||
this.type = getFalloutFromBaseBlock(world, settings.getPos(), settings.getBlk());
|
||||
}
|
||||
|
||||
boolean spawnMeteorite( final IMeteoriteWorld w, final CompoundNBT meteoriteBlob )
|
||||
{
|
||||
this.settings = meteoriteBlob;
|
||||
|
||||
final int x = this.settings.getInt( "x" );
|
||||
final int y = this.settings.getInt( "y" );
|
||||
final int z = this.settings.getInt( "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" );
|
||||
|
||||
final Block blk = Block.getBlockById( this.settings.getInt( "blk" ) );
|
||||
|
||||
if( blk == Blocks.SAND )
|
||||
{
|
||||
this.type = new FalloutSand( w, x, y, z, this.putter, this.skyStoneDefinition );
|
||||
}
|
||||
else if( blk == Blocks.HARDENED_CLAY )
|
||||
{
|
||||
this.type = new FalloutCopy( w, x, y, z, this.putter, this.skyStoneDefinition );
|
||||
}
|
||||
else if( blk == Blocks.ICE || blk == Blocks.SNOW )
|
||||
{
|
||||
this.type = new FalloutSnow( w, x, y, z, this.putter, this.skyStoneDefinition );
|
||||
}
|
||||
|
||||
final int skyMode = this.settings.getInt( "skyMode" );
|
||||
|
||||
public void place() {
|
||||
// creator
|
||||
if( skyMode > 10 )
|
||||
{
|
||||
this.placeCrater( w, x, y, z );
|
||||
this.placeCrater();
|
||||
}
|
||||
|
||||
this.placeMeteorite( w, x, y, z );
|
||||
this.placeMeteorite();
|
||||
|
||||
// collapse blocks...
|
||||
if( skyMode > 3 )
|
||||
{
|
||||
this.decay( w, x, y, z );
|
||||
this.decay();
|
||||
}
|
||||
|
||||
w.done();
|
||||
return true;
|
||||
}
|
||||
|
||||
private void placeCrater( final IMeteoriteWorld w, final int x, final int y, final int z )
|
||||
private int minX(int x) {
|
||||
return x;
|
||||
}
|
||||
private int minZ(int x) {
|
||||
return x;
|
||||
}
|
||||
private int maxX(int x) {
|
||||
return x;
|
||||
}
|
||||
private int maxZ(int x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
private void placeCrater()
|
||||
{
|
||||
final boolean lava = this.settings.getBoolean( "lava" );
|
||||
|
||||
final int maxY = 255;
|
||||
final int minX = w.minX( x - 200 );
|
||||
final int maxX = w.maxX( x + 200 );
|
||||
final int minZ = w.minZ( z - 200 );
|
||||
final int maxZ = w.maxZ( z + 200 );
|
||||
final int minX = minX( x - 200 );
|
||||
final int maxX = maxX( x + 200 );
|
||||
final int minZ = minZ( z - 200 );
|
||||
final int maxZ = maxZ( z + 200 );
|
||||
|
||||
BlockPos.Mutable blockPos = new BlockPos.Mutable();
|
||||
for( int j = y - 5; j < maxY; j++ )
|
||||
{
|
||||
blockPos.setY(j);
|
||||
boolean changed = false;
|
||||
|
||||
for( int i = minX; i < maxX; i++ )
|
||||
{
|
||||
blockPos.setX(i);
|
||||
for( int k = minZ; k < maxZ; k++ )
|
||||
{
|
||||
blockPos.setZ(k);
|
||||
final double dx = i - x;
|
||||
final double dz = k - z;
|
||||
final double h = y - this.meteoriteSize + 1 + this.type.adjustCrater();
|
||||
@@ -181,45 +153,48 @@ public final class MeteoritePlacer
|
||||
|
||||
if( j > h + distanceFrom * 0.02 )
|
||||
{
|
||||
if( lava && j < y && w.getBlockState( i, j, k ).getMaterial().isSolid() )
|
||||
if( lava && j < y && world.getBlockState( blockPos ).getMaterial().isSolid() )
|
||||
{
|
||||
if( j > h + distanceFrom * 0.02 )
|
||||
{
|
||||
this.putter.put( w, i, j, k, Blocks.LAVA );
|
||||
this.putter.put(world, blockPos, Blocks.LAVA.getDefaultState() );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
changed = this.putter.put( w, i, j, k, Platform.AIR_BLOCK ) || changed;
|
||||
changed = this.putter.put(world, blockPos, Platform.AIR_BLOCK.getDefaultState() ) || changed;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for( final Object o : w.getWorld()
|
||||
.getEntitiesWithinAABB( ItemEntity.class,
|
||||
new AxisAlignedBB( w.minX( x - 30 ), y - 5, w.minZ( z - 30 ), w.maxX( x + 30 ), y + 30, w.maxZ( z + 30 ) ) ) )
|
||||
for( final Object o : world.getEntitiesWithinAABB( ItemEntity.class,
|
||||
new AxisAlignedBB( minX( x - 30 ), y - 5, minZ( z - 30 ), maxX( x + 30 ), y + 30, maxZ( z + 30 ) ) ) )
|
||||
{
|
||||
final Entity e = (Entity) o;
|
||||
e.remove();
|
||||
}
|
||||
}
|
||||
|
||||
private void placeMeteorite( final IMeteoriteWorld w, final int x, final int y, final int z )
|
||||
private void placeMeteorite()
|
||||
{
|
||||
|
||||
// spawn meteor
|
||||
this.skyStoneDefinition.maybeBlock().ifPresent( block -> this.placeMeteoriteSkyStone( w, x, y, z, block ) );
|
||||
this.placeMeteoriteSkyStone();
|
||||
|
||||
placeChest();
|
||||
}
|
||||
|
||||
private void placeChest() {
|
||||
if( AEConfig.instance().isFeatureEnabled( AEFeature.SPAWN_PRESSES_IN_METEORITES ) )
|
||||
{
|
||||
this.skyChestDefinition.maybeBlock().ifPresent( block -> this.putter.put( w, x, y, z, block ) );
|
||||
this.putter.put(world, pos, this.skyChestDefinition.block().getDefaultState());
|
||||
|
||||
final TileEntity te = w.getTileEntity( x, y, z );
|
||||
final TileEntity te = world.getTileEntity(pos); // FIXME: this is also probably a band-aid for another issue
|
||||
final InventoryAdaptor ap = InventoryAdaptor.getAdaptor( te, Direction.UP );
|
||||
if( ap != null )
|
||||
if( ap != null && !ap.containsItems() ) // FIXME: band-aid for meteorites being generated multiple times
|
||||
{
|
||||
// TODO: loot tables would be better
|
||||
int primary = Math.max( 1, (int) ( Math.random() * 4 ) );
|
||||
|
||||
if( primary > 3 ) // in case math breaks...
|
||||
@@ -287,14 +262,14 @@ public final class MeteoritePlacer
|
||||
{
|
||||
case 0:
|
||||
final int amount = (int) ( ( Math.random() * SKYSTONE_SPAWN_LIMIT ) + 1 );
|
||||
this.skyStoneDefinition.maybeStack( amount ).ifPresent( ap::addItems );
|
||||
ap.addItems(new ItemStack(skyStoneItem, amount));
|
||||
break;
|
||||
case 1:
|
||||
final List<ItemStack> possibles = new ArrayList<>();
|
||||
possibles.add( new ItemStack( net.minecraft.item.Items.GOLD_NUGGET ) );
|
||||
|
||||
ItemStack nugget = Platform.pickRandom( possibles );
|
||||
if( !nugget.isEmpty() )
|
||||
if( nugget != null && !nugget.isEmpty() )
|
||||
{
|
||||
nugget = nugget.copy();
|
||||
nugget.setCount( (int) ( Math.random() * 12 ) + 1 );
|
||||
@@ -307,63 +282,80 @@ public final class MeteoritePlacer
|
||||
}
|
||||
}
|
||||
|
||||
private void placeMeteoriteSkyStone( IMeteoriteWorld w, int x, int y, int z, Block block )
|
||||
private void placeMeteoriteSkyStone()
|
||||
{
|
||||
final int meteorXLength = w.minX( x - 8 );
|
||||
final int meteorXHeight = w.maxX( x + 8 );
|
||||
final int meteorZLength = w.minZ( z - 8 );
|
||||
final int meteorZHeight = w.maxZ( z + 8 );
|
||||
final int meteorXLength = minX( x - 8 );
|
||||
final int meteorXHeight = maxX( x + 8 );
|
||||
final int meteorZLength = minZ( z - 8 );
|
||||
final int meteorZHeight = maxZ( z + 8 );
|
||||
|
||||
BlockPos.Mutable pos = new BlockPos.Mutable();
|
||||
for( int i = meteorXLength; i < meteorXHeight; i++ )
|
||||
{
|
||||
pos.setX(i);
|
||||
for( int j = y - 8; j < y + 8; j++ )
|
||||
{
|
||||
pos.setY(j);
|
||||
for( int k = meteorZLength; k < meteorZHeight; k++ )
|
||||
{
|
||||
pos.setZ(k);
|
||||
final double dx = i - x;
|
||||
final double dy = j - y;
|
||||
final double dz = k - z;
|
||||
|
||||
if( dx * dx * 0.7 + dy * dy * ( j > y ? 1.4 : 0.8 ) + dz * dz * 0.7 < this.squaredMeteoriteSize )
|
||||
{
|
||||
this.putter.put( w, i, j, k, block );
|
||||
this.putter.put(world, pos, skyStone );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void decay( final IMeteoriteWorld w, final int x, final int y, final int z )
|
||||
private void decay()
|
||||
{
|
||||
double randomShit = 0;
|
||||
|
||||
final int meteorXLength = w.minX( x - 30 );
|
||||
final int meteorXHeight = w.maxX( x + 30 );
|
||||
final int meteorZLength = w.minZ( z - 30 );
|
||||
final int meteorZHeight = w.maxZ( z + 30 );
|
||||
final int meteorXLength = minX( x - 30 );
|
||||
final int meteorXHeight = maxX( x + 30 );
|
||||
final int meteorZLength = minZ( z - 30 );
|
||||
final int meteorZHeight = maxZ( z + 30 );
|
||||
|
||||
BlockPos.Mutable blockPos = new BlockPos.Mutable();
|
||||
BlockPos.Mutable blockPosUp = new BlockPos.Mutable();
|
||||
BlockPos.Mutable blockPosDown = new BlockPos.Mutable();
|
||||
for( int i = meteorXLength; i < meteorXHeight; i++ )
|
||||
{
|
||||
blockPos.setX(i);
|
||||
blockPosUp.setX(i);
|
||||
blockPosDown.setX(i);
|
||||
for( int k = meteorZLength; k < meteorZHeight; k++ )
|
||||
{
|
||||
blockPos.setZ(k);
|
||||
blockPosUp.setZ(k);
|
||||
blockPosDown.setZ(k);
|
||||
for( int j = y - 9; j < y + 30; j++ )
|
||||
{
|
||||
Block blk = w.getBlock( i, j, k );
|
||||
blockPos.setY(j);
|
||||
blockPosUp.setY(j + 1);
|
||||
blockPosDown.setY(j - 1);
|
||||
BlockState state = world.getBlockState( blockPos );
|
||||
Block blk = world.getBlockState( blockPos ).getBlock();
|
||||
if( blk == Blocks.LAVA )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if( blk.isReplaceable( w.getWorld(), new BlockPos( i, j, k ) ) )
|
||||
// TODO reconsider
|
||||
if( state.canBeReplacedByLogs( world, new BlockPos( blockPos ) ) )
|
||||
{
|
||||
blk = Platform.AIR_BLOCK;
|
||||
final Block blk_b = w.getBlock( i, j + 1, k );
|
||||
final Block blk_b = world.getBlockState( blockPosUp ).getBlock();
|
||||
|
||||
if( blk_b != blk )
|
||||
{
|
||||
final BlockState meta_b = w.getBlockState( i, j + 1, k );
|
||||
|
||||
w.setBlock( i, j, k, meta_b, 3 );
|
||||
final BlockState stateUp = world.getBlockState( blockPosUp );
|
||||
world.setBlockState( blockPos, stateUp, 3 );
|
||||
}
|
||||
else if( randomShit < 100 * this.crater )
|
||||
{
|
||||
@@ -372,16 +364,16 @@ public final class MeteoritePlacer
|
||||
final double dz = k - z;
|
||||
final double dist = dx * dx + dy * dy + dz * dz;
|
||||
|
||||
final Block xf = w.getBlock( i, j - 1, k );
|
||||
if( !xf.isReplaceable( w.getWorld(), new BlockPos( i, j - 1, k ) ) )
|
||||
final BlockState xf = world.getBlockState( blockPosDown );
|
||||
if( !xf.canBeReplacedByLogs( world, blockPosDown ) )
|
||||
{
|
||||
final double extraRange = Math.random() * 0.6;
|
||||
final double height = this.crater * ( extraRange + 0.2 ) - Math.abs( dist - this.crater * 1.7 );
|
||||
|
||||
if( xf != blk && height > 0 && Math.random() > 0.6 )
|
||||
if( xf.getBlock() != blk && height > 0 && Math.random() > 0.6 )
|
||||
{
|
||||
randomShit++;
|
||||
this.type.getRandomFall( w, i, j, k );
|
||||
this.type.getRandomFall(world, blockPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -389,8 +381,7 @@ public final class MeteoritePlacer
|
||||
else
|
||||
{
|
||||
// decay.
|
||||
final Block blk_b = w.getBlock( i, j + 1, k );
|
||||
if( blk_b == Platform.AIR_BLOCK )
|
||||
if( world.isAirBlock(blockPosUp) )
|
||||
{
|
||||
if( Math.random() > 0.4 )
|
||||
{
|
||||
@@ -400,7 +391,7 @@ public final class MeteoritePlacer
|
||||
|
||||
if( dx * dx + dy * dy + dz * dz < this.crater * 1.6 )
|
||||
{
|
||||
this.type.getRandomInset( w, i, j, k );
|
||||
this.type.getRandomInset(world, blockPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -410,151 +401,23 @@ public final class MeteoritePlacer
|
||||
}
|
||||
}
|
||||
|
||||
double getSqDistance( final int x, final int z )
|
||||
{
|
||||
final int chunkX = this.settings.getInt( "x" ) - x;
|
||||
final int chunkZ = this.settings.getInt( "z" ) - z;
|
||||
|
||||
return chunkX * chunkX + chunkZ * chunkZ;
|
||||
private Fallout getFalloutFromBaseBlock(IWorld w, BlockPos pos, ResourceLocation blk) {
|
||||
if( blk.equals(Blocks.SAND.getRegistryName()) )
|
||||
{
|
||||
return new FalloutSand( w, pos, this.putter, this.skyStone );
|
||||
}
|
||||
else if( blk.equals(Blocks.TERRACOTTA.getRegistryName()) )
|
||||
{
|
||||
return new FalloutCopy( w, pos, this.putter, this.skyStone );
|
||||
}
|
||||
else if( blk.equals(Blocks.ICE.getRegistryName()) || blk.equals(Blocks.SNOW.getRegistryName()) )
|
||||
{
|
||||
return new FalloutSnow( w, pos, this.putter, this.skyStone );
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Fallout( this.putter, this.skyStone );
|
||||
}
|
||||
}
|
||||
|
||||
public boolean spawnMeteorite( final IMeteoriteWorld w, final int x, final int y, final int z )
|
||||
{
|
||||
|
||||
if( !w.isNether() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Block blk = w.getBlock( x, y, z );
|
||||
if( !this.validSpawn.contains( blk ) )
|
||||
{
|
||||
return false; // must spawn on a valid block..
|
||||
}
|
||||
|
||||
this.settings = new CompoundNBT();
|
||||
this.settings.putInt( "x", x );
|
||||
this.settings.putInt( "y", y );
|
||||
this.settings.putInt( "z", z );
|
||||
this.settings.putString( "blk", blk.getRegistryName().toString() );
|
||||
|
||||
this.settings.putDouble( "real_sizeOfMeteorite", this.meteoriteSize );
|
||||
this.settings.putDouble( "realCrater", this.realCrater );
|
||||
this.settings.putDouble( "sizeOfMeteorite", this.squaredMeteoriteSize );
|
||||
this.settings.putDouble( "crater", this.crater );
|
||||
|
||||
this.settings.putBoolean( "lava", Math.random() > 0.9 );
|
||||
|
||||
if( blk == Blocks.SAND )
|
||||
{
|
||||
this.type = new FalloutSand( w, x, y, z, this.putter, this.skyStoneDefinition );
|
||||
}
|
||||
else if( blk == Blocks.TERRACOTTA )
|
||||
{
|
||||
this.type = new FalloutCopy( w, x, y, z, this.putter, this.skyStoneDefinition );
|
||||
}
|
||||
else if( blk == Blocks.ICE || blk == Blocks.SNOW )
|
||||
{
|
||||
this.type = new FalloutSnow( w, x, y, z, this.putter, this.skyStoneDefinition );
|
||||
}
|
||||
|
||||
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( this.validSpawn.contains( blk ) )
|
||||
{
|
||||
realValidBlocks++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int validBlocks = 0;
|
||||
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( this.invalidSpawn.contains( blk ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if( this.validSpawn.contains( blk ) )
|
||||
{
|
||||
validBlocks++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final int minBlocks = 200;
|
||||
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_BLOCK )
|
||||
{
|
||||
solid = false;
|
||||
}
|
||||
}
|
||||
|
||||
if( !solid )
|
||||
{
|
||||
skyMode = 0;
|
||||
}
|
||||
|
||||
// creator
|
||||
if( skyMode > 10 )
|
||||
{
|
||||
this.placeCrater( w, x, y, z );
|
||||
}
|
||||
|
||||
this.placeMeteorite( w, x, y, z );
|
||||
|
||||
// collapse blocks...
|
||||
if( skyMode > 3 )
|
||||
{
|
||||
this.decay( w, x, y, z );
|
||||
}
|
||||
|
||||
this.settings.putInt( "skyMode", skyMode );
|
||||
w.done();
|
||||
|
||||
WorldData.instance().spawnData().addNearByMeteorites( w.getWorld().getDimension(), x >> 4, z >> 4, this.settings );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
CompoundNBT getSettings()
|
||||
{
|
||||
return this.settings;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
package appeng.worldgen;
|
||||
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.INBT;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import net.minecraft.world.storage.WorldSavedData;
|
||||
import net.minecraftforge.fml.server.ServerLifecycleHooks;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* This is per-world data to track where Meteorites have been spawned.
|
||||
*/
|
||||
public final class MeteoriteSpawnData {
|
||||
|
||||
private static final String NAME = "ae2_meteorite_spawns";
|
||||
|
||||
private final SavedData data;
|
||||
|
||||
private MeteoriteSpawnData(SavedData data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public void setGenerated( int chunkX, int chunkZ ) {
|
||||
synchronized (data) {
|
||||
// edit.
|
||||
data.generated.putBoolean(chunkX + "," + chunkZ, true);
|
||||
data.markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasGenerated( int chunkX, int chunkZ ) {
|
||||
synchronized( data )
|
||||
{
|
||||
return data.generated.getBoolean( chunkX + "," + chunkZ );
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private CompoundNBT getSpawnData(int chunkX, int chunkZ, boolean create) {
|
||||
chunkX /= 16;
|
||||
chunkZ /= 16;
|
||||
String key = chunkX + "," + chunkZ;
|
||||
INBT inbt = data.spawns.get(key);
|
||||
if (!(inbt instanceof CompoundNBT)) {
|
||||
if (create) {
|
||||
inbt = new CompoundNBT();
|
||||
data.spawns.put(key, inbt);
|
||||
data.markDirty();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return (CompoundNBT) inbt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether another meteorite has spawned within the given block range of the given position.
|
||||
*/
|
||||
public boolean isMeteoriteSpawnInRange(BlockPos pos, int rangeSquared) {
|
||||
synchronized( data )
|
||||
{
|
||||
ChunkPos chunkPos = new ChunkPos(pos);
|
||||
CompoundNBT spawnData = getSpawnData(chunkPos.x, chunkPos.z, false);
|
||||
if (spawnData == null) {
|
||||
return false;
|
||||
}
|
||||
final int size = spawnData.getInt( "num" );
|
||||
for (int i = 0; i < size; i++) {
|
||||
CompoundNBT existingSettingsNbt = spawnData.getCompound(String.valueOf(i));
|
||||
BlockPos existingPos = PlacedMeteoriteSettings.read(existingSettingsNbt).getPos();
|
||||
int deltaX = (existingPos.getX() - pos.getX());
|
||||
int deltaZ = (existingPos.getZ() - pos.getZ());
|
||||
if (deltaX * deltaX + deltaZ * deltaZ <= rangeSquared) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean tryAddSpawnedMeteorite(PlacedMeteoriteSettings settings, int minDistanceSquared) {
|
||||
synchronized( data )
|
||||
{
|
||||
if (isMeteoriteSpawnInRange(settings.getPos(), minDistanceSquared)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
addSpawnedMeteorite(settings);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void addSpawnedMeteorite(PlacedMeteoriteSettings settings) {
|
||||
synchronized( data )
|
||||
{
|
||||
ChunkPos chunkPos = new ChunkPos(settings.getPos());
|
||||
CompoundNBT spawnData = getSpawnData(chunkPos.x, chunkPos.z, true);
|
||||
final int size = spawnData.getInt( "num" );
|
||||
spawnData.put( String.valueOf( size ), settings.write(new CompoundNBT()) );
|
||||
spawnData.putInt( "num", size + 1 );
|
||||
data.markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<PlacedMeteoriteSettings> getNearByMeteorites(int chunkX, int chunkZ) {
|
||||
final Collection<PlacedMeteoriteSettings> ll = new ArrayList<>();
|
||||
|
||||
synchronized( data )
|
||||
{
|
||||
for( int x = -1; x <= 1; x++ )
|
||||
{
|
||||
for( int z = -1; z <= 1; z++ )
|
||||
{
|
||||
final int cx = x + ( chunkX >> 4 );
|
||||
final int cz = z + ( chunkZ >> 4 );
|
||||
|
||||
final CompoundNBT data = getSpawnData( cx << 4, cz << 4, false );
|
||||
|
||||
if( data != null )
|
||||
{
|
||||
// edit.
|
||||
final int size = data.getInt( "num" );
|
||||
for( int s = 0; s < size; s++ )
|
||||
{
|
||||
CompoundNBT settingsNbt = data.getCompound(String.valueOf(s));
|
||||
ll.add(PlacedMeteoriteSettings.read(settingsNbt));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ll;
|
||||
}
|
||||
|
||||
public synchronized static MeteoriteSpawnData get(IWorld world) {
|
||||
ServerWorld serverWorld;
|
||||
if (world instanceof ServerWorld) {
|
||||
serverWorld = (ServerWorld) world;
|
||||
} else {
|
||||
MinecraftServer server = ServerLifecycleHooks.getCurrentServer();
|
||||
serverWorld = server.getWorld(world.getDimension().getType());
|
||||
}
|
||||
|
||||
SavedData savedData = serverWorld.getSavedData().getOrCreate(SavedData::new, NAME);
|
||||
return new MeteoriteSpawnData(savedData);
|
||||
}
|
||||
|
||||
private static class SavedData extends WorldSavedData {
|
||||
|
||||
private CompoundNBT generated;
|
||||
private CompoundNBT spawns;
|
||||
|
||||
public SavedData() {
|
||||
super(NAME);
|
||||
this.generated = new CompoundNBT();
|
||||
this.spawns = new CompoundNBT();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void read(CompoundNBT nbt) {
|
||||
this.generated = nbt.getCompound("generated");
|
||||
this.spawns = nbt.getCompound("spawns");
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized CompoundNBT write(CompoundNBT compound) {
|
||||
compound.put("generated", generated);
|
||||
compound.put("spawns", spawns);
|
||||
return compound;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
package appeng.worldgen;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.definitions.IBlocks;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.worldgen.meteorite.IMeteoriteWorld;
|
||||
import appeng.worldgen.meteorite.StandardWorld;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IWorldReader;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Makes decisions about spawning meteorites in the world.
|
||||
*/
|
||||
public class MeteoriteSpawner {
|
||||
|
||||
private final Set<Block> validSpawn = new HashSet<>();
|
||||
private final Set<Block> invalidSpawn = new HashSet<>();
|
||||
|
||||
public MeteoriteSpawner()
|
||||
{
|
||||
final IBlocks blocks = AEApi.instance().definitions().blocks();
|
||||
|
||||
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.ICE );
|
||||
this.validSpawn.add( Blocks.SNOW );
|
||||
|
||||
this.invalidSpawn.add( blocks.skyStoneBlock().block() );
|
||||
this.invalidSpawn.add( Blocks.IRON_DOOR );
|
||||
this.invalidSpawn.add( Blocks.IRON_BARS );
|
||||
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.JUNGLE_DOOR );
|
||||
this.invalidSpawn.add( Blocks.SPRUCE_DOOR );
|
||||
this.invalidSpawn.add( Blocks.BRICKS );
|
||||
this.invalidSpawn.add( Blocks.CLAY );
|
||||
this.invalidSpawn.add( Blocks.WATER );
|
||||
}
|
||||
|
||||
public PlacedMeteoriteSettings trySpawnMeteoriteAtSuitableHeight(IWorldReader world, int x, int y, int z) {
|
||||
|
||||
for( int tries = 0; tries < 20; tries++ )
|
||||
{
|
||||
PlacedMeteoriteSettings spawned = trySpawnMeteorite(world, new BlockPos(x, y, z));
|
||||
if (spawned != null) {
|
||||
return spawned;
|
||||
}
|
||||
|
||||
y -= 15;
|
||||
if( y < 40 )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PlacedMeteoriteSettings trySpawnMeteorite(IWorldReader world, BlockPos pos )
|
||||
{
|
||||
Block blk = world.getBlockState(pos).getBlock();
|
||||
if( !this.validSpawn.contains( blk ) )
|
||||
{
|
||||
return null; // must spawn on a valid block..
|
||||
}
|
||||
|
||||
double meteoriteSize = ( Math.random() * 6.0 ) + 2;
|
||||
double realCrater = meteoriteSize * 2 + 5;
|
||||
boolean lava = Math.random() > 0.9;
|
||||
|
||||
if (!areSurroundingsSuitable(world, pos)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// we can spawn here!
|
||||
int skyMode = countBlockWithSkyLight(world, pos);
|
||||
|
||||
boolean solid = !isAirBelowSpawnPoint(world, pos);
|
||||
|
||||
if( !solid )
|
||||
{
|
||||
skyMode = 0;
|
||||
}
|
||||
|
||||
return new PlacedMeteoriteSettings(pos, blk.getRegistryName(), lava, skyMode, meteoriteSize, realCrater);
|
||||
}
|
||||
|
||||
private static boolean isAirBelowSpawnPoint(IWorldReader w, BlockPos pos) {
|
||||
BlockPos.Mutable testPos = new BlockPos.Mutable(pos);
|
||||
for( int j = pos.getY() - 15; j < pos.getY() - 1; j++ )
|
||||
{
|
||||
testPos.setY(j);
|
||||
if( w.isAirBlock(testPos) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private int countBlockWithSkyLight(IWorldReader w, BlockPos pos) {
|
||||
int skyMode = 0;
|
||||
|
||||
BlockPos.Mutable testPos = new BlockPos.Mutable();
|
||||
for( int i = pos.getX() - 15; i < pos.getX() + 15; i++ )
|
||||
{
|
||||
testPos.setX(i);
|
||||
for( int j = pos.getY() - 15; j < pos.getY() + 11; j++ )
|
||||
{
|
||||
testPos.setY(j);
|
||||
for( int k = pos.getZ() - 15; k < pos.getZ() + 15; k++ )
|
||||
{
|
||||
testPos.setZ(k);
|
||||
if( w.canBlockSeeSky( testPos ) )
|
||||
{
|
||||
skyMode++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return skyMode;
|
||||
}
|
||||
|
||||
private boolean areSurroundingsSuitable(IWorldReader w, BlockPos pos) {
|
||||
int realValidBlocks = 0;
|
||||
|
||||
BlockPos.Mutable testPos = new BlockPos.Mutable();
|
||||
for( int i = pos.getX() - 6; i < pos.getX() + 6; i++ )
|
||||
{
|
||||
testPos.setX(i);
|
||||
for( int j = pos.getY() - 6; j < pos.getY() + 6; j++ )
|
||||
{
|
||||
testPos.setY(j);
|
||||
for( int k = pos.getZ() - 6; k < pos.getZ() + 6; k++ )
|
||||
{
|
||||
testPos.setZ(k);
|
||||
Block testBlk = w.getBlockState(testPos).getBlock();
|
||||
if( this.validSpawn.contains( testBlk ) )
|
||||
{
|
||||
realValidBlocks++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int validBlocks = 0;
|
||||
for( int i = pos.getX() - 15; i < pos.getX() + 15; i++ )
|
||||
{
|
||||
testPos.setX(i);
|
||||
for( int j = pos.getY() - 15; j < pos.getY() + 15; j++ )
|
||||
{
|
||||
testPos.setY(j);
|
||||
for( int k = pos.getZ() - 15; k < pos.getZ() + 15; k++ )
|
||||
{
|
||||
testPos.setZ(k);
|
||||
Block testBlk = w.getBlockState( testPos ).getBlock();
|
||||
if( this.invalidSpawn.contains( testBlk ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if( this.validSpawn.contains( testBlk ) )
|
||||
{
|
||||
validBlocks++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final int minBlocks = 200;
|
||||
return validBlocks > minBlocks && realValidBlocks > 80;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,134 +19,91 @@
|
||||
package appeng.worldgen;
|
||||
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.IChunkProvider;
|
||||
import net.minecraft.world.gen.IChunkGenerator;
|
||||
import net.minecraftforge.fml.common.IWorldGenerator;
|
||||
|
||||
import appeng.api.features.AEFeature;
|
||||
import appeng.api.features.IWorldGen.WorldGenType;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.features.registries.WorldGenRegistry;
|
||||
import appeng.core.worlddata.WorldData;
|
||||
import appeng.hooks.TickHandler;
|
||||
import appeng.util.IWorldCallable;
|
||||
import appeng.util.Platform;
|
||||
import appeng.worldgen.meteorite.ChunkOnly;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.gen.ChunkGenerator;
|
||||
import net.minecraft.world.gen.GenerationSettings;
|
||||
import net.minecraft.world.gen.feature.Feature;
|
||||
import net.minecraft.world.gen.feature.NoFeatureConfig;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
public final class MeteoriteWorldGen implements IWorldGenerator
|
||||
public final class MeteoriteWorldGen extends Feature<NoFeatureConfig>
|
||||
{
|
||||
|
||||
public static final MeteoriteWorldGen INSTANCE = new MeteoriteWorldGen();
|
||||
|
||||
private MeteoriteWorldGen( )
|
||||
{
|
||||
super( NoFeatureConfig::deserialize );
|
||||
setRegistryName( AppEng.MOD_ID, "meteorite" );
|
||||
}
|
||||
|
||||
private final MeteoriteSpawner spawner = new MeteoriteSpawner();
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
@Override
|
||||
public void generate( final Random r, final int chunkX, final int chunkZ, final World w, final IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider )
|
||||
public boolean place( IWorld w, ChunkGenerator<? extends GenerationSettings> generator, Random r, BlockPos pos, NoFeatureConfig config )
|
||||
{
|
||||
if( WorldGenRegistry.INSTANCE.isWorldGenEnabled( WorldGenType.METEORITES, w ) )
|
||||
{
|
||||
final int x = r.nextInt( 16 ) + ( chunkX << 4 );
|
||||
final int z = r.nextInt( 16 ) + ( chunkZ << 4 );
|
||||
final int depth = AEConfig.instance().getMeteoriteMaximumSpawnHeight() + r.nextInt( 20 );
|
||||
|
||||
TickHandler.INSTANCE.addCallable( w, new MeteoriteSpawn( x, depth, z ) );
|
||||
if(!AEConfig.instance().isFeatureEnabled( AEFeature.METEORITE_WORLD_GEN )) {
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
WorldData.instance().compassData().service().updateArea( w, chunkX, chunkZ );
|
||||
|
||||
ChunkPos chunkPos = new ChunkPos( pos );
|
||||
if (!WorldGenRegistry.INSTANCE.isWorldGenEnabled(WorldGenType.METEORITES, w.getWorld())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean tryMeteorite( final World w, int depth, final int x, final int z )
|
||||
{
|
||||
for( int tries = 0; tries < 20; tries++ )
|
||||
double minSqDist = Double.MAX_VALUE;
|
||||
|
||||
MeteoriteSpawnData spawnData = MeteoriteSpawnData.get(w);
|
||||
|
||||
// near by meteorites!
|
||||
for( final PlacedMeteoriteSettings data : spawnData.getNearByMeteorites(chunkPos.x, chunkPos.z) )
|
||||
{
|
||||
final MeteoritePlacer mp = new MeteoritePlacer();
|
||||
minSqDist = Math.min( minSqDist, getSqDistance( data, pos ) );
|
||||
}
|
||||
|
||||
if( mp.spawnMeteorite( new ChunkOnly( w, x >> 4, z >> 4 ), x, depth, z ) )
|
||||
{
|
||||
final int px = x >> 4;
|
||||
final int pz = z >> 4;
|
||||
final boolean isCluster = ( minSqDist < 30 * 30 ) && Platform.getRandomFloat() < AEConfig.instance().getMeteoriteClusterChance();
|
||||
|
||||
for( int cx = px - 6; cx < px + 6; cx++ )
|
||||
{
|
||||
for( int cz = pz - 6; cz < pz + 6; cz++ )
|
||||
{
|
||||
if( w.getChunkProvider().getLoadedChunk( cx, cz ) != null )
|
||||
{
|
||||
if( px == cx && pz == cz )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if( minSqDist > AEConfig.instance().getMinMeteoriteDistanceSq() || isCluster )
|
||||
{
|
||||
final int x = r.nextInt( 16 ) + ( chunkPos.x << 4 );
|
||||
final int y = AEConfig.instance().getMeteoriteMaximumSpawnHeight() + r.nextInt( 20 );
|
||||
final int z = r.nextInt( 16 ) + ( chunkPos.z << 4 );
|
||||
|
||||
if( WorldData.instance().spawnData().hasGenerated( w.provider.getDimension(), cx, cz ) )
|
||||
{
|
||||
final MeteoritePlacer mp2 = new MeteoritePlacer();
|
||||
mp2.spawnMeteorite( new ChunkOnly( w, cx, cz ), mp.getSettings() );
|
||||
}
|
||||
}
|
||||
}
|
||||
PlacedMeteoriteSettings settings = spawner.trySpawnMeteoriteAtSuitableHeight(w, x, y, z);
|
||||
if (settings != null) {
|
||||
// Double check that no other chunk generated a meteorite within range while we were working
|
||||
int checkRange = isCluster ? (30*30) : AEConfig.instance().getMinMeteoriteDistanceSq();
|
||||
if (spawnData.tryAddSpawnedMeteorite(settings, checkRange)) {
|
||||
MeteoritePlacer placer = new MeteoritePlacer(w, settings);
|
||||
placer.place();
|
||||
WorldData.instance().compassData().service().updateArea( w, chunkPos.x, chunkPos.z );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
depth -= 15;
|
||||
if( depth < 40 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
spawnData.setGenerated( chunkPos.x, chunkPos.z );
|
||||
return true;
|
||||
}
|
||||
|
||||
private Iterable<CompoundNBT> getNearByMeteorites( final World w, final int chunkX, final int chunkZ )
|
||||
private static double getSqDistance( PlacedMeteoriteSettings placed, BlockPos pos )
|
||||
{
|
||||
return WorldData.instance().spawnData().getNearByMeteorites( w.provider.getDimension(), chunkX, chunkZ );
|
||||
final int chunkX = placed.getPos().getX() - pos.getX();
|
||||
final int chunkZ = placed.getPos().getZ() - pos.getZ();
|
||||
return chunkX * chunkX + chunkZ * chunkZ;
|
||||
}
|
||||
|
||||
private class MeteoriteSpawn implements IWorldCallable<Object>
|
||||
{
|
||||
|
||||
private final int x;
|
||||
private final int z;
|
||||
private final int depth;
|
||||
|
||||
public MeteoriteSpawn( final int x, final int depth, final int z )
|
||||
{
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
this.depth = depth;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object call( final World world ) throws Exception
|
||||
{
|
||||
final int chunkX = this.x >> 4;
|
||||
final int chunkZ = this.z >> 4;
|
||||
|
||||
double minSqDist = Double.MAX_VALUE;
|
||||
|
||||
// near by meteorites!
|
||||
for( final CompoundNBT data : MeteoriteWorldGen.this.getNearByMeteorites( world, chunkX, chunkZ ) )
|
||||
{
|
||||
final MeteoritePlacer mp = new MeteoritePlacer();
|
||||
mp.spawnMeteorite( new ChunkOnly( world, chunkX, chunkZ ), data );
|
||||
|
||||
minSqDist = Math.min( minSqDist, mp.getSqDistance( this.x, this.z ) );
|
||||
}
|
||||
|
||||
final boolean isCluster = ( minSqDist < 30 * 30 ) && Platform.getRandomFloat() < AEConfig.instance().getMeteoriteClusterChance();
|
||||
|
||||
if( minSqDist > AEConfig.instance().getMinMeteoriteDistanceSq() || isCluster )
|
||||
{
|
||||
MeteoriteWorldGen.this.tryMeteorite( world, this.depth, this.x, this.z );
|
||||
}
|
||||
|
||||
WorldData.instance().spawnData().setGenerated( world.provider.getDimension(), chunkX, chunkZ );
|
||||
WorldData.instance().compassData().service().updateArea( world, chunkX, chunkZ );
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
package appeng.worldgen;
|
||||
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.NBTUtil;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.common.util.INBTSerializable;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public final class PlacedMeteoriteSettings {
|
||||
|
||||
private final BlockPos pos;
|
||||
private final ResourceLocation blk;
|
||||
private final boolean lava;
|
||||
private final int skyMode;
|
||||
private final double meteoriteRadius;
|
||||
private final double craterRadius;
|
||||
|
||||
public PlacedMeteoriteSettings(BlockPos pos, ResourceLocation blk, boolean lava, int skyMode, double meteoriteRadius, double craterRadius) {
|
||||
this.pos = pos;
|
||||
this.blk = blk;
|
||||
this.lava = lava;
|
||||
this.skyMode = skyMode;
|
||||
this.meteoriteRadius = meteoriteRadius;
|
||||
this.craterRadius = craterRadius;
|
||||
}
|
||||
|
||||
public BlockPos getPos() {
|
||||
return pos;
|
||||
}
|
||||
|
||||
public ResourceLocation getBlk() {
|
||||
return blk;
|
||||
}
|
||||
|
||||
public boolean isLava() {
|
||||
return lava;
|
||||
}
|
||||
|
||||
public int getSkyMode() {
|
||||
return skyMode;
|
||||
}
|
||||
|
||||
public double getMeteoriteRadius() {
|
||||
return meteoriteRadius;
|
||||
}
|
||||
|
||||
public double getCraterRadius() {
|
||||
return craterRadius;
|
||||
}
|
||||
|
||||
public CompoundNBT write(CompoundNBT tag) {
|
||||
tag.putInt("x", pos.getX());
|
||||
tag.putInt("y", pos.getY());
|
||||
tag.putInt("z", pos.getZ());
|
||||
tag.putString( "blk", blk.toString() );
|
||||
|
||||
tag.putDouble( "meteoriteRadius", meteoriteRadius );
|
||||
tag.putDouble( "craterRadius", craterRadius );
|
||||
|
||||
tag.putBoolean( "lava", lava );
|
||||
tag.putInt( "skyMode", skyMode );
|
||||
return tag;
|
||||
}
|
||||
|
||||
public static PlacedMeteoriteSettings read(CompoundNBT tag) {
|
||||
BlockPos pos = new BlockPos(tag.getInt("x"), tag.getInt("y"), tag.getInt("z"));
|
||||
ResourceLocation blk = new ResourceLocation(tag.getString("blk"));
|
||||
double meteoriteRadius = tag.getDouble("meteoriteRadius");
|
||||
double craterRadius = tag.getDouble("craterRadius");
|
||||
boolean lava = tag.getBoolean("lava");
|
||||
int skyMode = tag.getInt("skyMode");
|
||||
|
||||
return new PlacedMeteoriteSettings(pos, blk, lava, skyMode, meteoriteRadius, craterRadius);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,60 +19,75 @@
|
||||
package appeng.worldgen;
|
||||
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.AbstractChunkProvider;
|
||||
import net.minecraft.world.gen.ChunkGenerator;
|
||||
import net.minecraft.world.gen.feature.WorldGenMinable;
|
||||
import net.minecraftforge.fml.common.IWorldGenerator;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.definitions.IBlockDefinition;
|
||||
import appeng.api.definitions.IBlocks;
|
||||
import appeng.api.features.IWorldGen.WorldGenType;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.features.registries.WorldGenRegistry;
|
||||
import com.mojang.datafixers.Dynamic;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.gen.ChunkGenerator;
|
||||
import net.minecraft.world.gen.GenerationSettings;
|
||||
import net.minecraft.world.gen.feature.ReplaceBlockConfig;
|
||||
import net.minecraft.world.gen.feature.ReplaceBlockFeature;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.function.Function;
|
||||
|
||||
|
||||
public final class QuartzWorldGen implements IWorldGenerator
|
||||
public final class QuartzWorldGen extends ReplaceBlockFeature
|
||||
{
|
||||
/*
|
||||
private final WorldGenMinable oreNormal;
|
||||
private final WorldGenMinable oreCharged;
|
||||
*/
|
||||
|
||||
public QuartzWorldGen()
|
||||
public QuartzWorldGen( Function<Dynamic<?>, ? extends ReplaceBlockConfig> serializer )
|
||||
{
|
||||
super(serializer);
|
||||
final IBlocks blocks = AEApi.instance().definitions().blocks();
|
||||
final IBlockDefinition oreDefinition = blocks.quartzOre();
|
||||
final IBlockDefinition chargedDefinition = blocks.quartzOreCharged();
|
||||
|
||||
/*
|
||||
this.oreNormal = oreDefinition.maybeBlock()
|
||||
.map( b -> new WorldGenMinable( b.getDefaultState(), AEConfig.instance().getQuartzOresPerCluster() ) )
|
||||
.orElse( null );
|
||||
this.oreCharged = chargedDefinition.maybeBlock()
|
||||
.map( b -> new WorldGenMinable( b.getDefaultState(), AEConfig.instance().getQuartzOresPerCluster() ) )
|
||||
.orElse( null );
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generate(final Random r, final int chunkX, final int chunkZ, final World w, final ChunkGenerator chunkGenerator, final AbstractChunkProvider chunkProvider )
|
||||
private static boolean shouldGenerate( final boolean isCharged, final World w )
|
||||
{
|
||||
return WorldGenRegistry.INSTANCE.isWorldGenEnabled( isCharged ? WorldGenType.CHARGED_CERTUS_QUARTZ : WorldGenType.CERTUS_QUARTZ, w );
|
||||
}
|
||||
|
||||
@Override public boolean place( IWorld worldIn, ChunkGenerator<? extends GenerationSettings> generator, Random r, BlockPos pos, ReplaceBlockConfig config )
|
||||
{
|
||||
/*
|
||||
if( this.oreNormal == null && this.oreCharged == null )
|
||||
{
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
int seaLevel = w.provider.getAverageGroundLevel() + 1;
|
||||
World w = worldIn.getWorld();
|
||||
|
||||
int seaLevel = w.getSeaLevel();
|
||||
|
||||
ChunkPos chunkPos = new ChunkPos( pos );
|
||||
|
||||
if( seaLevel < 20 )
|
||||
{
|
||||
final int x = ( chunkX << 4 ) + 8;
|
||||
final int z = ( chunkZ << 4 ) + 8;
|
||||
seaLevel = w.getHeight( x, z );
|
||||
final int x = ( chunkPos.x << 4 ) + 8;
|
||||
final int z = ( chunkPos.z << 4 ) + 8;
|
||||
seaLevel = w.getHeight( Heightmap.Type.WORLD_SURFACE, x, z );
|
||||
}
|
||||
|
||||
final double oreDepthMultiplier = AEConfig.instance().getQuartzOresClusterAmount() * seaLevel / 64;
|
||||
final int oreDepthMultiplier = AEConfig.instance().getQuartzOresClusterAmount() * seaLevel / 64;
|
||||
final int scale = (int) Math.round( r.nextGaussian() * Math.sqrt( oreDepthMultiplier ) + oreDepthMultiplier );
|
||||
|
||||
for( int cnt = 0; cnt < ( r.nextBoolean() ? scale * 2 : scale ) / 2; ++cnt )
|
||||
@@ -87,16 +102,14 @@ public final class QuartzWorldGen implements IWorldGenerator
|
||||
final WorldGenMinable whichOre = isCharged ? this.oreCharged : this.oreNormal;
|
||||
if( whichOre != null && shouldGenerate( isCharged, w ) )
|
||||
{
|
||||
final int cx = chunkX * 16 + r.nextInt( 16 );
|
||||
final int cx = chunkPos.x * 16 + r.nextInt( 16 );
|
||||
final int cy = r.nextInt( 40 * seaLevel / 64 ) + r.nextInt( 22 * seaLevel / 64 ) + 12 * seaLevel / 64;
|
||||
final int cz = chunkZ * 16 + r.nextInt( 16 );
|
||||
final int cz = chunkPos.z * 16 + r.nextInt( 16 );
|
||||
whichOre.generate( w, r, new BlockPos( cx, cy, cz ) );
|
||||
}
|
||||
}
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean shouldGenerate( final boolean isCharged, final World w )
|
||||
{
|
||||
return WorldGenRegistry.INSTANCE.isWorldGenEnabled( isCharged ? WorldGenType.CHARGED_CERTUS_QUARTZ : WorldGenType.CERTUS_QUARTZ, w );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,21 +22,22 @@ package appeng.worldgen.meteorite;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
import appeng.util.Platform;
|
||||
import net.minecraft.world.chunk.IChunk;
|
||||
|
||||
|
||||
public class ChunkOnly extends StandardWorld
|
||||
{
|
||||
|
||||
private final Chunk target;
|
||||
private final IChunk target;
|
||||
private final int cx;
|
||||
private final int cz;
|
||||
private int verticalBits = 0;
|
||||
|
||||
public ChunkOnly( final World w, final int cx, final int cz )
|
||||
public ChunkOnly(final IWorld w, final int cx, final int cz )
|
||||
{
|
||||
super( w );
|
||||
this.target = w.getChunk( cx, cz );
|
||||
@@ -68,48 +69,42 @@ public class ChunkOnly extends StandardWorld
|
||||
return Math.min( in, ( this.cz + 1 ) << 4 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getBlock( final int x, final int y, final int z )
|
||||
@Override
|
||||
public boolean contains(BlockPos pos) {
|
||||
return this.range(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getBlock( BlockPos pos )
|
||||
{
|
||||
if( this.range( x, y, z ) )
|
||||
if( this.range( pos ) )
|
||||
{
|
||||
return this.target.getBlockState( new BlockPos(x, y, z) ).getBlock();
|
||||
return this.target.getBlockState( new BlockPos(pos) ).getBlock();
|
||||
}
|
||||
return Platform.AIR_BLOCK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlock( final int x, final int y, final int z, final Block blk )
|
||||
public void setBlock( BlockPos pos, final BlockState blk )
|
||||
{
|
||||
if( this.range( x, y, z ) )
|
||||
if( this.range( pos ) )
|
||||
{
|
||||
this.verticalBits |= 1 << ( y >> 4 );
|
||||
this.getWorld().setBlockState( new BlockPos( x, y, z ), blk.getDefaultState() );
|
||||
target.setBlockState(new BlockPos( pos ), blk, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlock( final int x, final int y, final int z, final BlockState state, final int flags )
|
||||
public void setBlock( BlockPos pos, final BlockState state, final int flags )
|
||||
{
|
||||
if( this.range( x, y, z ) )
|
||||
if( this.range( pos ) )
|
||||
{
|
||||
this.verticalBits |= 1 << ( y >> 4 );
|
||||
this.getWorld().setBlockState( new BlockPos( x, y, z ), state, flags & ( ~2 ) );
|
||||
this.getWorld().setBlockState( new BlockPos( pos ), state, flags & ( ~2 ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void done()
|
||||
public boolean range( BlockPos pos )
|
||||
{
|
||||
if( this.verticalBits != 0 )
|
||||
{
|
||||
Platform.sendChunk( this.target, this.verticalBits );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean range( final int x, final int y, final int z )
|
||||
{
|
||||
return this.cx == ( x >> 4 ) && this.cz == ( z >> 4 );
|
||||
return this.cx == ( pos.getX() >> 4 ) && this.cz == ( pos.getZ() >> 4 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,21 +19,23 @@
|
||||
package appeng.worldgen.meteorite;
|
||||
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
|
||||
import appeng.api.definitions.IBlockDefinition;
|
||||
import appeng.util.Platform;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IWorld;
|
||||
|
||||
|
||||
public class Fallout
|
||||
{
|
||||
private final MeteoriteBlockPutter putter;
|
||||
private final IBlockDefinition skyStoneDefinition;
|
||||
private final BlockState skyStone;
|
||||
|
||||
public Fallout( final MeteoriteBlockPutter putter, final IBlockDefinition skyStoneDefinition )
|
||||
public Fallout( final MeteoriteBlockPutter putter, final BlockState skyStone )
|
||||
{
|
||||
this.putter = putter;
|
||||
this.skyStoneDefinition = skyStoneDefinition;
|
||||
this.skyStone = skyStone;
|
||||
}
|
||||
|
||||
public int adjustCrater()
|
||||
@@ -41,53 +43,53 @@ public class Fallout
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void getRandomFall( final IMeteoriteWorld w, final int x, final int y, final int z )
|
||||
public void getRandomFall(final IWorld w, BlockPos pos )
|
||||
{
|
||||
final double a = Math.random();
|
||||
if( a > 0.9 )
|
||||
{
|
||||
this.putter.put( w, x, y, z, Blocks.STONE );
|
||||
this.putter.put( w, pos, Blocks.STONE.getDefaultState() );
|
||||
}
|
||||
else if( a > 0.8 )
|
||||
{
|
||||
this.putter.put( w, x, y, z, Blocks.COBBLESTONE );
|
||||
this.putter.put( w, pos, Blocks.COBBLESTONE.getDefaultState() );
|
||||
}
|
||||
else if( a > 0.7 )
|
||||
{
|
||||
this.putter.put( w, x, y, z, Blocks.DIRT );
|
||||
this.putter.put( w, pos, Blocks.DIRT.getDefaultState() );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.putter.put( w, x, y, z, Blocks.GRAVEL );
|
||||
this.putter.put( w, pos, Blocks.GRAVEL.getDefaultState() );
|
||||
}
|
||||
}
|
||||
|
||||
public void getRandomInset( final IMeteoriteWorld w, final int x, final int y, final int z )
|
||||
public void getRandomInset( final IWorld w, BlockPos pos )
|
||||
{
|
||||
final double a = Math.random();
|
||||
if( a > 0.9 )
|
||||
{
|
||||
this.putter.put( w, x, y, z, Blocks.COBBLESTONE );
|
||||
this.putter.put( w, pos, Blocks.COBBLESTONE.getDefaultState() );
|
||||
}
|
||||
else if( a > 0.8 )
|
||||
{
|
||||
this.putter.put( w, x, y, z, Blocks.STONE );
|
||||
this.putter.put( w, pos, Blocks.STONE.getDefaultState() );
|
||||
}
|
||||
else if( a > 0.7 )
|
||||
{
|
||||
this.putter.put( w, x, y, z, Blocks.GRASS_BLOCK );
|
||||
this.putter.put( w, pos, Blocks.GRASS_BLOCK.getDefaultState() );
|
||||
}
|
||||
else if( a > 0.6 )
|
||||
{
|
||||
this.skyStoneDefinition.maybeBlock().ifPresent( block -> this.putter.put( w, x, y, z, block ) );
|
||||
this.putter.put( w, pos, this.skyStone );
|
||||
}
|
||||
else if( a > 0.5 )
|
||||
{
|
||||
this.putter.put( w, x, y, z, Blocks.GRAVEL );
|
||||
this.putter.put( w, pos, Blocks.GRAVEL.getDefaultState() );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.putter.put( w, x, y, z, Platform.AIR_BLOCK );
|
||||
this.putter.put( w, pos, Platform.AIR_BLOCK.getDefaultState() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,10 +19,14 @@
|
||||
package appeng.worldgen.meteorite;
|
||||
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
|
||||
import appeng.api.definitions.IBlockDefinition;
|
||||
import appeng.util.Platform;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IWorld;
|
||||
|
||||
|
||||
public class FalloutCopy extends Fallout
|
||||
@@ -34,47 +38,47 @@ public class FalloutCopy extends Fallout
|
||||
private final BlockState block;
|
||||
private final MeteoriteBlockPutter putter;
|
||||
|
||||
public FalloutCopy( final IMeteoriteWorld w, final int x, final int y, final int z, final MeteoriteBlockPutter putter, final IBlockDefinition skyStoneDefinition )
|
||||
public FalloutCopy(final IWorld w, BlockPos pos, final MeteoriteBlockPutter putter, final BlockState skyStone )
|
||||
{
|
||||
super( putter, skyStoneDefinition );
|
||||
super( putter, skyStone );
|
||||
this.putter = putter;
|
||||
this.block = w.getBlockState( x, y, z );
|
||||
this.block = w.getBlockState( pos );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getRandomFall( final IMeteoriteWorld w, final int x, final int y, final int z )
|
||||
public void getRandomFall( final IWorld w, BlockPos pos )
|
||||
{
|
||||
final double a = Math.random();
|
||||
if( a > SPECIFIED_BLOCK_THRESHOLD )
|
||||
{
|
||||
this.putter.put( w, x, y, z, this.block, 3 );
|
||||
this.putter.put( w, pos, this.block );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.getOther( w, x, y, z, a );
|
||||
this.getOther( w, pos, a );
|
||||
}
|
||||
}
|
||||
|
||||
public void getOther( final IMeteoriteWorld w, final int x, final int y, final int z, final double a )
|
||||
public void getOther( final IWorld w, BlockPos pos, final double a )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getRandomInset( final IMeteoriteWorld w, final int x, final int y, final int z )
|
||||
public void getRandomInset( final IWorld w, BlockPos pos )
|
||||
{
|
||||
final double a = Math.random();
|
||||
if( a > SPECIFIED_BLOCK_THRESHOLD )
|
||||
{
|
||||
this.putter.put( w, x, y, z, this.block, 3 );
|
||||
this.putter.put( w, pos, this.block );
|
||||
}
|
||||
else if( a > AIR_BLOCK_THRESHOLD )
|
||||
{
|
||||
this.putter.put( w, x, y, z, Platform.AIR_BLOCK );
|
||||
this.putter.put( w, pos, Blocks.AIR.getDefaultState() );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.getOther( w, x, y, z, a - BLOCK_THRESHOLD_STEP );
|
||||
this.getOther( w, pos, a - BLOCK_THRESHOLD_STEP );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,9 +19,12 @@
|
||||
package appeng.worldgen.meteorite;
|
||||
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
|
||||
import appeng.api.definitions.IBlockDefinition;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IWorld;
|
||||
|
||||
|
||||
public class FalloutSand extends FalloutCopy
|
||||
@@ -29,9 +32,9 @@ public class FalloutSand extends FalloutCopy
|
||||
private static final double GLASS_THRESHOLD = 0.66;
|
||||
private final MeteoriteBlockPutter putter;
|
||||
|
||||
public FalloutSand( final IMeteoriteWorld w, final int x, final int y, final int z, final MeteoriteBlockPutter putter, final IBlockDefinition skyStoneDefinition )
|
||||
public FalloutSand(final IWorld w, BlockPos pos, final MeteoriteBlockPutter putter, final BlockState skyStone )
|
||||
{
|
||||
super( w, x, y, z, putter, skyStoneDefinition );
|
||||
super( w, pos, putter, skyStone );
|
||||
this.putter = putter;
|
||||
}
|
||||
|
||||
@@ -42,11 +45,11 @@ public class FalloutSand extends FalloutCopy
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getOther( final IMeteoriteWorld w, final int x, final int y, final int z, final double a )
|
||||
public void getOther( final IWorld w, BlockPos pos, final double a )
|
||||
{
|
||||
if( a > GLASS_THRESHOLD )
|
||||
{
|
||||
this.putter.put( w, x, y, z, Blocks.GLASS );
|
||||
this.putter.put( w, pos, Blocks.GLASS.getDefaultState() );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,9 +19,12 @@
|
||||
package appeng.worldgen.meteorite;
|
||||
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
|
||||
import appeng.api.definitions.IBlockDefinition;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IWorld;
|
||||
|
||||
|
||||
public class FalloutSnow extends FalloutCopy
|
||||
@@ -30,9 +33,9 @@ public class FalloutSnow extends FalloutCopy
|
||||
private static final double ICE_THRESHOLD = 0.5;
|
||||
private final MeteoriteBlockPutter putter;
|
||||
|
||||
public FalloutSnow( final IMeteoriteWorld w, final int x, final int y, final int z, final MeteoriteBlockPutter putter, final IBlockDefinition skyStoneDefinition )
|
||||
public FalloutSnow(final IWorld w, BlockPos pos, final MeteoriteBlockPutter putter, final BlockState skyStone)
|
||||
{
|
||||
super( w, x, y, z, putter, skyStoneDefinition );
|
||||
super( w, pos, putter, skyStone );
|
||||
this.putter = putter;
|
||||
}
|
||||
|
||||
@@ -43,15 +46,15 @@ public class FalloutSnow extends FalloutCopy
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getOther( final IMeteoriteWorld w, final int x, final int y, final int z, final double a )
|
||||
public void getOther( final IWorld w, BlockPos pos, final double a )
|
||||
{
|
||||
if( a > SNOW_THRESHOLD )
|
||||
{
|
||||
this.putter.put( w, x, y, z, Blocks.SNOW );
|
||||
this.putter.put( w, pos, Blocks.SNOW.getDefaultState() );
|
||||
}
|
||||
else if( a > ICE_THRESHOLD )
|
||||
{
|
||||
this.putter.put( w, x, y, z, Blocks.ICE );
|
||||
this.putter.put( w, pos, Blocks.ICE.getDefaultState() );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,8 @@ package appeng.worldgen.meteorite;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
|
||||
@@ -35,21 +37,19 @@ public interface IMeteoriteWorld
|
||||
|
||||
int maxZ( int in );
|
||||
|
||||
boolean isNether();
|
||||
boolean contains( BlockPos pos );
|
||||
|
||||
Block getBlock( int x, int y, int z );
|
||||
Block getBlock( BlockPos pos );
|
||||
|
||||
boolean canBlockSeeTheSky( int i, int j, int k );
|
||||
boolean canBlockSeeTheSky( BlockPos pos );
|
||||
|
||||
TileEntity getTileEntity( int x, int y, int z );
|
||||
TileEntity getTileEntity( BlockPos pos );
|
||||
|
||||
World getWorld();
|
||||
IWorld getWorld();
|
||||
|
||||
void setBlock( int i, int j, int k, Block blk );
|
||||
void setBlock( BlockPos pos, final BlockState state, final int flags );
|
||||
|
||||
void setBlock( int i, int j, int k, BlockState state, int l );
|
||||
void setBlock( BlockPos pos, BlockState blk );
|
||||
|
||||
void done();
|
||||
|
||||
BlockState getBlockState( int x, int y, int z );
|
||||
BlockState getBlockState( BlockPos pos );
|
||||
}
|
||||
@@ -22,30 +22,23 @@ package appeng.worldgen.meteorite;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IWorld;
|
||||
|
||||
|
||||
public class MeteoriteBlockPutter
|
||||
{
|
||||
public boolean put( final IMeteoriteWorld w, final int i, final int j, final int k, final Block blk )
|
||||
public boolean put(final IWorld w, BlockPos pos, final BlockState blk )
|
||||
{
|
||||
final Block original = w.getBlock( i, j, k );
|
||||
final BlockState original = w.getBlockState( pos );
|
||||
|
||||
if( original == Blocks.BEDROCK || original == blk )
|
||||
if( original.getBlock() == Blocks.BEDROCK || original == blk )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
w.setBlock( i, j, k, blk );
|
||||
w.setBlockState(pos, blk, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
void put( final IMeteoriteWorld w, final int i, final int j, final int k, final BlockState state, final int meta )
|
||||
{
|
||||
if( w.getBlock( i, j, k ) == Blocks.BEDROCK )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
w.setBlock( i, j, k, state, 3 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.util.Platform;
|
||||
@@ -32,9 +33,9 @@ import appeng.util.Platform;
|
||||
public class StandardWorld implements IMeteoriteWorld
|
||||
{
|
||||
|
||||
private final World w;
|
||||
private final IWorld w;
|
||||
|
||||
public StandardWorld( final World w )
|
||||
public StandardWorld( final IWorld w )
|
||||
{
|
||||
this.w = w;
|
||||
}
|
||||
@@ -64,82 +65,76 @@ public class StandardWorld implements IMeteoriteWorld
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNether()
|
||||
{
|
||||
return !this.getWorld().provider.isNether();
|
||||
public boolean contains(BlockPos pos) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getBlock( final int x, final int y, final int z )
|
||||
public Block getBlock( BlockPos pos )
|
||||
{
|
||||
if( this.range( x, y, z ) )
|
||||
if( this.range( pos ) )
|
||||
{
|
||||
return this.getWorld().getBlockState( new BlockPos( x, y, z ) ).getBlock();
|
||||
return this.getWorld().getBlockState( new BlockPos( pos ) ).getBlock();
|
||||
}
|
||||
return Platform.AIR_BLOCK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBlockSeeTheSky( final int x, final int y, final int z )
|
||||
public boolean canBlockSeeTheSky( BlockPos pos )
|
||||
{
|
||||
if( this.range( x, y, z ) )
|
||||
if( this.range( pos ) )
|
||||
{
|
||||
return this.getWorld().canBlockSeeSky( new BlockPos( x, y, z ) );
|
||||
return this.getWorld().canBlockSeeSky( new BlockPos( pos ) );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getTileEntity( final int x, final int y, final int z )
|
||||
public TileEntity getTileEntity( BlockPos pos )
|
||||
{
|
||||
if( this.range( x, y, z ) )
|
||||
if( this.range( pos ) )
|
||||
{
|
||||
return this.getWorld().getTileEntity( new BlockPos( x, y, z ) );
|
||||
return this.getWorld().getTileEntity( new BlockPos( pos ) );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld()
|
||||
public IWorld getWorld()
|
||||
{
|
||||
return this.w;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlock( final int x, final int y, final int z, final Block blk )
|
||||
public void setBlock( BlockPos pos, final BlockState blk )
|
||||
{
|
||||
if( this.range( x, y, z ) )
|
||||
if( this.range( pos ) )
|
||||
{
|
||||
this.getWorld().setBlockState( new BlockPos( x, y, z ), blk.getDefaultState() );
|
||||
// FIXME: Attempt at reducing impact of placing meteors by passing 16|32 here
|
||||
this.getWorld().setBlockState( new BlockPos( pos ), blk, 16|32 );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void done()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public boolean range( final int x, final int y, final int z )
|
||||
public boolean range( BlockPos pos )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlock( final int x, final int y, final int z, final BlockState state, final int l )
|
||||
public void setBlock( BlockPos pos, final BlockState state, final int l )
|
||||
{
|
||||
if( this.range( x, y, z ) )
|
||||
if( this.range( pos ) )
|
||||
{
|
||||
this.w.setBlockState( new BlockPos( x, y, z ), state, l );
|
||||
this.w.setBlockState( new BlockPos( pos ), state, l );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlockState( final int x, final int y, final int z )
|
||||
public BlockState getBlockState( BlockPos pos )
|
||||
{
|
||||
if( this.range( x, y, z ) )
|
||||
if( this.range( pos ) )
|
||||
{
|
||||
return this.w.getBlockState( new BlockPos( x, y, z ) );
|
||||
return this.w.getBlockState( new BlockPos( pos ) );
|
||||
}
|
||||
return Blocks.AIR.getDefaultState();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user