reformatted all src files (#141)

This commit is contained in:
YoungOnion
2022-09-17 05:08:02 -06:00
committed by GitHub
parent 3328bfcda2
commit 9011273229
1056 changed files with 88127 additions and 110597 deletions
+448 -540
View File
@@ -19,11 +19,16 @@
package appeng.worldgen;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
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.features.AEFeature;
import appeng.core.worlddata.WorldData;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
import appeng.worldgen.meteorite.*;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
@@ -37,539 +42,442 @@ import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
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.features.AEFeature;
import appeng.core.worlddata.WorldData;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
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
{
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 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.skyStoneChest();
this.skyStoneDefinition = blocks.skyStoneBlock();
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 );
this.validSpawn.add( Blocks.STAINED_HARDENED_CLAY );
this.skyStoneDefinition.maybeBlock().ifPresent( this.invalidSpawn::add );
this.invalidSpawn.add( Blocks.PLANKS );
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.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 );
}
boolean spawnMeteorite( final IMeteoriteWorld w, final NBTTagCompound meteoriteBlob )
{
this.settings = meteoriteBlob;
final int x = this.settings.getInteger( "x" );
final int y = this.settings.getInteger( "y" );
final 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" );
final Block blk = Block.getBlockById( this.settings.getInteger( "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.getInteger( "skyMode" );
// 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 );
}
w.done();
return true;
}
private void placeCrater( final IMeteoriteWorld w, final int x, final int y, final int z )
{
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 );
for( int j = y - 5; j < maxY; j++ )
{
boolean changed = false;
for( int i = minX; i < maxX; i++ )
{
for( int k = minZ; k < maxZ; k++ )
{
final double dx = i - x;
final double dz = k - z;
final double h = y - this.meteoriteSize + 1 + this.type.adjustCrater();
final double distanceFrom = dx * dx + dz * dz;
if( j > h + distanceFrom * 0.02 )
{
if( lava && j < y && w.getBlockState( i, j, k ).getMaterial().isSolid() )
{
if( j > h + distanceFrom * 0.02 )
{
this.putter.put( w, i, j, k, Blocks.LAVA );
}
}
else
{
changed = this.putter.put( w, i, j, k, Platform.AIR_BLOCK ) || changed;
}
}
}
}
}
for( final Object o : w.getWorld()
.getEntitiesWithinAABB( EntityItem.class,
new AxisAlignedBB( w.minX( x - 30 ), y - 5, w.minZ( z - 30 ), w.maxX( x + 30 ), y + 30, w.maxZ( z + 30 ) ) ) )
{
final Entity e = (Entity) o;
e.setDead();
}
}
private void placeMeteorite( final IMeteoriteWorld w, final int x, final int y, final int z )
{
// spawn meteor
this.skyStoneDefinition.maybeBlock().ifPresent( block -> this.placeMeteoriteSkyStone( w, x, y, z, block ) );
if( AEConfig.instance().isFeatureEnabled( AEFeature.SPAWN_PRESSES_IN_METEORITES ) )
{
this.skyChestDefinition.maybeBlock().ifPresent( block -> this.putter.put( w, x, y, z, block ) );
final TileEntity te = w.getTileEntity( x, y, z );
final InventoryAdaptor ap = InventoryAdaptor.getAdaptor( te, EnumFacing.UP );
if( ap != null )
{
int primary = Math.max( 1, (int) ( Math.random() * 4 ) );
if( primary > 3 ) // in case math breaks...
{
primary = 3;
}
for( int zz = 0; zz < primary; zz++ )
{
int r;
boolean duplicate;
do
{
duplicate = false;
if( Math.random() > PRESSES_SPAWN_CHANCE )
{
r = WorldData.instance().storageData().getNextOrderedValue( "presses" );
}
else
{
r = (int) ( Math.random() * 1000 );
}
ItemStack toAdd = ItemStack.EMPTY;
final IMaterials materials = AEApi.instance().definitions().materials();
switch( r % 4 )
{
case 0:
toAdd = materials.calcProcessorPress().maybeStack( 1 ).orElse( ItemStack.EMPTY );
break;
case 1:
toAdd = materials.engProcessorPress().maybeStack( 1 ).orElse( ItemStack.EMPTY );
break;
case 2:
toAdd = materials.logicProcessorPress().maybeStack( 1 ).orElse( ItemStack.EMPTY );
break;
case 3:
toAdd = materials.siliconPress().maybeStack( 1 ).orElse( ItemStack.EMPTY );
break;
default:
}
if( !toAdd.isEmpty() )
{
if( ap.simulateRemove( 1, toAdd, null ).isEmpty() )
{
ap.addItems( toAdd );
}
else
{
duplicate = true;
}
}
}
while( duplicate );
}
final int secondary = Math.max( 1, (int) ( Math.random() * 3 ) );
for( int zz = 0; zz < secondary; zz++ )
{
switch( (int) ( Math.random() * 1000 ) % 3 )
{
case 0:
final int amount = (int) ( ( Math.random() * SKYSTONE_SPAWN_LIMIT ) + 1 );
this.skyStoneDefinition.maybeStack( amount ).ifPresent( ap::addItems );
break;
case 1:
final List<ItemStack> possibles = new ArrayList<>();
possibles.addAll( OreDictionary.getOres( "nuggetIron" ) );
possibles.addAll( OreDictionary.getOres( "nuggetCopper" ) );
possibles.addAll( OreDictionary.getOres( "nuggetTin" ) );
possibles.addAll( OreDictionary.getOres( "nuggetSilver" ) );
possibles.addAll( OreDictionary.getOres( "nuggetLead" ) );
possibles.addAll( OreDictionary.getOres( "nuggetPlatinum" ) );
possibles.addAll( OreDictionary.getOres( "nuggetNickel" ) );
possibles.addAll( OreDictionary.getOres( "nuggetAluminium" ) );
possibles.addAll( OreDictionary.getOres( "nuggetElectrum" ) );
possibles.add( new ItemStack( net.minecraft.init.Items.GOLD_NUGGET ) );
ItemStack nugget = Platform.pickRandom( possibles );
if( !nugget.isEmpty() )
{
nugget = nugget.copy();
nugget.setCount( (int) ( Math.random() * 12 ) + 1 );
ap.addItems( nugget );
}
break;
}
}
}
}
}
private void placeMeteoriteSkyStone( IMeteoriteWorld w, int x, int y, int z, Block block )
{
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 );
for( int i = meteorXLength; i < meteorXHeight; i++ )
{
for( int j = y - 8; j < y + 8; j++ )
{
for( int k = meteorZLength; k < meteorZHeight; 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 );
}
}
}
}
}
private void decay( final IMeteoriteWorld w, final int x, final int y, final int z )
{
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 );
for( int i = meteorXLength; i < meteorXHeight; i++ )
{
for( int k = meteorZLength; k < meteorZHeight; k++ )
{
for( int j = y - 9; j < y + 30; j++ )
{
Block blk = w.getBlock( i, j, k );
if( blk == Blocks.LAVA )
{
continue;
}
if( blk.isReplaceable( w.getWorld(), new BlockPos( i, j, k ) ) )
{
blk = Platform.AIR_BLOCK;
final Block blk_b = w.getBlock( i, j + 1, k );
if( blk_b != blk )
{
final IBlockState meta_b = w.getBlockState( i, j + 1, k );
w.setBlock( i, j, k, meta_b, 3 );
}
else if( randomShit < 100 * this.crater )
{
final double dx = i - x;
final double dy = j - y;
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 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 )
{
randomShit++;
this.type.getRandomFall( w, i, j, k );
}
}
}
}
else
{
// decay.
final Block blk_b = w.getBlock( i, j + 1, k );
if( blk_b == Platform.AIR_BLOCK )
{
if( Math.random() > 0.4 )
{
final double dx = i - x;
final double dy = j - y;
final double dz = k - z;
if( dx * dx + dy * dy + dz * dz < this.crater * 1.6 )
{
this.type.getRandomInset( w, i, j, k );
}
}
}
}
}
}
}
}
double getSqDistance( final int x, final int z )
{
final int chunkX = this.settings.getInteger( "x" ) - x;
final int chunkZ = this.settings.getInteger( "z" ) - z;
return chunkX * chunkX + chunkZ * chunkZ;
}
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 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 );
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 );
}
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.setInteger( "skyMode", skyMode );
w.done();
WorldData.instance().spawnData().addNearByMeteorites( w.getWorld().provider.getDimension(), x >> 4, z >> 4, this.settings );
return true;
}
return false;
}
NBTTagCompound getSettings()
{
return this.settings;
}
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
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 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.skyStoneChest();
this.skyStoneDefinition = blocks.skyStoneBlock();
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);
this.validSpawn.add(Blocks.STAINED_HARDENED_CLAY);
this.skyStoneDefinition.maybeBlock().ifPresent(this.invalidSpawn::add);
this.invalidSpawn.add(Blocks.PLANKS);
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.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);
}
boolean spawnMeteorite(final IMeteoriteWorld w, final NBTTagCompound meteoriteBlob) {
this.settings = meteoriteBlob;
final int x = this.settings.getInteger("x");
final int y = this.settings.getInteger("y");
final 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");
final Block blk = Block.getBlockById(this.settings.getInteger("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.getInteger("skyMode");
// 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);
}
w.done();
return true;
}
private void placeCrater(final IMeteoriteWorld w, final int x, final int y, final int z) {
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);
for (int j = y - 5; j < maxY; j++) {
boolean changed = false;
for (int i = minX; i < maxX; i++) {
for (int k = minZ; k < maxZ; k++) {
final double dx = i - x;
final double dz = k - z;
final double h = y - this.meteoriteSize + 1 + this.type.adjustCrater();
final double distanceFrom = dx * dx + dz * dz;
if (j > h + distanceFrom * 0.02) {
if (lava && j < y && w.getBlockState(i, j, k).getMaterial().isSolid()) {
if (j > h + distanceFrom * 0.02) {
this.putter.put(w, i, j, k, Blocks.LAVA);
}
} else {
changed = this.putter.put(w, i, j, k, Platform.AIR_BLOCK) || changed;
}
}
}
}
}
for (final Object o : w.getWorld()
.getEntitiesWithinAABB(EntityItem.class,
new AxisAlignedBB(w.minX(x - 30), y - 5, w.minZ(z - 30), w.maxX(x + 30), y + 30, w.maxZ(z + 30)))) {
final Entity e = (Entity) o;
e.setDead();
}
}
private void placeMeteorite(final IMeteoriteWorld w, final int x, final int y, final int z) {
// spawn meteor
this.skyStoneDefinition.maybeBlock().ifPresent(block -> this.placeMeteoriteSkyStone(w, x, y, z, block));
if (AEConfig.instance().isFeatureEnabled(AEFeature.SPAWN_PRESSES_IN_METEORITES)) {
this.skyChestDefinition.maybeBlock().ifPresent(block -> this.putter.put(w, x, y, z, block));
final TileEntity te = w.getTileEntity(x, y, z);
final InventoryAdaptor ap = InventoryAdaptor.getAdaptor(te, EnumFacing.UP);
if (ap != null) {
int primary = Math.max(1, (int) (Math.random() * 4));
if (primary > 3) // in case math breaks...
{
primary = 3;
}
for (int zz = 0; zz < primary; zz++) {
int r;
boolean duplicate;
do {
duplicate = false;
if (Math.random() > PRESSES_SPAWN_CHANCE) {
r = WorldData.instance().storageData().getNextOrderedValue("presses");
} else {
r = (int) (Math.random() * 1000);
}
ItemStack toAdd = ItemStack.EMPTY;
final IMaterials materials = AEApi.instance().definitions().materials();
switch (r % 4) {
case 0:
toAdd = materials.calcProcessorPress().maybeStack(1).orElse(ItemStack.EMPTY);
break;
case 1:
toAdd = materials.engProcessorPress().maybeStack(1).orElse(ItemStack.EMPTY);
break;
case 2:
toAdd = materials.logicProcessorPress().maybeStack(1).orElse(ItemStack.EMPTY);
break;
case 3:
toAdd = materials.siliconPress().maybeStack(1).orElse(ItemStack.EMPTY);
break;
default:
}
if (!toAdd.isEmpty()) {
if (ap.simulateRemove(1, toAdd, null).isEmpty()) {
ap.addItems(toAdd);
} else {
duplicate = true;
}
}
}
while (duplicate);
}
final int secondary = Math.max(1, (int) (Math.random() * 3));
for (int zz = 0; zz < secondary; zz++) {
switch ((int) (Math.random() * 1000) % 3) {
case 0:
final int amount = (int) ((Math.random() * SKYSTONE_SPAWN_LIMIT) + 1);
this.skyStoneDefinition.maybeStack(amount).ifPresent(ap::addItems);
break;
case 1:
final List<ItemStack> possibles = new ArrayList<>();
possibles.addAll(OreDictionary.getOres("nuggetIron"));
possibles.addAll(OreDictionary.getOres("nuggetCopper"));
possibles.addAll(OreDictionary.getOres("nuggetTin"));
possibles.addAll(OreDictionary.getOres("nuggetSilver"));
possibles.addAll(OreDictionary.getOres("nuggetLead"));
possibles.addAll(OreDictionary.getOres("nuggetPlatinum"));
possibles.addAll(OreDictionary.getOres("nuggetNickel"));
possibles.addAll(OreDictionary.getOres("nuggetAluminium"));
possibles.addAll(OreDictionary.getOres("nuggetElectrum"));
possibles.add(new ItemStack(net.minecraft.init.Items.GOLD_NUGGET));
ItemStack nugget = Platform.pickRandom(possibles);
if (!nugget.isEmpty()) {
nugget = nugget.copy();
nugget.setCount((int) (Math.random() * 12) + 1);
ap.addItems(nugget);
}
break;
}
}
}
}
}
private void placeMeteoriteSkyStone(IMeteoriteWorld w, int x, int y, int z, Block block) {
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);
for (int i = meteorXLength; i < meteorXHeight; i++) {
for (int j = y - 8; j < y + 8; j++) {
for (int k = meteorZLength; k < meteorZHeight; 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);
}
}
}
}
}
private void decay(final IMeteoriteWorld w, final int x, final int y, final int z) {
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);
for (int i = meteorXLength; i < meteorXHeight; i++) {
for (int k = meteorZLength; k < meteorZHeight; k++) {
for (int j = y - 9; j < y + 30; j++) {
Block blk = w.getBlock(i, j, k);
if (blk == Blocks.LAVA) {
continue;
}
if (blk.isReplaceable(w.getWorld(), new BlockPos(i, j, k))) {
blk = Platform.AIR_BLOCK;
final Block blk_b = w.getBlock(i, j + 1, k);
if (blk_b != blk) {
final IBlockState meta_b = w.getBlockState(i, j + 1, k);
w.setBlock(i, j, k, meta_b, 3);
} else if (randomShit < 100 * this.crater) {
final double dx = i - x;
final double dy = j - y;
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 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) {
randomShit++;
this.type.getRandomFall(w, i, j, k);
}
}
}
} else {
// decay.
final Block blk_b = w.getBlock(i, j + 1, k);
if (blk_b == Platform.AIR_BLOCK) {
if (Math.random() > 0.4) {
final double dx = i - x;
final double dy = j - y;
final double dz = k - z;
if (dx * dx + dy * dy + dz * dz < this.crater * 1.6) {
this.type.getRandomInset(w, i, j, k);
}
}
}
}
}
}
}
}
double getSqDistance(final int x, final int z) {
final int chunkX = this.settings.getInteger("x") - x;
final int chunkZ = this.settings.getInteger("z") - z;
return chunkX * chunkX + chunkZ * chunkZ;
}
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 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);
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);
}
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.setInteger("skyMode", skyMode);
w.done();
WorldData.instance().spawnData().addNearByMeteorites(w.getWorld().provider.getDimension(), x >> 4, z >> 4, this.settings);
return true;
}
return false;
}
NBTTagCompound getSettings() {
return this.settings;
}
}
@@ -19,14 +19,6 @@
package appeng.worldgen;
import java.util.Random;
import net.minecraft.nbt.NBTTagCompound;
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.IWorldGen.WorldGenType;
import appeng.core.AEConfig;
import appeng.core.features.registries.WorldGenRegistry;
@@ -35,118 +27,105 @@ import appeng.hooks.TickHandler;
import appeng.util.IWorldCallable;
import appeng.util.Platform;
import appeng.worldgen.meteorite.ChunkOnly;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.IChunkGenerator;
import net.minecraftforge.fml.common.IWorldGenerator;
import java.util.Random;
public final class MeteoriteWorldGen implements IWorldGenerator
{
@Override
public void generate( final Random r, final int chunkX, final int chunkZ, final World w, final IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider )
{
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 );
public final class MeteoriteWorldGen implements IWorldGenerator {
@Override
public void generate(final Random r, final int chunkX, final int chunkZ, final World w, final IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider) {
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 ) );
}
else
{
WorldData.instance().compassData().service().updateArea( w, chunkX, chunkZ );
}
}
TickHandler.INSTANCE.addCallable(w, new MeteoriteSpawn(x, depth, z));
} else {
WorldData.instance().compassData().service().updateArea(w, chunkX, chunkZ);
}
}
private boolean tryMeteorite( final World w, int depth, final int x, final int z )
{
for( int tries = 0; tries < 20; tries++ )
{
final MeteoritePlacer mp = new MeteoritePlacer();
private boolean tryMeteorite(final World w, int depth, final int x, final int z) {
for (int tries = 0; tries < 20; tries++) {
final MeteoritePlacer mp = new MeteoritePlacer();
if( mp.spawnMeteorite( new ChunkOnly( w, x >> 4, z >> 4 ), x, depth, z ) )
{
final int px = x >> 4;
final int pz = z >> 4;
if (mp.spawnMeteorite(new ChunkOnly(w, x >> 4, z >> 4), x, depth, z)) {
final int px = x >> 4;
final int pz = z >> 4;
for( int cx = px - 6; cx < px + 6; cx++ )
{
for( int cz = pz - 6; cz < pz + 6; cz++ )
{
if( w.getChunkProvider().getLoadedChunk( cx, cz ) != null )
{
if( px == cx && pz == cz )
{
continue;
}
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( WorldData.instance().spawnData().hasGenerated( w.provider.getDimension(), cx, cz ) )
{
final MeteoritePlacer mp2 = new MeteoritePlacer();
mp2.spawnMeteorite( new ChunkOnly( w, cx, cz ), mp.getSettings() );
}
}
}
}
if (WorldData.instance().spawnData().hasGenerated(w.provider.getDimension(), cx, cz)) {
final MeteoritePlacer mp2 = new MeteoritePlacer();
mp2.spawnMeteorite(new ChunkOnly(w, cx, cz), mp.getSettings());
}
}
}
}
return true;
}
return true;
}
depth -= 15;
if( depth < 40 )
{
return false;
}
}
depth -= 15;
if (depth < 40) {
return false;
}
}
return false;
}
return false;
}
private Iterable<NBTTagCompound> getNearByMeteorites( final World w, final int chunkX, final int chunkZ )
{
return WorldData.instance().spawnData().getNearByMeteorites( w.provider.getDimension(), chunkX, chunkZ );
}
private Iterable<NBTTagCompound> getNearByMeteorites(final World w, final int chunkX, final int chunkZ) {
return WorldData.instance().spawnData().getNearByMeteorites(w.provider.getDimension(), chunkX, chunkZ);
}
private class MeteoriteSpawn implements IWorldCallable<Object>
{
private class MeteoriteSpawn implements IWorldCallable<Object> {
private final int x;
private final int z;
private final int depth;
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;
}
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;
@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;
double minSqDist = Double.MAX_VALUE;
// near by meteorites!
for( final NBTTagCompound data : MeteoriteWorldGen.this.getNearByMeteorites( world, chunkX, chunkZ ) )
{
final MeteoritePlacer mp = new MeteoritePlacer();
mp.spawnMeteorite( new ChunkOnly( world, chunkX, chunkZ ), data );
// near by meteorites!
for (final NBTTagCompound 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 ) );
}
minSqDist = Math.min(minSqDist, mp.getSqDistance(this.x, this.z));
}
final boolean isCluster = ( minSqDist < 30 * 30 ) && Platform.getRandomFloat() < AEConfig.instance().getMeteoriteClusterChance();
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 );
}
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 );
WorldData.instance().spawnData().setGenerated(world.provider.getDimension(), chunkX, chunkZ);
WorldData.instance().compassData().service().updateArea(world, chunkX, chunkZ);
return null;
}
}
return null;
}
}
}
@@ -19,8 +19,12 @@
package appeng.worldgen;
import java.util.Random;
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 net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
@@ -28,75 +32,61 @@ import net.minecraft.world.gen.IChunkGenerator;
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 java.util.Random;
public final class QuartzWorldGen implements IWorldGenerator
{
private final WorldGenMinable oreNormal;
private final WorldGenMinable oreCharged;
public final class QuartzWorldGen implements IWorldGenerator {
private final WorldGenMinable oreNormal;
private final WorldGenMinable oreCharged;
public QuartzWorldGen()
{
final IBlocks blocks = AEApi.instance().definitions().blocks();
final IBlockDefinition oreDefinition = blocks.quartzOre();
final IBlockDefinition chargedDefinition = blocks.quartzOreCharged();
public QuartzWorldGen() {
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 );
}
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 IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider )
{
if( this.oreNormal == null && this.oreCharged == null )
{
return;
}
@Override
public void generate(final Random r, final int chunkX, final int chunkZ, final World w, final IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider) {
if (this.oreNormal == null && this.oreCharged == null) {
return;
}
int seaLevel = w.provider.getAverageGroundLevel() + 1;
int seaLevel = w.provider.getAverageGroundLevel() + 1;
if( seaLevel < 20 )
{
final int x = ( chunkX << 4 ) + 8;
final int z = ( chunkZ << 4 ) + 8;
seaLevel = w.getHeight( x, z );
}
if (seaLevel < 20) {
final int x = (chunkX << 4) + 8;
final int z = (chunkZ << 4) + 8;
seaLevel = w.getHeight(x, z);
}
final double oreDepthMultiplier = AEConfig.instance().getQuartzOresClusterAmount() * seaLevel / 64;
final int scale = (int) Math.round( r.nextGaussian() * Math.sqrt( oreDepthMultiplier ) + oreDepthMultiplier );
final double 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 )
{
boolean isCharged = false;
for (int cnt = 0; cnt < (r.nextBoolean() ? scale * 2 : scale) / 2; ++cnt) {
boolean isCharged = false;
if( this.oreCharged != null )
{
isCharged = r.nextFloat() > AEConfig.instance().getSpawnChargedChance();
}
if (this.oreCharged != null) {
isCharged = r.nextFloat() > AEConfig.instance().getSpawnChargedChance();
}
final WorldGenMinable whichOre = isCharged ? this.oreCharged : this.oreNormal;
if( whichOre != null && shouldGenerate( isCharged, w ) )
{
final int cx = chunkX * 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 );
whichOre.generate( w, r, new BlockPos( cx, cy, cz ) );
}
}
}
final WorldGenMinable whichOre = isCharged ? this.oreCharged : this.oreNormal;
if (whichOre != null && shouldGenerate(isCharged, w)) {
final int cx = chunkX * 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);
whichOre.generate(w, r, new BlockPos(cx, cy, cz));
}
}
}
private static boolean shouldGenerate( final boolean isCharged, final World w )
{
return WorldGenRegistry.INSTANCE.isWorldGenEnabled( isCharged ? WorldGenType.CHARGED_CERTUS_QUARTZ : WorldGenType.CERTUS_QUARTZ, w );
}
private static boolean shouldGenerate(final boolean isCharged, final World w) {
return WorldGenRegistry.INSTANCE.isWorldGenEnabled(isCharged ? WorldGenType.CHARGED_CERTUS_QUARTZ : WorldGenType.CERTUS_QUARTZ, w);
}
}
@@ -19,97 +19,81 @@
package appeng.worldgen.meteorite;
import appeng.util.Platform;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import appeng.util.Platform;
public class ChunkOnly extends StandardWorld {
public class ChunkOnly extends StandardWorld
{
private final Chunk target;
private final int cx;
private final int cz;
private int verticalBits = 0;
private final Chunk target;
private final int cx;
private final int cz;
private int verticalBits = 0;
public ChunkOnly(final World w, final int cx, final int cz) {
super(w);
this.target = w.getChunkFromChunkCoords(cx, cz);
this.cx = cx;
this.cz = cz;
}
public ChunkOnly( final World w, final int cx, final int cz )
{
super( w );
this.target = w.getChunkFromChunkCoords( cx, cz );
this.cx = cx;
this.cz = cz;
}
@Override
public int minX(final int in) {
return Math.max(in, this.cx << 4);
}
@Override
public int minX( final int in )
{
return Math.max( in, this.cx << 4 );
}
@Override
public int minZ(final int in) {
return Math.max(in, this.cz << 4);
}
@Override
public int minZ( final int in )
{
return Math.max( in, this.cz << 4 );
}
@Override
public int maxX(final int in) {
return Math.min(in, (this.cx + 1) << 4);
}
@Override
public int maxX( final int in )
{
return Math.min( in, ( this.cx + 1 ) << 4 );
}
@Override
public int maxZ(final int in) {
return Math.min(in, (this.cz + 1) << 4);
}
@Override
public int maxZ( final int in )
{
return Math.min( in, ( this.cz + 1 ) << 4 );
}
@Override
public Block getBlock(final int x, final int y, final int z) {
if (this.range(x, y, z)) {
return this.target.getBlockState(x, y, z).getBlock();
}
return Platform.AIR_BLOCK;
}
@Override
public Block getBlock( final int x, final int y, final int z )
{
if( this.range( x, y, z ) )
{
return this.target.getBlockState( x, y, z ).getBlock();
}
return Platform.AIR_BLOCK;
}
@Override
public void setBlock(final int x, final int y, final int z, final Block blk) {
if (this.range(x, y, z)) {
this.verticalBits |= 1 << (y >> 4);
this.getWorld().setBlockState(new BlockPos(x, y, z), blk.getDefaultState());
}
}
@Override
public void setBlock( final int x, final int y, final int z, final Block blk )
{
if( this.range( x, y, z ) )
{
this.verticalBits |= 1 << ( y >> 4 );
this.getWorld().setBlockState( new BlockPos( x, y, z ), blk.getDefaultState() );
}
}
@Override
public void setBlock(final int x, final int y, final int z, final IBlockState state, final int flags) {
if (this.range(x, y, z)) {
this.verticalBits |= 1 << (y >> 4);
this.getWorld().setBlockState(new BlockPos(x, y, z), state, flags & (~2));
}
}
@Override
public void setBlock( final int x, final int y, final int z, final IBlockState state, final int flags )
{
if( this.range( x, y, z ) )
{
this.verticalBits |= 1 << ( y >> 4 );
this.getWorld().setBlockState( new BlockPos( x, y, z ), state, flags & ( ~2 ) );
}
}
@Override
public void done() {
if (this.verticalBits != 0) {
Platform.sendChunk(this.target, this.verticalBits);
}
}
@Override
public void done()
{
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 );
}
@Override
public boolean range(final int x, final int y, final int z) {
return this.cx == (x >> 4) && this.cz == (z >> 4);
}
}
@@ -19,75 +19,51 @@
package appeng.worldgen.meteorite;
import net.minecraft.init.Blocks;
import appeng.api.definitions.IBlockDefinition;
import appeng.util.Platform;
import net.minecraft.init.Blocks;
public class Fallout
{
private final MeteoriteBlockPutter putter;
private final IBlockDefinition skyStoneDefinition;
public class Fallout {
private final MeteoriteBlockPutter putter;
private final IBlockDefinition skyStoneDefinition;
public Fallout( final MeteoriteBlockPutter putter, final IBlockDefinition skyStoneDefinition )
{
this.putter = putter;
this.skyStoneDefinition = skyStoneDefinition;
}
public Fallout(final MeteoriteBlockPutter putter, final IBlockDefinition skyStoneDefinition) {
this.putter = putter;
this.skyStoneDefinition = skyStoneDefinition;
}
public int adjustCrater()
{
return 0;
}
public int adjustCrater() {
return 0;
}
public void getRandomFall( final IMeteoriteWorld w, final int x, final int y, final int z )
{
final double a = Math.random();
if( a > 0.9 )
{
this.putter.put( w, x, y, z, Blocks.STONE );
}
else if( a > 0.8 )
{
this.putter.put( w, x, y, z, Blocks.COBBLESTONE );
}
else if( a > 0.7 )
{
this.putter.put( w, x, y, z, Blocks.DIRT );
}
else
{
this.putter.put( w, x, y, z, Blocks.GRAVEL );
}
}
public void getRandomFall(final IMeteoriteWorld w, final int x, final int y, final int z) {
final double a = Math.random();
if (a > 0.9) {
this.putter.put(w, x, y, z, Blocks.STONE);
} else if (a > 0.8) {
this.putter.put(w, x, y, z, Blocks.COBBLESTONE);
} else if (a > 0.7) {
this.putter.put(w, x, y, z, Blocks.DIRT);
} else {
this.putter.put(w, x, y, z, Blocks.GRAVEL);
}
}
public void getRandomInset( final IMeteoriteWorld w, final int x, final int y, final int z )
{
final double a = Math.random();
if( a > 0.9 )
{
this.putter.put( w, x, y, z, Blocks.COBBLESTONE );
}
else if( a > 0.8 )
{
this.putter.put( w, x, y, z, Blocks.STONE );
}
else if( a > 0.7 )
{
this.putter.put( w, x, y, z, Blocks.GRASS );
}
else if( a > 0.6 )
{
this.skyStoneDefinition.maybeBlock().ifPresent( block -> this.putter.put( w, x, y, z, block ) );
}
else if( a > 0.5 )
{
this.putter.put( w, x, y, z, Blocks.GRAVEL );
}
else
{
this.putter.put( w, x, y, z, Platform.AIR_BLOCK );
}
}
public void getRandomInset(final IMeteoriteWorld w, final int x, final int y, final int z) {
final double a = Math.random();
if (a > 0.9) {
this.putter.put(w, x, y, z, Blocks.COBBLESTONE);
} else if (a > 0.8) {
this.putter.put(w, x, y, z, Blocks.STONE);
} else if (a > 0.7) {
this.putter.put(w, x, y, z, Blocks.GRASS);
} else if (a > 0.6) {
this.skyStoneDefinition.maybeBlock().ifPresent(block -> this.putter.put(w, x, y, z, block));
} else if (a > 0.5) {
this.putter.put(w, x, y, z, Blocks.GRAVEL);
} else {
this.putter.put(w, x, y, z, Platform.AIR_BLOCK);
}
}
}
@@ -19,62 +19,48 @@
package appeng.worldgen.meteorite;
import net.minecraft.block.state.IBlockState;
import appeng.api.definitions.IBlockDefinition;
import appeng.util.Platform;
import net.minecraft.block.state.IBlockState;
public class FalloutCopy extends Fallout
{
private static final double SPECIFIED_BLOCK_THRESHOLD = 0.9;
private static final double AIR_BLOCK_THRESHOLD = 0.8;
private static final double BLOCK_THRESHOLD_STEP = 0.1;
public class FalloutCopy extends Fallout {
private static final double SPECIFIED_BLOCK_THRESHOLD = 0.9;
private static final double AIR_BLOCK_THRESHOLD = 0.8;
private static final double BLOCK_THRESHOLD_STEP = 0.1;
private final IBlockState block;
private final MeteoriteBlockPutter putter;
private final IBlockState 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 )
{
super( putter, skyStoneDefinition );
this.putter = putter;
this.block = w.getBlockState( x, y, z );
}
public FalloutCopy(final IMeteoriteWorld w, final int x, final int y, final int z, final MeteoriteBlockPutter putter, final IBlockDefinition skyStoneDefinition) {
super(putter, skyStoneDefinition);
this.putter = putter;
this.block = w.getBlockState(x, y, z);
}
@Override
public void getRandomFall( final IMeteoriteWorld w, final int x, final int y, final int z )
{
final double a = Math.random();
if( a > SPECIFIED_BLOCK_THRESHOLD )
{
this.putter.put( w, x, y, z, this.block, 3 );
}
else
{
this.getOther( w, x, y, z, a );
}
}
@Override
public void getRandomFall(final IMeteoriteWorld w, final int x, final int y, final int z) {
final double a = Math.random();
if (a > SPECIFIED_BLOCK_THRESHOLD) {
this.putter.put(w, x, y, z, this.block, 3);
} else {
this.getOther(w, x, y, z, a);
}
}
public void getOther( final IMeteoriteWorld w, final int x, final int y, final int z, final double a )
{
public void getOther(final IMeteoriteWorld w, final int x, final int y, final int z, final double a) {
}
}
@Override
public void getRandomInset( final IMeteoriteWorld w, final int x, final int y, final int z )
{
final double a = Math.random();
if( a > SPECIFIED_BLOCK_THRESHOLD )
{
this.putter.put( w, x, y, z, this.block, 3 );
}
else if( a > AIR_BLOCK_THRESHOLD )
{
this.putter.put( w, x, y, z, Platform.AIR_BLOCK );
}
else
{
this.getOther( w, x, y, z, a - BLOCK_THRESHOLD_STEP );
}
}
@Override
public void getRandomInset(final IMeteoriteWorld w, final int x, final int y, final int z) {
final double a = Math.random();
if (a > SPECIFIED_BLOCK_THRESHOLD) {
this.putter.put(w, x, y, z, this.block, 3);
} else if (a > AIR_BLOCK_THRESHOLD) {
this.putter.put(w, x, y, z, Platform.AIR_BLOCK);
} else {
this.getOther(w, x, y, z, a - BLOCK_THRESHOLD_STEP);
}
}
}
@@ -19,34 +19,28 @@
package appeng.worldgen.meteorite;
import appeng.api.definitions.IBlockDefinition;
import net.minecraft.init.Blocks;
import appeng.api.definitions.IBlockDefinition;
public class FalloutSand extends FalloutCopy {
private static final double GLASS_THRESHOLD = 0.66;
private final MeteoriteBlockPutter putter;
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) {
super(w, x, y, z, putter, skyStoneDefinition);
this.putter = putter;
}
public FalloutSand( final IMeteoriteWorld w, final int x, final int y, final int z, final MeteoriteBlockPutter putter, final IBlockDefinition skyStoneDefinition )
{
super( w, x, y, z, putter, skyStoneDefinition );
this.putter = putter;
}
@Override
public int adjustCrater() {
return 2;
}
@Override
public int adjustCrater()
{
return 2;
}
@Override
public void getOther( final IMeteoriteWorld w, final int x, final int y, final int z, final double a )
{
if( a > GLASS_THRESHOLD )
{
this.putter.put( w, x, y, z, Blocks.GLASS );
}
}
@Override
public void getOther(final IMeteoriteWorld w, final int x, final int y, final int z, final double a) {
if (a > GLASS_THRESHOLD) {
this.putter.put(w, x, y, z, Blocks.GLASS);
}
}
}
@@ -19,39 +19,31 @@
package appeng.worldgen.meteorite;
import appeng.api.definitions.IBlockDefinition;
import net.minecraft.init.Blocks;
import appeng.api.definitions.IBlockDefinition;
public class FalloutSnow extends FalloutCopy {
private static final double SNOW_THRESHOLD = 0.7;
private static final double ICE_THRESHOLD = 0.5;
private final MeteoriteBlockPutter putter;
public class FalloutSnow extends FalloutCopy
{
private static final double SNOW_THRESHOLD = 0.7;
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) {
super(w, x, y, z, putter, skyStoneDefinition);
this.putter = putter;
}
public FalloutSnow( final IMeteoriteWorld w, final int x, final int y, final int z, final MeteoriteBlockPutter putter, final IBlockDefinition skyStoneDefinition )
{
super( w, x, y, z, putter, skyStoneDefinition );
this.putter = putter;
}
@Override
public int adjustCrater() {
return 2;
}
@Override
public int adjustCrater()
{
return 2;
}
@Override
public void getOther( final IMeteoriteWorld w, final int x, final int y, final int z, final double a )
{
if( a > SNOW_THRESHOLD )
{
this.putter.put( w, x, y, z, Blocks.SNOW );
}
else if( a > ICE_THRESHOLD )
{
this.putter.put( w, x, y, z, Blocks.ICE );
}
}
@Override
public void getOther(final IMeteoriteWorld w, final int x, final int y, final int z, final double a) {
if (a > SNOW_THRESHOLD) {
this.putter.put(w, x, y, z, Blocks.SNOW);
} else if (a > ICE_THRESHOLD) {
this.putter.put(w, x, y, z, Blocks.ICE);
}
}
}
@@ -25,31 +25,30 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
public interface IMeteoriteWorld
{
int minX( int in );
public interface IMeteoriteWorld {
int minX(int in);
int minZ( int in );
int minZ(int in);
int maxX( int in );
int maxX(int in);
int maxZ( int in );
int maxZ(int in);
boolean isNether();
boolean isNether();
Block getBlock( int x, int y, int z );
Block getBlock(int x, int y, int z);
boolean canBlockSeeTheSky( int i, int j, int k );
boolean canBlockSeeTheSky(int i, int j, int k);
TileEntity getTileEntity( int x, int y, int z );
TileEntity getTileEntity(int x, int y, int z);
World getWorld();
World getWorld();
void setBlock( int i, int j, int k, Block blk );
void setBlock(int i, int j, int k, Block blk);
void setBlock( int i, int j, int k, IBlockState state, int l );
void setBlock(int i, int j, int k, IBlockState state, int l);
void done();
void done();
IBlockState getBlockState( int x, int y, int z );
IBlockState getBlockState(int x, int y, int z);
}
@@ -24,28 +24,23 @@ import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
public class MeteoriteBlockPutter
{
public boolean put( final IMeteoriteWorld w, final int i, final int j, final int k, final Block blk )
{
final Block original = w.getBlock( i, j, k );
public class MeteoriteBlockPutter {
public boolean put(final IMeteoriteWorld w, final int i, final int j, final int k, final Block blk) {
final Block original = w.getBlock(i, j, k);
if( original == Blocks.BEDROCK || original == blk )
{
return false;
}
if (original == Blocks.BEDROCK || original == blk) {
return false;
}
w.setBlock( i, j, k, blk );
return true;
}
w.setBlock(i, j, k, blk);
return true;
}
void put( final IMeteoriteWorld w, final int i, final int j, final int k, final IBlockState state, final int meta )
{
if( w.getBlock( i, j, k ) == Blocks.BEDROCK )
{
return;
}
void put(final IMeteoriteWorld w, final int i, final int j, final int k, final IBlockState state, final int meta) {
if (w.getBlock(i, j, k) == Blocks.BEDROCK) {
return;
}
w.setBlock( i, j, k, state, 3 );
}
w.setBlock(i, j, k, state, 3);
}
}
@@ -19,6 +19,7 @@
package appeng.worldgen.meteorite;
import appeng.util.Platform;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
@@ -26,121 +27,97 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import appeng.util.Platform;
public class StandardWorld implements IMeteoriteWorld {
public class StandardWorld implements IMeteoriteWorld
{
private final World w;
private final World w;
public StandardWorld(final World w) {
this.w = w;
}
public StandardWorld( final World w )
{
this.w = w;
}
@Override
public int minX(final int in) {
return in;
}
@Override
public int minX( final int in )
{
return in;
}
@Override
public int minZ(final int in) {
return in;
}
@Override
public int minZ( final int in )
{
return in;
}
@Override
public int maxX(final int in) {
return in;
}
@Override
public int maxX( final int in )
{
return in;
}
@Override
public int maxZ(final int in) {
return in;
}
@Override
public int maxZ( final int in )
{
return in;
}
@Override
public boolean isNether() {
return !this.getWorld().provider.isNether();
}
@Override
public boolean isNether()
{
return !this.getWorld().provider.isNether();
}
@Override
public Block getBlock(final int x, final int y, final int z) {
if (this.range(x, y, z)) {
return this.getWorld().getBlockState(new BlockPos(x, y, z)).getBlock();
}
return Platform.AIR_BLOCK;
}
@Override
public Block getBlock( final int x, final int y, final int z )
{
if( this.range( x, y, z ) )
{
return this.getWorld().getBlockState( new BlockPos( x, y, z ) ).getBlock();
}
return Platform.AIR_BLOCK;
}
@Override
public boolean canBlockSeeTheSky(final int x, final int y, final int z) {
if (this.range(x, y, z)) {
return this.getWorld().canBlockSeeSky(new BlockPos(x, y, z));
}
return false;
}
@Override
public boolean canBlockSeeTheSky( final int x, final int y, final int z )
{
if( this.range( x, y, z ) )
{
return this.getWorld().canBlockSeeSky( new BlockPos( x, y, z ) );
}
return false;
}
@Override
public TileEntity getTileEntity(final int x, final int y, final int z) {
if (this.range(x, y, z)) {
return this.getWorld().getTileEntity(new BlockPos(x, y, z));
}
return null;
}
@Override
public TileEntity getTileEntity( final int x, final int y, final int z )
{
if( this.range( x, y, z ) )
{
return this.getWorld().getTileEntity( new BlockPos( x, y, z ) );
}
return null;
}
@Override
public World getWorld() {
return this.w;
}
@Override
public World getWorld()
{
return this.w;
}
@Override
public void setBlock(final int x, final int y, final int z, final Block blk) {
if (this.range(x, y, z)) {
this.getWorld().setBlockState(new BlockPos(x, y, z), blk.getDefaultState());
}
}
@Override
public void setBlock( final int x, final int y, final int z, final Block blk )
{
if( this.range( x, y, z ) )
{
this.getWorld().setBlockState( new BlockPos( x, y, z ), blk.getDefaultState() );
}
}
@Override
public void done() {
@Override
public void done()
{
}
}
public boolean range(final int x, final int y, final int z) {
return true;
}
public boolean range( final int x, final int y, final int z )
{
return true;
}
@Override
public void setBlock(final int x, final int y, final int z, final IBlockState state, final int l) {
if (this.range(x, y, z)) {
this.w.setBlockState(new BlockPos(x, y, z), state, l);
}
}
@Override
public void setBlock( final int x, final int y, final int z, final IBlockState state, final int l )
{
if( this.range( x, y, z ) )
{
this.w.setBlockState( new BlockPos( x, y, z ), state, l );
}
}
@Override
public IBlockState getBlockState( final int x, final int y, final int z )
{
if( this.range( x, y, z ) )
{
return this.w.getBlockState( new BlockPos( x, y, z ) );
}
return Blocks.AIR.getDefaultState();
}
@Override
public IBlockState getBlockState(final int x, final int y, final int z) {
if (this.range(x, y, z)) {
return this.w.getBlockState(new BlockPos(x, y, z));
}
return Blocks.AIR.getDefaultState();
}
}