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 java.lang.reflect.Method;
|
|
|
|
|
|
|
|
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;
|
2014-12-29 21:59:05 +01:00
|
|
|
|
|
|
|
import mods.immibis.core.api.multipart.ICoverSystem;
|
|
|
|
import mods.immibis.core.api.multipart.IMultipartTile;
|
|
|
|
import mods.immibis.core.api.multipart.IPartContainer;
|
|
|
|
|
2014-08-08 08:40:17 +02:00
|
|
|
import appeng.api.AEApi;
|
|
|
|
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;
|
|
|
|
import appeng.integration.BaseModule;
|
|
|
|
import appeng.integration.abstraction.IImmibisMicroblocks;
|
|
|
|
|
2014-12-31 14:10:50 +01:00
|
|
|
|
2014-08-08 08:40:17 +02:00
|
|
|
public class ImmibisMicroblocks extends BaseModule implements IImmibisMicroblocks
|
|
|
|
{
|
|
|
|
|
2014-12-31 14:10:50 +01: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;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void Init() throws Throwable
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.TestClass( IMultipartTile.class );
|
|
|
|
this.TestClass( ICoverSystem.class );
|
|
|
|
this.TestClass( IPartContainer.class );
|
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" );
|
|
|
|
this.mergeIntoMicroblockContainer = this.MicroblockAPIUtils.getMethod( "mergeIntoMicroblockContainer", ItemStack.class, EntityPlayer.class, World.class,
|
2014-08-08 08:40:17 +02:00
|
|
|
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
|
|
|
}
|
2014-12-31 14:10:50 +01:00
|
|
|
catch ( Throwable t )
|
2014-08-08 08:40:17 +02:00
|
|
|
{
|
|
|
|
AELog.error( t );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-11-04 12:36:16 +01:00
|
|
|
public void PostInit()
|
2014-08-08 08:40:17 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-12-31 14:10:50 +01:00
|
|
|
public boolean leaveParts( TileEntity te )
|
2014-08-08 08:40:17 +02:00
|
|
|
{
|
|
|
|
if ( te instanceof IMultipartTile )
|
|
|
|
{
|
2014-12-31 14:10:50 +01:00
|
|
|
ICoverSystem ci = ( ( IMultipartTile ) te ).getCoverSystem();
|
2014-08-08 08:40:17 +02:00
|
|
|
if ( ci != null )
|
2014-12-31 14:10:50 +01:00
|
|
|
{
|
2014-08-08 08:40:17 +02:00
|
|
|
ci.convertToContainerBlock();
|
2014-12-31 14:10:50 +01:00
|
|
|
}
|
2014-08-08 08:40:17 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-12-31 14:10:50 +01:00
|
|
|
public IPartHost getOrCreateHost( EntityPlayer player, int side, 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
|
|
|
|
2014-12-31 14:10:50 +01:00
|
|
|
if ( te instanceof IMultipartTile && this.canConvertTiles && isPartItem )
|
|
|
|
{
|
|
|
|
final Block blk = AEApi.instance().blocks().blockMultiPart.block();
|
|
|
|
final ItemStack what = AEApi.instance().blocks().blockMultiPart.stack( 1 );
|
2014-08-08 08:40:17 +02:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// 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.mergeIntoMicroblockContainer.invoke( null, what, player, w, x, y, z, side, blk, 0 );
|
2014-08-08 08:40:17 +02:00
|
|
|
}
|
2014-12-31 14:10:50 +01:00
|
|
|
catch ( Throwable e )
|
2014-08-08 08:40:17 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.canConvertTiles = false;
|
2014-09-28 11:47:17 +02:00
|
|
|
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 );
|
|
|
|
if ( tx instanceof IPartHost )
|
|
|
|
return ( IPartHost ) tx;
|
|
|
|
|
2014-08-08 08:40:17 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|