2014-11-14 12:02:52 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Applied Energistics 2.
|
|
|
|
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
|
|
|
*/
|
|
|
|
|
2014-02-16 19:41:45 +01:00
|
|
|
package appeng.integration.modules;
|
2014-02-15 07:40:02 +01:00
|
|
|
|
2014-11-28 04:36:46 +01:00
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
import java.lang.reflect.Method;
|
2014-05-11 18:28:34 +02:00
|
|
|
|
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;
|
2014-11-28 04:36:46 +01:00
|
|
|
|
|
|
|
import cpw.mods.fml.common.event.FMLInterModComms;
|
|
|
|
|
|
|
|
import buildcraft.BuildCraftEnergy;
|
|
|
|
import buildcraft.BuildCraftTransport;
|
2014-12-21 19:08:05 +01:00
|
|
|
import buildcraft.api.blueprints.BuilderAPI;
|
|
|
|
import buildcraft.api.blueprints.ISchematicRegistry;
|
|
|
|
import buildcraft.api.facades.IFacadeItem;
|
2014-11-28 04:36:46 +01:00
|
|
|
import buildcraft.api.tools.IToolWrench;
|
2014-12-21 19:08:05 +01:00
|
|
|
import buildcraft.api.transport.IInjectable;
|
2014-11-28 04:36:46 +01:00
|
|
|
import buildcraft.api.transport.IPipeConnection;
|
|
|
|
import buildcraft.api.transport.IPipeTile;
|
|
|
|
import buildcraft.transport.ItemFacade;
|
|
|
|
import buildcraft.transport.PipeIconProvider;
|
|
|
|
|
2014-02-15 07:40:02 +01:00
|
|
|
import appeng.api.AEApi;
|
2015-01-03 02:53:14 +01:00
|
|
|
import appeng.api.IAppEngApi;
|
2014-02-15 07:40:02 +01:00
|
|
|
import appeng.api.config.TunnelType;
|
2015-01-03 02:53:14 +01:00
|
|
|
import appeng.api.definitions.IBlockDefinition;
|
|
|
|
import appeng.api.definitions.IBlocks;
|
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;
|
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;
|
2014-11-28 04:36:46 +01:00
|
|
|
import appeng.integration.modules.BCHelpers.AERotatableBlockSchematic;
|
2014-05-11 18:28:34 +02:00
|
|
|
import appeng.integration.modules.BCHelpers.BCPipeHandler;
|
2014-02-15 07:40:02 +01:00
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
|
2014-12-21 19:08:05 +01:00
|
|
|
public final class BC extends BaseModule implements IBC
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
public static BC instance;
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
public BC()
|
|
|
|
{
|
2014-12-19 19:01:51 +01:00
|
|
|
this.testClassExistence( IPipeConnection.class );
|
|
|
|
this.testClassExistence( ItemFacade.class );
|
|
|
|
this.testClassExistence( IToolWrench.class );
|
2014-04-06 08:55:24 +02:00
|
|
|
}
|
|
|
|
|
2014-02-15 07:40:02 +01:00
|
|
|
@Override
|
2015-01-03 02:53:14 +01:00
|
|
|
public boolean isWrench( Item eq )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
|
|
|
return eq instanceof IToolWrench;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-01-03 02:53:14 +01:00
|
|
|
public boolean canWrench( Item i, EntityPlayer p, int x, int y, int z )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
return ( (IToolWrench) i ).canWrench( p, x, y, z );
|
2014-02-15 07:40:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-01-03 02:53:14 +01:00
|
|
|
public void wrenchUsed( Item i, EntityPlayer p, int x, int y, int z )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
( (IToolWrench) i ).wrenchUsed( p, x, y, z );
|
2014-02-15 07:40:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-01-03 02:53:14 +01:00
|
|
|
public boolean canAddItemsToPipe( TileEntity te, ItemStack is, ForgeDirection dir )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
if ( is != null && te != null && te instanceof IInjectable )
|
|
|
|
{
|
|
|
|
IInjectable pt = (IInjectable) te;
|
|
|
|
if ( pt.canInjectItems( dir ) )
|
|
|
|
{
|
|
|
|
int amt = pt.injectItem( is, false, dir, null );
|
|
|
|
if ( amt == is.stackSize )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2014-02-15 07:40:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-01-03 02:53:14 +01:00
|
|
|
public boolean addItemsToPipe( TileEntity te, ItemStack is, ForgeDirection dir )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
2014-12-21 19:08:05 +01:00
|
|
|
if ( is != null && te != null && te instanceof IInjectable )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
2014-12-21 19:08:05 +01:00
|
|
|
IInjectable pt = (IInjectable) te;
|
|
|
|
if ( pt.canInjectItems( dir ) )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
2014-12-21 19:08:05 +01:00
|
|
|
int amt = pt.injectItem( is, false, dir, null );
|
2014-02-15 07:40:02 +01:00
|
|
|
if ( amt == is.stackSize )
|
|
|
|
{
|
2014-12-21 19:08:05 +01:00
|
|
|
pt.injectItem( is, true, dir, null );
|
2014-02-15 07:40:02 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-01-03 02:53:14 +01:00
|
|
|
public boolean isFacade( ItemStack is )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
|
|
|
if ( is == null )
|
|
|
|
return false;
|
2014-05-10 04:08:56 +02:00
|
|
|
|
2014-12-21 19:08:05 +01:00
|
|
|
return is.getItem() instanceof IFacadeItem;
|
2014-02-15 07:40:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-01-03 02:53:14 +01:00
|
|
|
public boolean isPipe( TileEntity te, ForgeDirection dir )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
if ( te instanceof IPipeTile )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
final IPipeTile pipeTile = (IPipeTile) te;
|
|
|
|
return !pipeTile.hasPipePluggable( dir.getOpposite() );
|
2014-02-15 07:40:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
@Override
|
|
|
|
public void addFacade( ItemStack item )
|
|
|
|
{
|
|
|
|
if ( item != null )
|
|
|
|
FMLInterModComms.sendMessage( "BuildCraft|Transport", "add-facade", item );
|
|
|
|
}
|
|
|
|
|
2014-02-15 07:40:02 +01:00
|
|
|
@Override
|
|
|
|
public void registerPowerP2P()
|
|
|
|
{
|
|
|
|
IP2PTunnelRegistry reg = AEApi.instance().registries().p2pTunnel();
|
2014-12-21 19:08:05 +01:00
|
|
|
reg.addNewAttunement( new ItemStack( BuildCraftEnergy.engineBlock, 1, 0 ), TunnelType.RF_POWER );
|
|
|
|
reg.addNewAttunement( new ItemStack( BuildCraftEnergy.engineBlock, 1, 1 ), TunnelType.RF_POWER );
|
|
|
|
reg.addNewAttunement( new ItemStack( BuildCraftEnergy.engineBlock, 1, 2 ), TunnelType.RF_POWER );
|
|
|
|
reg.addNewAttunement( new ItemStack( BuildCraftTransport.pipePowerCobblestone ), TunnelType.RF_POWER );
|
|
|
|
reg.addNewAttunement( new ItemStack( BuildCraftTransport.pipePowerDiamond ), TunnelType.RF_POWER );
|
|
|
|
reg.addNewAttunement( new ItemStack( BuildCraftTransport.pipePowerGold ), TunnelType.RF_POWER );
|
|
|
|
reg.addNewAttunement( new ItemStack( BuildCraftTransport.pipePowerQuartz ), TunnelType.RF_POWER );
|
|
|
|
reg.addNewAttunement( new ItemStack( BuildCraftTransport.pipePowerStone ), TunnelType.RF_POWER );
|
|
|
|
reg.addNewAttunement( new ItemStack( BuildCraftTransport.pipePowerWood ), TunnelType.RF_POWER );
|
2014-02-15 07:40:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@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
|
2015-01-03 02:53:14 +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
|
|
|
|
{
|
2014-12-21 19:08:05 +01:00
|
|
|
final ItemFacade.FacadeState state = ItemFacade.FacadeState.create( blk, meta );
|
|
|
|
final ItemStack facade = ItemFacade.getFacade( state );
|
2014-05-10 04:08:56 +02:00
|
|
|
|
2014-12-21 19:08:05 +01:00
|
|
|
return new FacadePart( facade, side );
|
2014-05-10 04:08:56 +02:00
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
catch ( Throwable ignored )
|
2014-05-10 04:08:56 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2014-02-15 07:40:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-01-03 02:53:14 +01:00
|
|
|
public IFacadePart createFacadePart( ItemStack fs, ForgeDirection side )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
|
|
|
return new FacadePart( fs, side );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-01-03 02:53:14 +01:00
|
|
|
public ItemStack getTextureForFacade( ItemStack facade )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
2014-12-21 19:08:05 +01:00
|
|
|
final Item maybeFacadeItem = facade.getItem();
|
2014-05-10 04:08:56 +02:00
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
if ( maybeFacadeItem instanceof buildcraft.api.facades.IFacadeItem )
|
2014-05-10 04:08:56 +02:00
|
|
|
{
|
2014-12-21 19:08:05 +01:00
|
|
|
final buildcraft.api.facades.IFacadeItem facadeItem = (buildcraft.api.facades.IFacadeItem) maybeFacadeItem;
|
2014-05-10 04:08:56 +02:00
|
|
|
|
2014-12-21 19:08:05 +01:00
|
|
|
final Block[] blocks = facadeItem.getBlocksForFacade( facade );
|
|
|
|
final int[] metas = facadeItem.getMetaValuesForFacade( facade );
|
2014-05-10 04:08:56 +02:00
|
|
|
|
2014-12-21 19:08:05 +01:00
|
|
|
if ( blocks.length > 0 && metas.length > 0 )
|
|
|
|
{
|
|
|
|
return new ItemStack( blocks[0], 1, metas[0] );
|
|
|
|
}
|
2014-05-10 04:08:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
catch ( Throwable ignored )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
// Pipe
|
|
|
|
}
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
private void addFacadeStack( IBlockDefinition definition )
|
|
|
|
{
|
|
|
|
for ( ItemStack facadeStack : definition.maybeStack( 1 ).asSet() )
|
|
|
|
{
|
|
|
|
this.addFacade( facadeStack );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void init()
|
|
|
|
{
|
|
|
|
final IAppEngApi api = AEApi.instance();
|
|
|
|
|
|
|
|
api.partHelper().registerNewLayer( "appeng.parts.layers.LayerIPipeConnection", "buildcraft.api.transport.IPipeConnection" );
|
|
|
|
api.registries().externalStorage().addExternalStorageInterface( new BCPipeHandler() );
|
|
|
|
|
|
|
|
final IBlocks blocks = api.definitions().blocks();
|
|
|
|
|
|
|
|
this.addFacadeStack( blocks.fluix() );
|
|
|
|
this.addFacadeStack( blocks.quartz() );
|
|
|
|
this.addFacadeStack( blocks.quartzChiseled() );
|
|
|
|
this.addFacadeStack( blocks.quartzPillar() );
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
this.initBuilderSupport();
|
|
|
|
}
|
|
|
|
catch ( Throwable builderSupport )
|
|
|
|
{
|
|
|
|
// not supported?
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( Block skyStoneBlock : blocks.skyStone().maybeBlock().asSet() )
|
|
|
|
{
|
|
|
|
this.addFacade( new ItemStack( skyStoneBlock, 1, 0 ) );
|
|
|
|
this.addFacade( new ItemStack( skyStoneBlock, 1, 1 ) );
|
|
|
|
this.addFacade( new ItemStack( skyStoneBlock, 1, 2 ) );
|
|
|
|
this.addFacade( new ItemStack( skyStoneBlock, 1, 3 ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initBuilderSupport()
|
|
|
|
{
|
|
|
|
final ISchematicRegistry schematicRegistry = BuilderAPI.schematicRegistry;
|
|
|
|
|
|
|
|
final IBlocks blocks = AEApi.instance().definitions().blocks();
|
|
|
|
final IBlockDefinition maybeMultiPart = blocks.multiPart();
|
|
|
|
|
|
|
|
for ( Method blockDefinition : blocks.getClass().getMethods() )
|
|
|
|
{
|
|
|
|
AEItemDefinition def;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
def = (AEItemDefinition) blockDefinition.invoke( blocks );
|
|
|
|
|
|
|
|
Block myBlock = def.block();
|
|
|
|
if ( myBlock instanceof IOrientableBlock && ( (IOrientableBlock) myBlock ).usesMetadata() && def.entity() == null )
|
|
|
|
{
|
|
|
|
schematicRegistry.registerSchematicBlock( myBlock, AERotatableBlockSchematic.class );
|
|
|
|
}
|
|
|
|
else if ( maybeMultiPart.isSameAs( new ItemStack( myBlock ) ) )
|
|
|
|
{
|
|
|
|
schematicRegistry.registerSchematicBlock( myBlock, AECableSchematicTile.class );
|
|
|
|
}
|
|
|
|
else if ( def.entity() != null )
|
|
|
|
{
|
|
|
|
schematicRegistry.registerSchematicBlock( myBlock, AEGenericSchematicTile.class );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch ( Throwable t )
|
|
|
|
{
|
|
|
|
// :P
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void postInit()
|
|
|
|
{
|
|
|
|
this.registerPowerP2P();
|
|
|
|
this.registerItemP2P();
|
|
|
|
this.registerLiquidsP2P();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void registerOrientableBlocks()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2014-02-15 07:40:02 +01:00
|
|
|
}
|