2014-02-16 19:41:45 +01:00
|
|
|
package appeng.integration.modules;
|
2014-02-15 07:40:02 +01:00
|
|
|
|
2014-05-11 18:28:34 +02:00
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
2014-02-15 07:40:02 +01:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.IIcon;
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
|
|
|
import appeng.api.AEApi;
|
|
|
|
import appeng.api.config.TunnelType;
|
2014-02-23 21:06:07 +01:00
|
|
|
import appeng.api.definitions.Blocks;
|
2014-02-15 07:40:02 +01:00
|
|
|
import appeng.api.features.IP2PTunnelRegistry;
|
|
|
|
import appeng.api.parts.IFacadePart;
|
2014-05-11 18:28:34 +02:00
|
|
|
import appeng.api.util.AEItemDefinition;
|
|
|
|
import appeng.api.util.IOrientableBlock;
|
|
|
|
import appeng.core.AppEng;
|
2014-02-15 07:40:02 +01:00
|
|
|
import appeng.facade.FacadePart;
|
2014-02-18 18:43:02 +01:00
|
|
|
import appeng.integration.BaseModule;
|
2014-02-15 07:40:02 +01:00
|
|
|
import appeng.integration.abstraction.IBC;
|
2014-05-11 18:28:34 +02:00
|
|
|
import appeng.integration.modules.BCHelpers.AECableSchematicTile;
|
|
|
|
import appeng.integration.modules.BCHelpers.AEGenericSchematicTile;
|
|
|
|
import appeng.integration.modules.BCHelpers.AERotateableBlockSchematic;
|
|
|
|
import appeng.integration.modules.BCHelpers.BCPipeHandler;
|
2014-02-15 07:40:02 +01:00
|
|
|
import buildcraft.BuildCraftEnergy;
|
|
|
|
import buildcraft.BuildCraftTransport;
|
2014-05-11 18:28:34 +02:00
|
|
|
import buildcraft.api.blueprints.SchematicRegistry;
|
2014-02-15 07:40:02 +01:00
|
|
|
import buildcraft.api.tools.IToolWrench;
|
2014-02-18 18:43:02 +01:00
|
|
|
import buildcraft.api.transport.IPipeConnection;
|
2014-02-15 07:40:02 +01:00
|
|
|
import buildcraft.api.transport.IPipeTile;
|
|
|
|
import buildcraft.api.transport.IPipeTile.PipeType;
|
|
|
|
import buildcraft.transport.ItemFacade;
|
|
|
|
import buildcraft.transport.PipeIconProvider;
|
|
|
|
import buildcraft.transport.TileGenericPipe;
|
2014-02-16 19:41:45 +01:00
|
|
|
import cpw.mods.fml.common.event.FMLInterModComms;
|
2014-02-15 07:40:02 +01:00
|
|
|
|
2014-02-20 04:16:41 +01:00
|
|
|
public class BC extends BaseModule implements IBC
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
public static BC instance;
|
|
|
|
|
2014-04-06 08:55:24 +02:00
|
|
|
public BC() {
|
|
|
|
TestClass( IPipeConnection.class );
|
|
|
|
TestClass( ItemFacade.class );
|
|
|
|
TestClass( IToolWrench.class );
|
|
|
|
}
|
|
|
|
|
2014-02-15 07:40:02 +01:00
|
|
|
@Override
|
|
|
|
public void addFacade(ItemStack item)
|
|
|
|
{
|
2014-04-04 17:46:05 +02:00
|
|
|
if ( item != null )
|
|
|
|
FMLInterModComms.sendMessage( "BuildCraft|Transport", "add-facade", item );
|
2014-02-15 07:40:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isWrench(Item eq)
|
|
|
|
{
|
|
|
|
return eq instanceof IToolWrench;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isPipe(TileEntity te, ForgeDirection dir)
|
|
|
|
{
|
|
|
|
if ( te instanceof IPipeTile )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if ( te instanceof TileGenericPipe )
|
|
|
|
if ( ((TileGenericPipe) te).hasPlug( dir.getOpposite() ) )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
catch (Exception err)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canWrench(Item i, EntityPlayer p, int x, int y, int z)
|
|
|
|
{
|
|
|
|
return ((IToolWrench) i).canWrench( p, x, y, z );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void wrenchUsed(Item i, EntityPlayer p, int x, int y, int z)
|
|
|
|
{
|
|
|
|
((IToolWrench) i).wrenchUsed( p, x, y, z );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean addItemsToPipe(TileEntity te, ItemStack is, ForgeDirection dir)
|
|
|
|
{
|
|
|
|
if ( is != null && te != null && te instanceof IPipeTile )
|
|
|
|
{
|
|
|
|
IPipeTile pt = (IPipeTile) te;
|
|
|
|
if ( pt.getPipeType() == PipeType.ITEM )
|
|
|
|
{
|
|
|
|
int amt = pt.injectItem( is, false, dir );
|
|
|
|
if ( amt == is.stackSize )
|
|
|
|
{
|
|
|
|
pt.injectItem( is, true, dir );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isFacade(ItemStack is)
|
|
|
|
{
|
|
|
|
if ( is == null )
|
|
|
|
return false;
|
2014-05-10 04:08:56 +02:00
|
|
|
|
2014-05-12 00:01:31 +02:00
|
|
|
try
|
|
|
|
{
|
2014-05-21 05:06:37 +02:00
|
|
|
return is.getItem() instanceof ItemFacade && ItemFacade.getType( is ) == ItemFacade.FacadeType.Basic;
|
2014-05-12 00:01:31 +02:00
|
|
|
}
|
|
|
|
catch (Throwable t)
|
|
|
|
{
|
2014-05-21 05:06:37 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
return is.getItem() instanceof ItemFacade && ItemFacade.getType( is ) == ItemFacade.TYPE_BASIC;
|
|
|
|
}
|
|
|
|
catch (Throwable g)
|
|
|
|
{
|
|
|
|
return is.getItem() instanceof ItemFacade;
|
|
|
|
}
|
2014-05-12 00:01:31 +02:00
|
|
|
}
|
2014-02-15 07:40:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canAddItemsToPipe(TileEntity te, ItemStack is, ForgeDirection dir)
|
|
|
|
{
|
|
|
|
|
|
|
|
if ( is != null && te != null && te instanceof IPipeTile )
|
|
|
|
{
|
|
|
|
IPipeTile pt = (IPipeTile) te;
|
|
|
|
if ( pt.getPipeType() == PipeType.ITEM )
|
|
|
|
{
|
|
|
|
int amt = pt.injectItem( is, false, dir );
|
|
|
|
if ( amt == is.stackSize )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void registerPowerP2P()
|
|
|
|
{
|
|
|
|
IP2PTunnelRegistry reg = AEApi.instance().registries().p2pTunnel();
|
|
|
|
reg.addNewAttunement( new ItemStack( BuildCraftEnergy.engineBlock, 1, 0 ), TunnelType.BC_POWER );
|
|
|
|
reg.addNewAttunement( new ItemStack( BuildCraftEnergy.engineBlock, 1, 1 ), TunnelType.BC_POWER );
|
|
|
|
reg.addNewAttunement( new ItemStack( BuildCraftEnergy.engineBlock, 1, 2 ), TunnelType.BC_POWER );
|
|
|
|
reg.addNewAttunement( new ItemStack( BuildCraftTransport.pipePowerCobblestone ), TunnelType.BC_POWER );
|
|
|
|
reg.addNewAttunement( new ItemStack( BuildCraftTransport.pipePowerDiamond ), TunnelType.BC_POWER );
|
|
|
|
reg.addNewAttunement( new ItemStack( BuildCraftTransport.pipePowerGold ), TunnelType.BC_POWER );
|
|
|
|
reg.addNewAttunement( new ItemStack( BuildCraftTransport.pipePowerQuartz ), TunnelType.BC_POWER );
|
|
|
|
reg.addNewAttunement( new ItemStack( BuildCraftTransport.pipePowerStone ), TunnelType.BC_POWER );
|
|
|
|
reg.addNewAttunement( new ItemStack( BuildCraftTransport.pipePowerWood ), TunnelType.BC_POWER );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void registerItemP2P()
|
|
|
|
{
|
|
|
|
IP2PTunnelRegistry reg = AEApi.instance().registries().p2pTunnel();
|
|
|
|
reg.addNewAttunement( new ItemStack( BuildCraftTransport.pipeItemsWood ), TunnelType.ITEM );
|
|
|
|
reg.addNewAttunement( new ItemStack( BuildCraftTransport.pipeItemsVoid ), TunnelType.ITEM );
|
|
|
|
reg.addNewAttunement( new ItemStack( BuildCraftTransport.pipeItemsSandstone ), TunnelType.ITEM );
|
|
|
|
reg.addNewAttunement( new ItemStack( BuildCraftTransport.pipeItemsQuartz ), TunnelType.ITEM );
|
|
|
|
reg.addNewAttunement( new ItemStack( BuildCraftTransport.pipeItemsObsidian ), TunnelType.ITEM );
|
|
|
|
reg.addNewAttunement( new ItemStack( BuildCraftTransport.pipeItemsIron ), TunnelType.ITEM );
|
|
|
|
reg.addNewAttunement( new ItemStack( BuildCraftTransport.pipeItemsGold ), TunnelType.ITEM );
|
|
|
|
reg.addNewAttunement( new ItemStack( BuildCraftTransport.pipeItemsEmerald ), TunnelType.ITEM );
|
|
|
|
reg.addNewAttunement( new ItemStack( BuildCraftTransport.pipeItemsDiamond ), TunnelType.ITEM );
|
|
|
|
reg.addNewAttunement( new ItemStack( BuildCraftTransport.pipeItemsStone ), TunnelType.ITEM );
|
|
|
|
reg.addNewAttunement( new ItemStack( BuildCraftTransport.pipeItemsCobblestone ), TunnelType.ITEM );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void registerLiquidsP2P()
|
|
|
|
{
|
|
|
|
IP2PTunnelRegistry reg = AEApi.instance().registries().p2pTunnel();
|
|
|
|
reg.addNewAttunement( new ItemStack( BuildCraftTransport.pipeFluidsCobblestone ), TunnelType.FLUID );
|
|
|
|
reg.addNewAttunement( new ItemStack( BuildCraftTransport.pipeFluidsEmerald ), TunnelType.FLUID );
|
|
|
|
reg.addNewAttunement( new ItemStack( BuildCraftTransport.pipeFluidsGold ), TunnelType.FLUID );
|
|
|
|
reg.addNewAttunement( new ItemStack( BuildCraftTransport.pipeFluidsIron ), TunnelType.FLUID );
|
|
|
|
reg.addNewAttunement( new ItemStack( BuildCraftTransport.pipeFluidsSandstone ), TunnelType.FLUID );
|
|
|
|
reg.addNewAttunement( new ItemStack( BuildCraftTransport.pipeFluidsStone ), TunnelType.FLUID );
|
|
|
|
reg.addNewAttunement( new ItemStack( BuildCraftTransport.pipeFluidsVoid ), TunnelType.FLUID );
|
|
|
|
reg.addNewAttunement( new ItemStack( BuildCraftTransport.pipeFluidsWood ), TunnelType.FLUID );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void Init()
|
|
|
|
{
|
2014-06-04 07:06:20 +02:00
|
|
|
AEApi.instance().partHelper().registerNewLayer( "appeng.parts.layers.LayerIPipeConnection", "buildcraft.api.transport.IPipeConnection" );
|
2014-02-15 07:40:02 +01:00
|
|
|
AEApi.instance().registries().externalStorage().addExternalStorageInterface( new BCPipeHandler() );
|
2014-02-23 21:06:07 +01:00
|
|
|
|
|
|
|
Blocks b = AEApi.instance().blocks();
|
|
|
|
addFacade( b.blockFluix.stack( 1 ) );
|
|
|
|
addFacade( b.blockQuartz.stack( 1 ) );
|
|
|
|
addFacade( b.blockQuartzChiseled.stack( 1 ) );
|
|
|
|
addFacade( b.blockQuartzPiller.stack( 1 ) );
|
2014-05-10 04:08:56 +02:00
|
|
|
|
2014-05-11 18:28:34 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
initBuilderSupport();
|
|
|
|
}
|
|
|
|
catch (Throwable builderSupport)
|
|
|
|
{
|
|
|
|
// not supported?
|
|
|
|
}
|
|
|
|
|
2014-04-04 17:46:05 +02:00
|
|
|
Block skyStone = b.blockSkyStone.block();
|
|
|
|
if ( skyStone != null )
|
|
|
|
{
|
|
|
|
addFacade( new ItemStack( skyStone, 1, 0 ) );
|
|
|
|
addFacade( new ItemStack( skyStone, 1, 1 ) );
|
|
|
|
addFacade( new ItemStack( skyStone, 1, 2 ) );
|
|
|
|
addFacade( new ItemStack( skyStone, 1, 3 ) );
|
|
|
|
}
|
2014-02-25 04:55:09 +01:00
|
|
|
}
|
2014-02-23 21:06:07 +01:00
|
|
|
|
2014-05-11 18:28:34 +02:00
|
|
|
private void initBuilderSupport()
|
|
|
|
{
|
|
|
|
SchematicRegistry.declareBlueprintSupport( AppEng.modid );
|
|
|
|
|
|
|
|
Blocks blks = AEApi.instance().blocks();
|
|
|
|
Block cable = blks.blockMultiPart.block();
|
|
|
|
for (Field f : blks.getClass().getFields())
|
|
|
|
{
|
|
|
|
AEItemDefinition def;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
def = (AEItemDefinition) f.get( blks );
|
|
|
|
if ( def != null )
|
|
|
|
{
|
|
|
|
Block myBlock = def.block();
|
|
|
|
if ( myBlock instanceof IOrientableBlock && ((IOrientableBlock) myBlock).usesMetadata() && def.entity() == null )
|
|
|
|
{
|
|
|
|
SchematicRegistry.registerSchematicBlock( myBlock, AERotateableBlockSchematic.class );
|
|
|
|
}
|
|
|
|
else if ( myBlock == cable )
|
|
|
|
{
|
|
|
|
SchematicRegistry.registerSchematicBlock( myBlock, AECableSchematicTile.class );
|
|
|
|
}
|
|
|
|
else if ( def.entity() != null )
|
|
|
|
{
|
|
|
|
SchematicRegistry.registerSchematicBlock( myBlock, AEGenericSchematicTile.class );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Throwable t)
|
|
|
|
{
|
|
|
|
// :P
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-25 04:55:09 +01:00
|
|
|
@Override
|
|
|
|
public void PostInit()
|
|
|
|
{
|
|
|
|
registerPowerP2P();
|
|
|
|
registerItemP2P();
|
2014-02-15 07:40:02 +01:00
|
|
|
registerLiquidsP2P();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-16 19:41:45 +01:00
|
|
|
public IFacadePart createFacadePart(Block blk, int meta, ForgeDirection side)
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
2014-05-10 04:08:56 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
ItemStack fs = ItemFacade.getFacade( blk, meta );
|
|
|
|
return new FacadePart( fs, side );
|
|
|
|
}
|
|
|
|
catch (Throwable t)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
ItemStack fs = ItemFacade.getStack( blk, meta );
|
|
|
|
return new FacadePart( fs, side );
|
|
|
|
}
|
|
|
|
catch (Throwable t)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2014-02-15 07:40:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IFacadePart createFacadePart(ItemStack fs, ForgeDirection side)
|
|
|
|
{
|
|
|
|
return new FacadePart( fs, side );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack getTextureForFacade(ItemStack facade)
|
|
|
|
{
|
2014-05-10 04:08:56 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
Block blk[] = ItemFacade.getBlocks( facade );
|
|
|
|
int meta[] = ItemFacade.getMetaValues( facade );
|
|
|
|
if ( blk == null || blk.length < 1 )
|
|
|
|
return null;
|
|
|
|
|
2014-06-04 03:32:33 +02:00
|
|
|
if ( blk[0] != null )
|
|
|
|
return new ItemStack( blk[0], 1, meta[0] );
|
2014-05-10 04:08:56 +02:00
|
|
|
}
|
|
|
|
catch (Throwable t)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Block blk = ItemFacade.getBlock( facade );
|
2014-06-04 03:32:33 +02:00
|
|
|
if ( blk != null )
|
|
|
|
return new ItemStack( blk, 1, ItemFacade.getMetaData( facade ) );
|
2014-05-10 04:08:56 +02:00
|
|
|
}
|
|
|
|
catch (Throwable t)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2014-02-15 07:40:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IIcon getFacadeTexture()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return BuildCraftTransport.instance.pipeIconProvider.getIcon( PipeIconProvider.TYPE.PipeStructureCobblestone.ordinal() ); // Structure
|
|
|
|
}
|
|
|
|
catch (Throwable t)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
// Pipe
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|