2014-04-10 21:52:17 +02:00
|
|
|
package appeng.integration.modules;
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
2014-02-15 07:40:02 +01:00
|
|
|
|
|
|
|
import net.minecraft.block.Block;
|
2014-04-10 21:52:17 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
2014-02-15 07:40:02 +01:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
|
|
import appeng.api.AEApi;
|
2014-04-10 21:52:17 +02:00
|
|
|
import appeng.api.definitions.Blocks;
|
2014-02-15 07:40:02 +01:00
|
|
|
import appeng.api.parts.IPartHost;
|
|
|
|
import appeng.core.AELog;
|
|
|
|
import appeng.fmp.CableBusPart;
|
|
|
|
import appeng.fmp.FMPEvent;
|
2014-07-26 03:16:00 +02:00
|
|
|
import appeng.fmp.FMPPlacementHelper;
|
2014-02-15 07:40:02 +01:00
|
|
|
import appeng.fmp.PartRegistry;
|
|
|
|
import appeng.integration.IIntegrationModule;
|
|
|
|
import appeng.integration.abstraction.IFMP;
|
2014-04-10 21:52:17 +02:00
|
|
|
import appeng.integration.modules.helpers.FMPPacketEvent;
|
2014-02-15 07:40:02 +01:00
|
|
|
import appeng.parts.CableBusContainer;
|
|
|
|
import codechicken.lib.vec.BlockCoord;
|
|
|
|
import codechicken.microblock.BlockMicroMaterial;
|
|
|
|
import codechicken.multipart.MultiPartRegistry;
|
|
|
|
import codechicken.multipart.MultiPartRegistry.IPartConverter;
|
|
|
|
import codechicken.multipart.MultiPartRegistry.IPartFactory;
|
|
|
|
import codechicken.multipart.MultipartGenerator;
|
|
|
|
import codechicken.multipart.TMultiPart;
|
|
|
|
import codechicken.multipart.TileMultipart;
|
2014-04-10 21:52:17 +02:00
|
|
|
import cpw.mods.fml.common.eventhandler.Event;
|
2014-02-15 07:40:02 +01:00
|
|
|
|
|
|
|
public class FMP implements IIntegrationModule, IPartFactory, IPartConverter, IFMP
|
|
|
|
{
|
|
|
|
|
|
|
|
public static FMP instance;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public TMultiPart createPart(String name, boolean client)
|
|
|
|
{
|
|
|
|
for (PartRegistry pr : PartRegistry.values())
|
|
|
|
{
|
2014-09-29 09:28:58 +02:00
|
|
|
if ( pr.getName().equals( name ) )
|
2014-02-15 07:40:02 +01:00
|
|
|
return pr.construct( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2014-07-26 03:16:00 +02:00
|
|
|
|
2014-02-15 07:40:02 +01:00
|
|
|
@Override
|
|
|
|
public TMultiPart convert(World world, BlockCoord pos)
|
|
|
|
{
|
2014-04-10 21:52:17 +02:00
|
|
|
Block blk = world.getBlock( pos.x, pos.y, pos.z );
|
2014-02-15 07:40:02 +01:00
|
|
|
int meta = world.getBlockMetadata( pos.x, pos.y, pos.z );
|
|
|
|
|
2014-04-10 21:52:17 +02:00
|
|
|
TMultiPart part = PartRegistry.getPartByBlock( blk, meta );
|
2014-02-15 07:40:02 +01:00
|
|
|
if ( part instanceof CableBusPart )
|
|
|
|
{
|
|
|
|
CableBusPart cbp = (CableBusPart) part;
|
|
|
|
cbp.convertFromTile( world.getTileEntity( pos.x, pos.y, pos.z ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return part;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void Init() throws Throwable
|
2014-07-26 03:16:00 +02:00
|
|
|
{
|
|
|
|
createAndRegister( AEApi.instance().blocks().blockQuartz.block(), 0 );
|
2014-09-20 22:36:48 +02:00
|
|
|
createAndRegister( AEApi.instance().blocks().blockQuartzPillar.block(), 0 );
|
2014-07-26 03:16:00 +02:00
|
|
|
createAndRegister( AEApi.instance().blocks().blockQuartzChiseled.block(), 0 );
|
|
|
|
createAndRegister( AEApi.instance().blocks().blockSkyStone.block(), 0 );
|
|
|
|
createAndRegister( AEApi.instance().blocks().blockSkyStone.block(), 1 );
|
|
|
|
createAndRegister( AEApi.instance().blocks().blockSkyStone.block(), 2 );
|
|
|
|
createAndRegister( AEApi.instance().blocks().blockSkyStone.block(), 3 );
|
2014-02-15 07:40:02 +01:00
|
|
|
|
|
|
|
PartRegistry reg[] = PartRegistry.values();
|
|
|
|
|
|
|
|
String data[] = new String[reg.length];
|
|
|
|
for (int x = 0; x < data.length; x++)
|
|
|
|
data[x] = reg[x].getName();
|
|
|
|
|
|
|
|
MultiPartRegistry.registerConverter( this );
|
|
|
|
MultiPartRegistry.registerParts( this, data );
|
|
|
|
|
|
|
|
MultipartGenerator.registerPassThroughInterface( "appeng.helpers.AEMultiTile" );
|
|
|
|
}
|
|
|
|
|
2014-07-26 03:16:00 +02:00
|
|
|
private void createAndRegister(Block block, int i)
|
|
|
|
{
|
2014-04-10 21:52:17 +02:00
|
|
|
if ( block != null )
|
2014-07-26 03:16:00 +02:00
|
|
|
BlockMicroMaterial.createAndRegister( block, i );
|
2014-04-10 21:52:17 +02:00
|
|
|
}
|
|
|
|
|
2014-02-15 07:40:02 +01:00
|
|
|
@Override
|
2014-11-04 12:36:16 +01:00
|
|
|
public void PostInit()
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
|
|
|
MinecraftForge.EVENT_BUS.register( new FMPEvent() );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IPartHost getOrCreateHost(TileEntity tile)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
BlockCoord loc = new BlockCoord( tile.xCoord, tile.yCoord, tile.zCoord );
|
|
|
|
|
2014-04-10 21:52:17 +02:00
|
|
|
TileMultipart mp = TileMultipart.getOrConvertTile( tile.getWorldObj(), loc );
|
2014-02-15 07:40:02 +01:00
|
|
|
if ( mp != null )
|
|
|
|
{
|
|
|
|
scala.collection.Iterator<TMultiPart> i = mp.partList().iterator();
|
|
|
|
while (i.hasNext())
|
|
|
|
{
|
|
|
|
TMultiPart p = i.next();
|
|
|
|
if ( p instanceof CableBusPart )
|
|
|
|
return (IPartHost) p;
|
|
|
|
}
|
|
|
|
|
2014-07-26 03:16:00 +02:00
|
|
|
return new FMPPlacementHelper( mp );
|
2014-02-15 07:40:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Throwable t)
|
|
|
|
{
|
|
|
|
AELog.error( t );
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public CableBusContainer getCableContainer(TileEntity te)
|
|
|
|
{
|
|
|
|
if ( te instanceof TileMultipart )
|
|
|
|
{
|
|
|
|
TileMultipart mp = (TileMultipart) te;
|
|
|
|
scala.collection.Iterator<TMultiPart> i = mp.partList().iterator();
|
|
|
|
while (i.hasNext())
|
|
|
|
{
|
|
|
|
TMultiPart p = i.next();
|
|
|
|
if ( p instanceof CableBusPart )
|
|
|
|
return ((CableBusPart) p).cb;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-09-21 00:30:21 +02:00
|
|
|
public void registerPassThrough(Class<?> layerInterface)
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
MultipartGenerator.registerPassThroughInterface( layerInterface.getName() );
|
|
|
|
}
|
|
|
|
catch (Throwable t)
|
|
|
|
{
|
|
|
|
AELog.severe( "Failed to register " + layerInterface.getName() + " with FMP, some features may not work with MultiParts." );
|
|
|
|
AELog.error( t );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-10 21:52:17 +02:00
|
|
|
@Override
|
2014-07-26 03:16:00 +02:00
|
|
|
public Event newFMPPacketEvent(EntityPlayerMP sender)
|
|
|
|
{
|
|
|
|
return new FMPPacketEvent( sender );
|
2014-04-10 21:52:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-07-26 03:16:00 +02:00
|
|
|
public Iterable<Block> blockTypes()
|
|
|
|
{
|
|
|
|
Blocks def = AEApi.instance().blocks();
|
2014-04-10 21:52:17 +02:00
|
|
|
return Arrays.asList( def.blockMultiPart.block(), def.blockQuartzTorch.block() );
|
|
|
|
}
|
|
|
|
|
2014-02-15 07:40:02 +01:00
|
|
|
}
|