Added Sky Stone Tracking.
Added Meteorite Compass Block / Item. Added Meteorite Spawner Debug Item. Some Refactoring.
This commit is contained in:
@@ -1,8 +0,0 @@
|
||||
package appeng.helpers;
|
||||
|
||||
public class AENoHandler extends Exception
|
||||
{
|
||||
|
||||
private static final long serialVersionUID = 7995805326136526631L;
|
||||
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
package appeng.helpers;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.entity.passive.EntityVillager;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.village.MerchantRecipe;
|
||||
import net.minecraft.village.MerchantRecipeList;
|
||||
import appeng.api.AEApi;
|
||||
import cpw.mods.fml.common.registry.VillagerRegistry.IVillageTradeHandler;
|
||||
|
||||
public class AETrading implements IVillageTradeHandler
|
||||
{
|
||||
|
||||
private void addToList(MerchantRecipeList l, ItemStack a, ItemStack b)
|
||||
{
|
||||
if ( a.stackSize < 1 )
|
||||
a.stackSize = 1;
|
||||
if ( b.stackSize < 1 )
|
||||
b.stackSize = 1;
|
||||
|
||||
if ( a.stackSize > a.getMaxStackSize() )
|
||||
a.stackSize = a.getMaxStackSize();
|
||||
if ( b.stackSize > b.getMaxStackSize() )
|
||||
b.stackSize = b.getMaxStackSize();
|
||||
|
||||
l.add( new MerchantRecipe( a, b ) );
|
||||
}
|
||||
|
||||
private void addTrade(MerchantRecipeList list, ItemStack a, ItemStack b, Random rand, int convertion_Variance)
|
||||
{
|
||||
// Sell
|
||||
ItemStack From = a.copy();
|
||||
ItemStack To = b.copy();
|
||||
|
||||
From.stackSize = 1 + (Math.abs( rand.nextInt() ) % (1 + convertion_Variance));
|
||||
To.stackSize = 1;
|
||||
|
||||
addToList( list, From, To );
|
||||
}
|
||||
|
||||
private void addMerchent(MerchantRecipeList list, ItemStack item, int emera, Random rand, int greed)
|
||||
{
|
||||
// Sell
|
||||
ItemStack From = item.copy();
|
||||
ItemStack To = new ItemStack( Items.emerald );
|
||||
|
||||
int multiplier = (Math.abs( rand.nextInt() ) % 6);
|
||||
emera += (Math.abs( rand.nextInt() ) % greed) - multiplier;
|
||||
int mood = rand.nextInt() % 2;
|
||||
|
||||
From.stackSize = multiplier + mood;
|
||||
To.stackSize = multiplier * emera - mood;
|
||||
|
||||
if ( To.stackSize < 0 )
|
||||
{
|
||||
From.stackSize -= To.stackSize;
|
||||
To.stackSize -= To.stackSize;
|
||||
}
|
||||
|
||||
addToList( list, From, To );
|
||||
|
||||
// Buy
|
||||
ItemStack reverseTo = From.copy();
|
||||
ItemStack reverseFrom = To.copy();
|
||||
|
||||
reverseFrom.stackSize = (int) (reverseFrom.stackSize * (rand.nextFloat() * 3.0f + 1.0f));
|
||||
reverseTo.stackSize = reverseTo.stackSize;
|
||||
|
||||
addToList( list, reverseFrom, reverseTo );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void manipulateTradesForVillager(EntityVillager villager, MerchantRecipeList recipeList, Random random)
|
||||
{
|
||||
addMerchent( recipeList, AEApi.instance().materials().materialSilicon.stack( 1 ), 1, random, 1 );
|
||||
addMerchent( recipeList, AEApi.instance().materials().materialCertusQuartzCrystal.stack( 1 ), 2, random, 3 );
|
||||
addMerchent( recipeList, AEApi.instance().materials().materialCertusQuartzDust.stack( 1 ), 1, random, 2 );
|
||||
|
||||
addTrade( recipeList, AEApi.instance().materials().materialCertusQuartzDust.stack( 1 ),
|
||||
AEApi.instance().materials().materialCertusQuartzCrystal.stack( 1 ), random, 1 );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package appeng.helpers;
|
||||
|
||||
import net.minecraft.block.BlockDispenser;
|
||||
import net.minecraft.dispenser.BehaviorDefaultDispenseItem;
|
||||
import net.minecraft.dispenser.IBlockSource;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.World;
|
||||
import appeng.entity.EntityTinyTNTPrimed;
|
||||
|
||||
final public class DispenserBehaviorTinyTNT extends BehaviorDefaultDispenseItem
|
||||
{
|
||||
|
||||
@Override
|
||||
protected ItemStack dispenseStack(IBlockSource dispenser, ItemStack dispensedItem)
|
||||
{
|
||||
EnumFacing enumfacing = BlockDispenser.func_149937_b( dispenser.getBlockMetadata() );
|
||||
World world = dispenser.getWorld();
|
||||
int i = dispenser.getXInt() + enumfacing.getFrontOffsetX();
|
||||
int j = dispenser.getYInt() + enumfacing.getFrontOffsetY();
|
||||
int k = dispenser.getZInt() + enumfacing.getFrontOffsetZ();
|
||||
EntityTinyTNTPrimed entitytntprimed = new EntityTinyTNTPrimed( world, (double) ((float) i + 0.5F), (double) ((float) j + 0.5F),
|
||||
(double) ((float) k + 0.5F), (EntityLiving) null );
|
||||
world.spawnEntityInWorld( entitytntprimed );
|
||||
--dispensedItem.stackSize;
|
||||
return dispensedItem;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package appeng.helpers;
|
||||
|
||||
import net.minecraft.block.BlockDispenser;
|
||||
import net.minecraft.dispenser.BehaviorDefaultDispenseItem;
|
||||
import net.minecraft.dispenser.IBlockSource;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import appeng.items.tools.powered.ToolEntropyManipulator;
|
||||
import appeng.util.Platform;
|
||||
|
||||
final public class DispenserEntropyManipulator extends BehaviorDefaultDispenseItem
|
||||
{
|
||||
|
||||
@Override
|
||||
protected ItemStack dispenseStack(IBlockSource dispenser, ItemStack dispensedItem)
|
||||
{
|
||||
Item i = dispensedItem.getItem();
|
||||
if ( i instanceof ToolEntropyManipulator )
|
||||
{
|
||||
EnumFacing enumfacing = BlockDispenser.func_149937_b( dispenser.getBlockMetadata() );
|
||||
ToolEntropyManipulator tm = (ToolEntropyManipulator) i;
|
||||
|
||||
World w = dispenser.getWorld();
|
||||
if ( w instanceof WorldServer )
|
||||
{
|
||||
int x = dispenser.getXInt() + enumfacing.getFrontOffsetX();
|
||||
int y = dispenser.getYInt() + enumfacing.getFrontOffsetY();
|
||||
int z = dispenser.getZInt() + enumfacing.getFrontOffsetZ();
|
||||
|
||||
tm.onItemUse( dispensedItem, Platform.getPlayer( (WorldServer) w ), w, x, y, z, enumfacing.ordinal(), 0.5f, 0.5f, 0.5f );
|
||||
}
|
||||
}
|
||||
return dispensedItem;
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
package appeng.helpers;
|
||||
|
||||
import net.minecraft.block.BlockDispenser;
|
||||
import net.minecraft.dispenser.BehaviorDefaultDispenseItem;
|
||||
import net.minecraft.dispenser.IBlockSource;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.items.tools.powered.ToolMassCannon;
|
||||
import appeng.util.Platform;
|
||||
|
||||
final public class DispenserMatterCannon extends BehaviorDefaultDispenseItem
|
||||
{
|
||||
|
||||
@Override
|
||||
protected ItemStack dispenseStack(IBlockSource dispenser, ItemStack dispensedItem)
|
||||
{
|
||||
Item i = dispensedItem.getItem();
|
||||
if ( i instanceof ToolMassCannon )
|
||||
{
|
||||
EnumFacing enumfacing = BlockDispenser.func_149937_b( dispenser.getBlockMetadata() );
|
||||
ForgeDirection dir = ForgeDirection.UNKNOWN;
|
||||
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
if ( enumfacing.getFrontOffsetX() == d.offsetX && enumfacing.getFrontOffsetY() == d.offsetY && enumfacing.getFrontOffsetZ() == d.offsetZ )
|
||||
dir = d;
|
||||
}
|
||||
|
||||
ToolMassCannon tm = (ToolMassCannon) i;
|
||||
|
||||
World w = dispenser.getWorld();
|
||||
if ( w instanceof WorldServer )
|
||||
{
|
||||
EntityPlayer p = Platform.getPlayer( (WorldServer) w );
|
||||
Platform.configurePlayer( p, dir, dispenser.getBlockTileEntity() );
|
||||
|
||||
p.posX += dir.offsetX;
|
||||
p.posY += dir.offsetY;
|
||||
p.posZ += dir.offsetZ;
|
||||
|
||||
dispensedItem = tm.onItemRightClick( dispensedItem, w, p );
|
||||
}
|
||||
}
|
||||
return dispensedItem;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,361 @@
|
||||
package appeng.helpers;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.world.World;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class MeteoritePlacer
|
||||
{
|
||||
|
||||
private class Fallout
|
||||
{
|
||||
|
||||
public int adjustCrator()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void getRandomFall(World w, int x, int y, int z)
|
||||
{
|
||||
double a = Math.random();
|
||||
if ( a > 0.9 )
|
||||
put( w, x, y, z, Blocks.stone );
|
||||
else if ( a > 0.8 )
|
||||
put( w, x, y, z, Blocks.cobblestone );
|
||||
else if ( a > 0.7 )
|
||||
put( w, x, y, z, Blocks.dirt );
|
||||
else if ( a > 0.7 )
|
||||
put( w, x, y, z, Blocks.gravel );
|
||||
}
|
||||
|
||||
public void getRandomInset(World w, int x, int y, int z)
|
||||
{
|
||||
double a = Math.random();
|
||||
if ( a > 0.9 )
|
||||
put( w, x, y, z, Blocks.cobblestone );
|
||||
else if ( a > 0.8 )
|
||||
put( w, x, y, z, Blocks.stone );
|
||||
else if ( a > 0.7 )
|
||||
put( w, x, y, z, Blocks.dirt );
|
||||
else if ( a > 0.6 )
|
||||
put( w, x, y, z, skystone );
|
||||
else if ( a > 0.5 )
|
||||
put( w, x, y, z, Blocks.gravel );
|
||||
else if ( a > 0.5 )
|
||||
put( w, x, y, z, Platform.air );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
private class FalloutCopy extends Fallout
|
||||
{
|
||||
|
||||
Block blk;
|
||||
int meta;
|
||||
|
||||
public FalloutCopy(World w, int x, int y, int z) {
|
||||
blk = w.getBlock( x, y, z );
|
||||
meta = w.getBlockMetadata( x, y, z );
|
||||
}
|
||||
|
||||
public void getOther(World w, int x, int y, int z, double a)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void getRandomFall(World w, int x, int y, int z)
|
||||
{
|
||||
double a = Math.random();
|
||||
if ( a > 0.9 )
|
||||
put( w, x, y, z, blk, meta );
|
||||
else
|
||||
getOther( w, x, y, z, a );
|
||||
}
|
||||
|
||||
public void getRandomInset(World w, int x, int y, int z)
|
||||
{
|
||||
double a = Math.random();
|
||||
if ( a > 0.9 )
|
||||
put( w, x, y, z, blk, meta );
|
||||
else if ( a > 0.8 )
|
||||
put( w, x, y, z, Platform.air );
|
||||
else
|
||||
getOther( w, x, y, z, a - 0.1 );
|
||||
}
|
||||
};
|
||||
|
||||
private class FalloutSand extends FalloutCopy
|
||||
{
|
||||
|
||||
public FalloutSand(World w, int x, int y, int z) {
|
||||
super( w, x, y, z );
|
||||
}
|
||||
|
||||
public int adjustCrator()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public void getOther(World w, int x, int y, int z, double a)
|
||||
{
|
||||
if ( a > 0.8 )
|
||||
put( w, x, y, z, Blocks.glass );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
int minBLocks = 200;
|
||||
HashSet<Block> validSpawn = new HashSet();
|
||||
HashSet<Block> invalidSpawn = new HashSet();
|
||||
|
||||
Fallout type = new Fallout();
|
||||
|
||||
Block skystone = AEApi.instance().blocks().blockSkyStone.block();
|
||||
|
||||
double real_sizeOfMetorite = (Math.random() * 6.0) + 2;
|
||||
double real_crator = real_sizeOfMetorite * 2 + 5;
|
||||
|
||||
double sizeOfMetorite = real_sizeOfMetorite * real_sizeOfMetorite;
|
||||
double crator = real_crator * real_crator;
|
||||
|
||||
public MeteoritePlacer() {
|
||||
Block skystone = AEApi.instance().blocks().blockSkyStone.block();
|
||||
|
||||
validSpawn.add( Blocks.stone );
|
||||
validSpawn.add( Blocks.cobblestone );
|
||||
validSpawn.add( Blocks.grass );
|
||||
validSpawn.add( Blocks.sand );
|
||||
validSpawn.add( Blocks.dirt );
|
||||
validSpawn.add( Blocks.gravel );
|
||||
validSpawn.add( Blocks.netherrack );
|
||||
validSpawn.add( Blocks.iron_ore );
|
||||
validSpawn.add( Blocks.gold_ore );
|
||||
validSpawn.add( Blocks.diamond_ore );
|
||||
validSpawn.add( Blocks.redstone_ore );
|
||||
validSpawn.add( Blocks.hardened_clay );
|
||||
|
||||
invalidSpawn.add( skystone );
|
||||
invalidSpawn.add( Blocks.planks );
|
||||
invalidSpawn.add( Blocks.iron_door );
|
||||
invalidSpawn.add( Blocks.iron_bars );
|
||||
invalidSpawn.add( Blocks.wooden_door );
|
||||
invalidSpawn.add( Blocks.brick_block );
|
||||
invalidSpawn.add( Blocks.clay );
|
||||
invalidSpawn.add( Blocks.water );
|
||||
invalidSpawn.add( Blocks.log );
|
||||
invalidSpawn.add( Blocks.log2 );
|
||||
}
|
||||
|
||||
public boolean spawnMeteorite(World w, int x, int y, int z)
|
||||
{
|
||||
int validBlocks = 0;
|
||||
|
||||
if ( w.provider.hasNoSky )
|
||||
return false;
|
||||
|
||||
Block blk = w.getBlock( x, y, z );
|
||||
if ( !validSpawn.contains( blk ) )
|
||||
return false; // must spawn on a valid block..
|
||||
|
||||
if ( blk == Blocks.sand )
|
||||
type = new FalloutSand( w, x, y, z );
|
||||
else if ( blk == Blocks.hardened_clay )
|
||||
type = new FalloutCopy( w, x, y, z );
|
||||
|
||||
int realValidBlocks = 0;
|
||||
|
||||
for (int i = x - 6; i < x + 6; i++)
|
||||
for (int j = y - 6; j < y + 6; j++)
|
||||
for (int k = z - 6; k < z + 6; k++)
|
||||
{
|
||||
blk = w.getBlock( i, j, k );
|
||||
if ( validSpawn.contains( blk ) )
|
||||
realValidBlocks++;
|
||||
}
|
||||
|
||||
for (int i = x - 15; i < x + 15; i++)
|
||||
for (int j = y - 15; j < y + 15; j++)
|
||||
for (int k = z - 15; k < z + 15; k++)
|
||||
{
|
||||
blk = w.getBlock( i, j, k );
|
||||
if ( invalidSpawn.contains( blk ) )
|
||||
return false;
|
||||
if ( validSpawn.contains( blk ) )
|
||||
validBlocks++;
|
||||
}
|
||||
|
||||
if ( validBlocks > minBLocks && realValidBlocks > 80 )
|
||||
{
|
||||
// we can spawn here!
|
||||
|
||||
int skyMode = 0;
|
||||
|
||||
for (int i = x - 15; i < x + 15; i++)
|
||||
for (int j = y - 15; j < y + 11; j++)
|
||||
for (int k = z - 15; k < z + 15; k++)
|
||||
{
|
||||
if ( w.canBlockSeeTheSky( i, j, k ) )
|
||||
skyMode++;
|
||||
}
|
||||
|
||||
boolean solid = true;
|
||||
for (int j = y - 15; j < y - 1; j++)
|
||||
{
|
||||
if ( w.getBlock( x, j, z ) == Platform.air )
|
||||
solid = false;
|
||||
}
|
||||
|
||||
if ( !solid )
|
||||
skyMode = 0;
|
||||
|
||||
// creator
|
||||
if ( skyMode > 10 )
|
||||
placeCrator( w, x, y, z );
|
||||
|
||||
placeMetor( w, x, y, z );
|
||||
|
||||
// collapse blocks...
|
||||
if ( skyMode > 3 )
|
||||
Decay( w, x, y, z );
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void placeCrator(World w, int x, int y, int z)
|
||||
{
|
||||
boolean lava = Math.random() > 0.9;
|
||||
|
||||
for (int i = x - 30; i < x + 30; i++)
|
||||
for (int j = y - 5; j < y + 40; j++)
|
||||
for (int k = z - 30; k < z + 30; k++)
|
||||
{
|
||||
double dx = i - x;
|
||||
double dz = k - z;
|
||||
double h = y - real_sizeOfMetorite + 1 + type.adjustCrator();
|
||||
|
||||
double distanceFrom = dx * dx + dz * dz;
|
||||
|
||||
if ( j > h + distanceFrom * 0.02 )
|
||||
{
|
||||
if ( lava && j < y && w.getBlock( x, y - 1, z ).isBlockSolid( w, i, j, k, 0 ) )
|
||||
{
|
||||
if ( j > h + distanceFrom * 0.02 )
|
||||
put( w, i, j, k, Blocks.lava );
|
||||
}
|
||||
else
|
||||
put( w, i, j, k, Platform.air );
|
||||
}
|
||||
}
|
||||
|
||||
for (Object o : w.getEntitiesWithinAABB( EntityItem.class, AxisAlignedBB.getBoundingBox( x - 30, y - 5, z - 30, x + 30, y + 30, z + 30 ) ))
|
||||
{
|
||||
Entity e = (Entity) o;
|
||||
e.setDead();
|
||||
}
|
||||
}
|
||||
|
||||
private void placeMetor(World w, int x, int y, int z)
|
||||
{
|
||||
// spawn metor
|
||||
for (int i = x - 8; i < x + 8; i++)
|
||||
for (int j = y - 8; j < y + 8; j++)
|
||||
for (int k = z - 8; k < z + 8; k++)
|
||||
{
|
||||
double dx = i - x;
|
||||
double dy = j - y;
|
||||
double dz = k - z;
|
||||
|
||||
if ( dx * dx * 0.7 + dy * dy * (j > y ? 1.4 : 0.8) + dz * dz * 0.7 < sizeOfMetorite )
|
||||
put( w, i, j, k, skystone );
|
||||
}
|
||||
}
|
||||
|
||||
private void Decay(World w, int x, int y, int z)
|
||||
{
|
||||
|
||||
for (int i = x - 30; i < x + 30; i++)
|
||||
for (int j = y - 9; j < y + 30; j++)
|
||||
for (int k = z - 30; k < z + 30; k++)
|
||||
{
|
||||
Block blk = w.getBlock( i, j, k );
|
||||
if ( blk == Blocks.lava )
|
||||
continue;
|
||||
|
||||
if ( blk.isReplaceable( w, i, j, k ) )
|
||||
{
|
||||
blk = Platform.air;
|
||||
Block blk_b = w.getBlock( i, j + 1, k );
|
||||
|
||||
if ( blk_b != blk )
|
||||
{
|
||||
int meta_b = w.getBlockMetadata( i, j + 1, k );
|
||||
|
||||
w.setBlock( i, j, k, blk_b, meta_b, 3 );
|
||||
w.setBlock( i, j + 1, k, blk );
|
||||
}
|
||||
else
|
||||
{
|
||||
double dx = i - x;
|
||||
double dy = j - y;
|
||||
double dz = k - z;
|
||||
double dist = dx * dx + dy * dy + dz * dz;
|
||||
|
||||
Block xf = w.getBlock( i, j - 1, k );
|
||||
|
||||
double height = crator * 0.1 - Math.abs( dist - crator * 1.7 );
|
||||
|
||||
if ( xf != blk && height > 0 && Math.random() > 0.5 )
|
||||
{
|
||||
type.getRandomFall( w, i, j, k );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// decay.
|
||||
Block blk_b = w.getBlock( i, j + 1, k );
|
||||
if ( blk_b == Platform.air )
|
||||
{
|
||||
if ( Math.random() > 0.4 )
|
||||
{
|
||||
double dx = i - x;
|
||||
double dy = j - y;
|
||||
double dz = k - z;
|
||||
|
||||
if ( dx * dx + dy * dy + dz * dz < crator * 1.6 )
|
||||
{
|
||||
type.getRandomInset( w, i, j, k );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void put(World w, int i, int j, int k, Block skystone)
|
||||
{
|
||||
if ( w.getBlock( i, j, k ) == Blocks.bedrock )
|
||||
return;
|
||||
|
||||
w.setBlock( i, j, k, skystone );
|
||||
}
|
||||
|
||||
private void put(World w, int i, int j, int k, Block skystone, int meta)
|
||||
{
|
||||
if ( w.getBlock( i, j, k ) == Blocks.bedrock )
|
||||
return;
|
||||
|
||||
w.setBlock( i, j, k, skystone, meta, 3 );
|
||||
}
|
||||
}
|
||||
@@ -1,356 +0,0 @@
|
||||
package appeng.helpers;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.Block.SoundType;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.parts.IFacadePart;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import appeng.api.parts.IPartItem;
|
||||
import appeng.api.parts.PartItemStack;
|
||||
import appeng.api.parts.SelectedPart;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketPartPlacement;
|
||||
import appeng.facade.IFacadeItem;
|
||||
import appeng.integration.abstraction.IBC;
|
||||
import appeng.integration.abstraction.IFMP;
|
||||
import appeng.util.LookDirection;
|
||||
import appeng.util.Platform;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
public class PartPlacement
|
||||
{
|
||||
|
||||
private ThreadLocal<Object> placing = new ThreadLocal<Object>();
|
||||
|
||||
@SubscribeEvent
|
||||
public void playerInteract(PlayerInteractEvent event)
|
||||
{
|
||||
if ( event.action == Action.RIGHT_CLICK_BLOCK && event.entityPlayer.worldObj.isRemote )
|
||||
{
|
||||
if ( placing.get() != null )
|
||||
return;
|
||||
|
||||
placing.set( event );
|
||||
|
||||
ItemStack held = event.entityPlayer.getHeldItem();
|
||||
if ( place( held, event.x, event.y, event.z, event.face, event.entityPlayer, event.entityPlayer.worldObj, PlaceType.INTERACT_FIRST_PASS, 0 ) )
|
||||
event.setCanceled( true );
|
||||
|
||||
placing.set( null );
|
||||
}
|
||||
}
|
||||
|
||||
public enum PlaceType
|
||||
{
|
||||
PLACE_ITEM, INTERACT_FIRST_PASS, INTERACT_SECOND_PASS
|
||||
};
|
||||
|
||||
public static boolean place(ItemStack held, int x, int y, int z, int face, EntityPlayer player, World world, PlaceType pass, int depth)
|
||||
{
|
||||
if ( depth > 3 )
|
||||
return false;
|
||||
|
||||
ForgeDirection side = ForgeDirection.getOrientation( face );
|
||||
|
||||
if ( held != null && Platform.isWrench( player, held, x, y, z ) && player.isSneaking() )
|
||||
{
|
||||
Block block = world.getBlock( x, y, z );
|
||||
TileEntity tile = world.getTileEntity( x, y, z );
|
||||
IPartHost host = null;
|
||||
|
||||
if ( tile instanceof IPartHost )
|
||||
host = (IPartHost) tile;
|
||||
|
||||
if ( host != null )
|
||||
{
|
||||
if ( !world.isRemote )
|
||||
{
|
||||
LookDirection dir = Platform.getPlayerRay( player );
|
||||
MovingObjectPosition mop = block.collisionRayTrace( world, x, y, z, dir.a, dir.b );
|
||||
if ( mop != null )
|
||||
{
|
||||
List<ItemStack> is = new LinkedList();
|
||||
SelectedPart sp = host.selectPart( mop.hitVec.addVector( -mop.blockX, -mop.blockY, -mop.blockZ ) );
|
||||
|
||||
if ( sp.part != null )
|
||||
{
|
||||
is.add( sp.part.getItemStack( PartItemStack.Wrench ) );
|
||||
sp.part.getDrops( is, true );
|
||||
host.removePart( sp.side, false );
|
||||
}
|
||||
|
||||
if ( sp.facade != null )
|
||||
{
|
||||
is.add( sp.facade.getItemStack() );
|
||||
host.getFacadeContainer().removeFacade( host, sp.side );
|
||||
world.notifyBlocksOfNeighborChange( x, y, z, Platform.air );
|
||||
}
|
||||
|
||||
if ( host.isEmpty() )
|
||||
world.setBlock( x, y, z, Platform.air );
|
||||
|
||||
if ( is != null && !is.isEmpty() )
|
||||
{
|
||||
Platform.spawnDrops( world, x, y, z, is );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
player.swingItem();
|
||||
try
|
||||
{
|
||||
NetworkHandler.instance.sendToServer( new PacketPartPlacement( x, y, z, face ) );
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
TileEntity tile = world.getTileEntity( x, y, z );
|
||||
IPartHost host = null;
|
||||
|
||||
if ( tile instanceof IPartHost )
|
||||
host = (IPartHost) tile;
|
||||
|
||||
if ( held != null )
|
||||
{
|
||||
IFacadePart fp = isFacade( held, side );
|
||||
if ( fp != null )
|
||||
{
|
||||
if ( host != null )
|
||||
{
|
||||
if ( !world.isRemote )
|
||||
{
|
||||
if ( host.getPart( ForgeDirection.UNKNOWN ) == null )
|
||||
return false;
|
||||
|
||||
if ( host.getFacadeContainer().addFacade( fp ) )
|
||||
{
|
||||
host.markForUpdate();
|
||||
if ( !player.capabilities.isCreativeMode )
|
||||
{
|
||||
held.stackSize--;
|
||||
if ( held.stackSize == 0 )
|
||||
{
|
||||
player.inventory.mainInventory[player.inventory.currentItem] = null;
|
||||
MinecraftForge.EVENT_BUS.post( new PlayerDestroyItemEvent( player, held ) );
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
player.swingItem();
|
||||
try
|
||||
{
|
||||
NetworkHandler.instance.sendToServer( new PacketPartPlacement( x, y, z, face ) );
|
||||
return true;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( host == null && tile != null && AppEng.instance.isIntegrationEnabled( "FMP" ) )
|
||||
host = ((IFMP) AppEng.instance.getIntegration( "FMP" )).getOrCreateHost( tile );
|
||||
|
||||
// if ( held == null )
|
||||
{
|
||||
Block block = world.getBlock( x, y, z );
|
||||
if ( host != null && player.isSneaking() && block != null )
|
||||
{
|
||||
LookDirection dir = Platform.getPlayerRay( player );
|
||||
MovingObjectPosition mop = block.collisionRayTrace( world, x, y, z, dir.a, dir.b );
|
||||
if ( mop != null )
|
||||
{
|
||||
mop.hitVec = mop.hitVec.addVector( -mop.blockX, -mop.blockY, -mop.blockZ );
|
||||
SelectedPart sPart = host.selectPart( mop.hitVec );
|
||||
if ( sPart != null && sPart.part != null )
|
||||
if ( sPart.part.onShiftActivate( player, mop.hitVec ) )
|
||||
{
|
||||
if ( world.isRemote )
|
||||
{
|
||||
try
|
||||
{
|
||||
NetworkHandler.instance.sendToServer( new PacketPartPlacement( x, y, z, face ) );
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( held == null || !(held.getItem() instanceof IPartItem) )
|
||||
return false;
|
||||
|
||||
int te_x = x;
|
||||
int te_y = y;
|
||||
int te_z = z;
|
||||
|
||||
if ( host == null && pass == PlaceType.PLACE_ITEM )
|
||||
{
|
||||
ItemStack is = AEApi.instance().blocks().blockMultiPart.stack( 1 );
|
||||
ItemBlock ib = (ItemBlock) is.getItem();
|
||||
ForgeDirection offset = ForgeDirection.UNKNOWN;
|
||||
|
||||
Block blkID = world.getBlock( x, y, z );
|
||||
if ( blkID != null && !blkID.isReplaceable( world, x, y, z ) )
|
||||
{
|
||||
offset = side;
|
||||
if ( Platform.isServer() )
|
||||
side = side.getOpposite();
|
||||
}
|
||||
|
||||
te_x = x + offset.offsetX;
|
||||
te_y = y + offset.offsetY;
|
||||
te_z = z + offset.offsetZ;
|
||||
|
||||
tile = world.getTileEntity( te_x, te_y, te_z );
|
||||
if ( tile instanceof IPartHost )
|
||||
host = (IPartHost) tile;
|
||||
|
||||
if ( host == null && tile != null && AppEng.instance.isIntegrationEnabled( "FMP" ) )
|
||||
host = ((IFMP) AppEng.instance.getIntegration( "FMP" )).getOrCreateHost( tile );
|
||||
|
||||
if ( host == null && AEApi.instance().blocks().blockMultiPart.block().canPlaceBlockAt( world, te_x, te_y, te_z )
|
||||
&& ib.placeBlockAt( is, player, world, te_x, te_y, te_z, side.ordinal(), 0.5f, 0.5f, 0.5f, 0 ) )
|
||||
{
|
||||
if ( !world.isRemote )
|
||||
{
|
||||
tile = world.getTileEntity( te_x, te_y, te_z );
|
||||
|
||||
if ( tile instanceof IPartHost )
|
||||
host = (IPartHost) tile;
|
||||
|
||||
pass = PlaceType.INTERACT_SECOND_PASS;
|
||||
}
|
||||
else
|
||||
{
|
||||
player.swingItem();
|
||||
try
|
||||
{
|
||||
NetworkHandler.instance.sendToServer( new PacketPartPlacement( x, y, z, face ) );
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if ( host != null && !host.canAddPart( held, side ) )
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( host == null )
|
||||
return false;
|
||||
|
||||
if ( !host.canAddPart( held, side ) )
|
||||
{
|
||||
if ( pass == PlaceType.INTERACT_FIRST_PASS || pass == PlaceType.PLACE_ITEM )
|
||||
{
|
||||
ForgeDirection offset = side;
|
||||
|
||||
te_x = x + offset.offsetX;
|
||||
te_y = y + offset.offsetY;
|
||||
te_z = z + offset.offsetZ;
|
||||
|
||||
Block blkID = world.getBlock( te_x, te_y, te_z );
|
||||
tile = world.getTileEntity( te_x, te_y, te_z );
|
||||
|
||||
if ( tile != null && AppEng.instance.isIntegrationEnabled( "FMP" ) )
|
||||
host = ((IFMP) AppEng.instance.getIntegration( "FMP" )).getOrCreateHost( tile );
|
||||
|
||||
if ( (blkID == null || blkID.isReplaceable( world, te_x, te_y, te_z ) || host != null) && offset != ForgeDirection.UNKNOWN )
|
||||
return place( held, te_x, te_y, te_z, side.getOpposite().ordinal(), player, world,
|
||||
pass == PlaceType.INTERACT_FIRST_PASS ? PlaceType.INTERACT_SECOND_PASS : PlaceType.PLACE_ITEM, depth + 1 );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( !world.isRemote )
|
||||
{
|
||||
ForgeDirection mySide = host.addPart( held, side, player );
|
||||
if ( mySide != null )
|
||||
{
|
||||
SoundType ss = AEApi.instance().blocks().blockMultiPart.block().stepSound;
|
||||
|
||||
// ss.getPlaceSound()
|
||||
world.playSoundEffect( 0.5 + x, 0.5 + y, 0.5 + z, ss.func_150496_b(), (ss.getVolume() + 1.0F) / 2.0F, ss.getPitch() * 0.8F );
|
||||
|
||||
if ( !player.capabilities.isCreativeMode )
|
||||
{
|
||||
held.stackSize--;
|
||||
if ( held.stackSize == 0 )
|
||||
{
|
||||
player.inventory.mainInventory[player.inventory.currentItem] = null;
|
||||
MinecraftForge.EVENT_BUS.post( new PlayerDestroyItemEvent( player, held ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
player.swingItem();
|
||||
try
|
||||
{
|
||||
NetworkHandler.instance.sendToServer( new PacketPartPlacement( x, y, z, face ) );
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static IFacadePart isFacade(ItemStack held, ForgeDirection side)
|
||||
{
|
||||
if ( held.getItem() instanceof IFacadeItem )
|
||||
return ((IFacadeItem) held.getItem()).createPartFromItemStack( held, side );
|
||||
if ( AppEng.instance.isIntegrationEnabled( "BC" ) )
|
||||
{
|
||||
IBC bc = (IBC) AppEng.instance.getIntegration( "BC" );
|
||||
if ( bc.isFacade( held ) )
|
||||
return bc.createFacadePart( held, side );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
package appeng.helpers;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.IChunkProvider;
|
||||
import net.minecraft.world.gen.feature.WorldGenMinable;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.core.AEConfig;
|
||||
import cpw.mods.fml.common.IWorldGenerator;
|
||||
|
||||
final public class QuartzWorldGen implements IWorldGenerator
|
||||
{
|
||||
|
||||
final WorldGenMinable oreNormal;
|
||||
final WorldGenMinable oreCharged;
|
||||
|
||||
public QuartzWorldGen() {
|
||||
Block normal = AEApi.instance().blocks().blockQuartzOre.block();
|
||||
Block charged = AEApi.instance().blocks().blockQuartzOreCharged.block();
|
||||
|
||||
if ( normal != null && charged != null )
|
||||
{
|
||||
oreNormal = new WorldGenMinable( normal, 0, AEConfig.instance.oresPerCluster, Blocks.stone );
|
||||
oreCharged = new WorldGenMinable( charged, 0, AEConfig.instance.oresPerCluster, Blocks.stone );
|
||||
}
|
||||
else
|
||||
oreNormal = oreCharged = null;
|
||||
};
|
||||
|
||||
@Override
|
||||
public void generate(Random r, int chunkX, int chunkZ, World w, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
|
||||
{
|
||||
int sealevel = w.provider.getAverageGroundLevel() + 1;
|
||||
|
||||
if ( oreNormal == null || oreCharged == null )
|
||||
return;
|
||||
|
||||
double oreDepthMultiplier = 15 * sealevel / 64;
|
||||
int scale = (int) Math.round( r.nextGaussian() * Math.sqrt( oreDepthMultiplier ) + oreDepthMultiplier );
|
||||
|
||||
for (int x = 0; x < (r.nextBoolean() ? scale * 2 : scale) / 2; ++x)
|
||||
{
|
||||
WorldGenMinable whichOre = r.nextFloat() > 0.92 ? oreCharged : oreNormal;
|
||||
int a = chunkX * 16 + r.nextInt( 22 );
|
||||
int b = r.nextInt( 40 * sealevel / 64 ) + r.nextInt( 22 * sealevel / 64 ) + 12 * sealevel / 64;
|
||||
int c = chunkZ * 16 + r.nextInt( 22 );
|
||||
whichOre.generate( w, r, a, b, c );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,136 +0,0 @@
|
||||
package appeng.helpers;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.core.AELog;
|
||||
import appeng.me.Grid;
|
||||
import appeng.me.NetworkList;
|
||||
import appeng.tile.AEBaseTile;
|
||||
import appeng.util.Platform;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.Type;
|
||||
|
||||
public class TickHandler
|
||||
{
|
||||
|
||||
class HandlerRep
|
||||
{
|
||||
|
||||
public Queue<AEBaseTile> tiles = new LinkedList();
|
||||
|
||||
public Collection<Grid> networks = new NetworkList();
|
||||
|
||||
public void clear()
|
||||
{
|
||||
tiles = new LinkedList();
|
||||
networks = new NetworkList();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
final public static TickHandler instance = new TickHandler();
|
||||
|
||||
final private Queue<Callable> callQueue = new LinkedList();
|
||||
|
||||
final private HandlerRep server = new HandlerRep();
|
||||
final private HandlerRep client = new HandlerRep();
|
||||
|
||||
HandlerRep getRepo()
|
||||
{
|
||||
if ( Platform.isServer() )
|
||||
return server;
|
||||
return client;
|
||||
}
|
||||
|
||||
public void addCallable(Callable c)
|
||||
{
|
||||
callQueue.add( c );
|
||||
}
|
||||
|
||||
public void addInit(AEBaseTile tile)
|
||||
{
|
||||
getRepo().tiles.add( tile );
|
||||
}
|
||||
|
||||
public void addNetwork(Grid grid)
|
||||
{
|
||||
if ( Platform.isServer() )
|
||||
getRepo().networks.add( grid );
|
||||
}
|
||||
|
||||
public void removeNetwork(Grid grid)
|
||||
{
|
||||
if ( Platform.isServer() )
|
||||
getRepo().networks.remove( grid );
|
||||
}
|
||||
|
||||
public Iterable<Grid> getGridList()
|
||||
{
|
||||
return getRepo().networks;
|
||||
}
|
||||
|
||||
public void shutdown()
|
||||
{
|
||||
getRepo().clear();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void unloadWorld(WorldEvent.Unload ev)
|
||||
{
|
||||
if ( Platform.isServer() )
|
||||
{
|
||||
LinkedList<IGridNode> toDestroy = new LinkedList();
|
||||
|
||||
for (Grid g : getRepo().networks)
|
||||
{
|
||||
for (IGridNode n : g.getNodes())
|
||||
{
|
||||
if ( n.getWorld() == ev.world )
|
||||
toDestroy.add( n );
|
||||
}
|
||||
}
|
||||
|
||||
for (IGridNode n : toDestroy)
|
||||
n.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onTick(TickEvent ev)
|
||||
{
|
||||
if ( ev.type == Type.SERVER )
|
||||
{
|
||||
HandlerRep repo = getRepo();
|
||||
while (!repo.tiles.isEmpty())
|
||||
{
|
||||
AEBaseTile bt = repo.tiles.poll();
|
||||
bt.onReady();
|
||||
}
|
||||
|
||||
for (Grid g : getRepo().networks)
|
||||
{
|
||||
g.update();
|
||||
}
|
||||
|
||||
Callable c = null;
|
||||
while ((c = callQueue.poll()) != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
c.call();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user