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-04-10 21:52:17 +02:00
|
|
|
package appeng.integration.modules;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.List;
|
2014-02-15 07:40:02 +01:00
|
|
|
|
2015-05-09 13:06:09 +02:00
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
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;
|
2014-12-29 21:59:05 +01:00
|
|
|
|
|
|
|
import cpw.mods.fml.common.eventhandler.Event;
|
|
|
|
|
|
|
|
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-02-15 07:40:02 +01:00
|
|
|
import appeng.api.AEApi;
|
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.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;
|
2015-08-06 16:01:56 +02:00
|
|
|
import appeng.helpers.Reflected;
|
2014-02-15 07:40:02 +01:00
|
|
|
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;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-02-15 07:40:02 +01:00
|
|
|
public class FMP implements IIntegrationModule, IPartFactory, IPartConverter, IFMP
|
|
|
|
{
|
2015-08-06 16:01:56 +02:00
|
|
|
@Reflected
|
2014-02-15 07:40:02 +01:00
|
|
|
public static FMP instance;
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public TMultiPart createPart( final String name, final boolean client )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
for( final PartRegistry pr : PartRegistry.values() )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( pr.getName().equals( name ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-02-15 07:40:02 +01:00
|
|
|
return pr.construct( 0 );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-02-15 07:40:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2014-07-26 03:16:00 +02:00
|
|
|
|
2014-02-15 07:40:02 +01:00
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public TMultiPart convert( final World world, final BlockCoord pos )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final Block blk = world.getBlock( pos.x, pos.y, pos.z );
|
|
|
|
final int meta = world.getBlockMetadata( pos.x, pos.y, pos.z );
|
2014-02-15 07:40:02 +01:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final TMultiPart part = PartRegistry.getPartByBlock( blk, meta );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( part instanceof CableBusPart )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final CableBusPart cbp = (CableBusPart) part;
|
2014-02-15 07:40:02 +01:00
|
|
|
cbp.convertFromTile( world.getTileEntity( pos.x, pos.y, pos.z ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return part;
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@Override
|
|
|
|
public Iterable<Block> blockTypes()
|
|
|
|
{
|
|
|
|
final IBlocks blocks = AEApi.instance().definitions().blocks();
|
|
|
|
final List<Block> blockTypes = Lists.newArrayListWithCapacity( 2 );
|
|
|
|
|
|
|
|
this.addBlockTypes( blockTypes, blocks.multiPart() );
|
|
|
|
this.addBlockTypes( blockTypes, blocks.quartzTorch() );
|
|
|
|
|
|
|
|
return blockTypes;
|
|
|
|
}
|
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
private void addBlockTypes( final Collection<Block> blockTypes, final IBlockDefinition definition )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
for( final Block block : definition.maybeBlock().asSet() )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
|
|
|
blockTypes.add( block );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-15 07:40:02 +01:00
|
|
|
@Override
|
2014-12-19 19:01:51 +01:00
|
|
|
public void init() throws Throwable
|
2014-07-26 03:16:00 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
final IBlocks blocks = AEApi.instance().definitions().blocks();
|
|
|
|
|
|
|
|
this.createAndRegister( blocks.quartz(), 0 );
|
|
|
|
this.createAndRegister( blocks.quartzPillar(), 0 );
|
|
|
|
this.createAndRegister( blocks.quartzChiseled(), 0 );
|
|
|
|
this.createAndRegister( blocks.skyStone(), 0 );
|
|
|
|
this.createAndRegister( blocks.skyStone(), 1 );
|
|
|
|
this.createAndRegister( blocks.skyStone(), 2 );
|
|
|
|
this.createAndRegister( blocks.skyStone(), 3 );
|
2014-02-15 07:40:02 +01:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final PartRegistry[] reg = PartRegistry.values();
|
2014-02-15 07:40:02 +01:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final String[] data = new String[reg.length];
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int x = 0; x < data.length; x++ )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-02-15 07:40:02 +01:00
|
|
|
data[x] = reg[x].getName();
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-02-15 07:40:02 +01:00
|
|
|
|
|
|
|
MultiPartRegistry.registerConverter( this );
|
|
|
|
MultiPartRegistry.registerParts( this, data );
|
|
|
|
|
|
|
|
MultipartGenerator.registerPassThroughInterface( "appeng.helpers.AEMultiTile" );
|
|
|
|
}
|
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
private void createAndRegister( final IBlockDefinition definition, final int i )
|
2014-07-26 03:16:00 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
for( final Block block : definition.maybeBlock().asSet() )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2014-07-26 03:16:00 +02:00
|
|
|
BlockMicroMaterial.createAndRegister( block, i );
|
2015-01-03 02:53:14 +01:00
|
|
|
}
|
2014-04-10 21:52:17 +02:00
|
|
|
}
|
|
|
|
|
2014-02-15 07:40:02 +01:00
|
|
|
@Override
|
2014-12-19 19:01:51 +01:00
|
|
|
public void postInit()
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
|
|
|
MinecraftForge.EVENT_BUS.register( new FMPEvent() );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public IPartHost getOrCreateHost( final TileEntity tile )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final BlockCoord loc = new BlockCoord( tile.xCoord, tile.yCoord, tile.zCoord );
|
2014-02-15 07:40:02 +01:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final TileMultipart mp = TileMultipart.getOrConvertTile( tile.getWorldObj(), loc );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( mp != null )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final scala.collection.Iterator<TMultiPart> i = mp.partList().iterator();
|
2015-04-03 08:54:31 +02:00
|
|
|
while( i.hasNext() )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final TMultiPart p = i.next();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( p instanceof CableBusPart )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-02-15 07:40:02 +01:00
|
|
|
return (IPartHost) p;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-02-15 07:40:02 +01:00
|
|
|
}
|
|
|
|
|
2014-07-26 03:16:00 +02:00
|
|
|
return new FMPPlacementHelper( mp );
|
2014-02-15 07:40:02 +01:00
|
|
|
}
|
|
|
|
}
|
2015-09-25 23:10:56 +02:00
|
|
|
catch( final Throwable t )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
|
|
|
AELog.error( t );
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public CableBusContainer getCableContainer( final TileEntity te )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( te instanceof TileMultipart )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final TileMultipart mp = (TileMultipart) te;
|
|
|
|
final scala.collection.Iterator<TMultiPart> i = mp.partList().iterator();
|
2015-04-03 08:54:31 +02:00
|
|
|
while( i.hasNext() )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final TMultiPart p = i.next();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( p instanceof CableBusPart )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
return ( (CableBusPart) p ).getCableBus();
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-02-15 07:40:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public void registerPassThrough( final Class<?> layerInterface )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
MultipartGenerator.registerPassThroughInterface( layerInterface.getName() );
|
|
|
|
}
|
2015-09-25 23:10:56 +02:00
|
|
|
catch( final Throwable t )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
|
|
|
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
|
2015-09-25 23:10:56 +02:00
|
|
|
public Event newFMPPacketEvent( final EntityPlayerMP sender )
|
2014-07-26 03:16:00 +02:00
|
|
|
{
|
|
|
|
return new FMPPacketEvent( sender );
|
2014-04-10 21:52:17 +02:00
|
|
|
}
|
2014-02-15 07:40:02 +01:00
|
|
|
}
|