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-08-08 08:40:17 +02:00
|
|
|
package appeng.integration.modules;
|
|
|
|
|
2014-12-31 14:10:50 +01:00
|
|
|
|
2014-08-08 08:40:17 +02:00
|
|
|
import appeng.api.AEApi;
|
2015-01-03 02:53:14 +01:00
|
|
|
import appeng.api.definitions.IBlockDefinition;
|
2014-08-08 08:40:17 +02:00
|
|
|
import appeng.api.parts.IPartHost;
|
2014-12-31 14:10:50 +01:00
|
|
|
import appeng.api.parts.IPartItem;
|
2014-08-08 08:40:17 +02:00
|
|
|
import appeng.core.AELog;
|
2015-01-03 02:53:14 +01:00
|
|
|
import appeng.helpers.Reflected;
|
2015-09-25 23:28:57 +02:00
|
|
|
import appeng.integration.IIntegrationModule;
|
2015-08-06 16:01:56 +02:00
|
|
|
import appeng.integration.IntegrationHelper;
|
2014-08-08 08:40:17 +02:00
|
|
|
import appeng.integration.abstraction.IImmibisMicroblocks;
|
2017-04-12 16:10:13 +02:00
|
|
|
import com.google.common.base.Optional;
|
|
|
|
import mods.immibis.core.api.multipart.ICoverSystem;
|
|
|
|
import mods.immibis.core.api.multipart.IMultipartTile;
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
import java.lang.reflect.Method;
|
2014-08-08 08:40:17 +02:00
|
|
|
|
2014-12-31 14:10:50 +01:00
|
|
|
|
2015-09-25 23:28:57 +02:00
|
|
|
public class ImmibisMicroblocks implements IImmibisMicroblocks, IIntegrationModule
|
2014-08-08 08:40:17 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
@Reflected
|
2015-05-08 22:53:50 +02:00
|
|
|
public static ImmibisMicroblocks instance;
|
2014-08-08 08:40:17 +02:00
|
|
|
|
2014-12-31 14:10:50 +01:00
|
|
|
private boolean canConvertTiles = false;
|
2014-08-08 08:40:17 +02:00
|
|
|
|
2014-12-31 14:10:50 +01:00
|
|
|
private Class<?> MicroblockAPIUtils;
|
2014-08-08 08:40:17 +02:00
|
|
|
private Method mergeIntoMicroblockContainer;
|
|
|
|
|
2015-08-06 16:01:56 +02:00
|
|
|
@Reflected
|
|
|
|
public ImmibisMicroblocks()
|
|
|
|
{
|
|
|
|
IntegrationHelper.testClassExistence( this, mods.immibis.core.api.multipart.IMultipartTile.class );
|
|
|
|
IntegrationHelper.testClassExistence( this, mods.immibis.core.api.multipart.ICoverSystem.class );
|
|
|
|
IntegrationHelper.testClassExistence( this, mods.immibis.core.api.multipart.IPartContainer.class );
|
|
|
|
}
|
|
|
|
|
2014-08-08 08:40:17 +02:00
|
|
|
@Override
|
2014-12-19 19:01:51 +01:00
|
|
|
public void init() throws Throwable
|
2014-08-08 08:40:17 +02:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.MicroblockAPIUtils = Class.forName( "mods.immibis.microblocks.api.MicroblockAPIUtils" );
|
2015-04-03 08:54:31 +02:00
|
|
|
this.mergeIntoMicroblockContainer = this.MicroblockAPIUtils.getMethod( "mergeIntoMicroblockContainer", ItemStack.class, EntityPlayer.class, World.class, int.class, int.class, int.class, int.class, Block.class, int.class );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.canConvertTiles = true;
|
2014-08-08 08:40:17 +02:00
|
|
|
}
|
2015-09-25 23:10:56 +02:00
|
|
|
catch( final Throwable t )
|
2014-08-08 08:40:17 +02:00
|
|
|
{
|
2015-11-22 15:54:29 +01:00
|
|
|
AELog.debug( t );
|
2014-08-08 08:40:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-12-19 19:01:51 +01:00
|
|
|
public void postInit()
|
2014-08-08 08:40:17 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public IPartHost getOrCreateHost( final EntityPlayer player, final int side, final TileEntity te )
|
2014-08-08 08:40:17 +02:00
|
|
|
{
|
2014-12-31 14:10:50 +01:00
|
|
|
final World w = te.getWorldObj();
|
|
|
|
final int x = te.xCoord;
|
|
|
|
final int y = te.yCoord;
|
|
|
|
final int z = te.zCoord;
|
|
|
|
final boolean isPartItem = player != null && player.getHeldItem() != null && player.getHeldItem().getItem() instanceof IPartItem;
|
2014-08-08 08:40:17 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( te instanceof IMultipartTile && this.canConvertTiles && isPartItem )
|
2014-12-31 14:10:50 +01:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
final IBlockDefinition multiPart = AEApi.instance().definitions().blocks().multiPart();
|
|
|
|
final Optional<Block> maybeMultiPartBlock = multiPart.maybeBlock();
|
|
|
|
final Optional<ItemStack> maybeMultiPartStack = multiPart.maybeStack( 1 );
|
2014-08-08 08:40:17 +02:00
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
final boolean multiPartPresent = maybeMultiPartBlock.isPresent() && maybeMultiPartStack.isPresent();
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( multiPartPresent )
|
2014-08-08 08:40:17 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
final Block multiPartBlock = maybeMultiPartBlock.get();
|
|
|
|
final ItemStack multiPartStack = maybeMultiPartStack.get();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// ItemStack.class, EntityPlayer.class, World.class,
|
|
|
|
// int.class, int.class, int.class, int.class, Block.class, int.class );
|
|
|
|
this.mergeIntoMicroblockContainer.invoke( null, multiPartStack, player, w, x, y, z, side, multiPartBlock, 0 );
|
|
|
|
}
|
2015-09-25 23:10:56 +02:00
|
|
|
catch( final Throwable e )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
this.canConvertTiles = false;
|
|
|
|
return null;
|
|
|
|
}
|
2014-08-08 08:40:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-31 14:10:50 +01:00
|
|
|
final TileEntity tx = w.getTileEntity( x, y, z );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( tx instanceof IPartHost )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return (IPartHost) tx;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-12-31 14:10:50 +01:00
|
|
|
|
2014-08-08 08:40:17 +02:00
|
|
|
return null;
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public boolean leaveParts( final TileEntity te )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
|
|
|
if( te instanceof IMultipartTile )
|
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final ICoverSystem ci = ( (IMultipartTile) te ).getCoverSystem();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ci != null )
|
|
|
|
{
|
|
|
|
ci.convertToContainerBlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2014-08-08 08:40:17 +02:00
|
|
|
}
|