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-03-18 18:54:57 +01:00
|
|
|
package appeng.integration.modules;
|
2014-02-15 07:40:02 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-02-15 07:40:02 +01:00
|
|
|
import java.lang.reflect.Field;
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2014-12-29 21:59:05 +01:00
|
|
|
|
2014-02-15 07:40:02 +01:00
|
|
|
import appeng.api.AEApi;
|
|
|
|
import appeng.api.storage.IMEInventory;
|
|
|
|
import appeng.integration.IIntegrationModule;
|
|
|
|
import appeng.integration.abstraction.IFZ;
|
2014-03-18 18:54:57 +01:00
|
|
|
import appeng.integration.modules.helpers.FactorizationBarrel;
|
|
|
|
import appeng.integration.modules.helpers.FactorizationHandler;
|
2014-02-15 07:40:02 +01:00
|
|
|
import appeng.util.Platform;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-02-15 07:40:02 +01:00
|
|
|
/**
|
|
|
|
* 100% Hacks.
|
|
|
|
*/
|
|
|
|
public class FZ implements IFZ, IIntegrationModule
|
|
|
|
{
|
|
|
|
|
|
|
|
public static FZ instance;
|
|
|
|
|
2014-11-04 02:06:52 +01:00
|
|
|
private static Class<?> day_BarrelClass;
|
2014-02-15 07:40:02 +01:00
|
|
|
private static Method day_getItemCount;
|
|
|
|
private static Method day_setItemCount;
|
|
|
|
private static Method day_getMaxSize;
|
|
|
|
private static Field day_item;
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public ItemStack barrelGetItem( TileEntity te )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2014-03-18 18:54:57 +01:00
|
|
|
ItemStack i = null;
|
2014-02-15 07:40:02 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( day_BarrelClass.isInstance( te ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-02-15 07:40:02 +01:00
|
|
|
i = (ItemStack) day_item.get( te );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-02-15 07:40:02 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( i != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-02-15 07:40:02 +01:00
|
|
|
i = Platform.cloneItemStack( i );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-03-19 03:55:49 +01:00
|
|
|
|
2014-02-15 07:40:02 +01:00
|
|
|
return i;
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( IllegalArgumentException ignored )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( IllegalAccessException ignored )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public int barrelGetMaxItemCount( TileEntity te )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( day_BarrelClass.isInstance( te ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-02-15 07:40:02 +01:00
|
|
|
return (Integer) day_getMaxSize.invoke( te );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-02-15 07:40:02 +01:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( IllegalAccessException ignored )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( IllegalArgumentException ignored )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( InvocationTargetException ignored )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public int barrelGetItemCount( TileEntity te )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( day_BarrelClass.isInstance( te ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-02-15 07:40:02 +01:00
|
|
|
return (Integer) day_getItemCount.invoke( te );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-02-15 07:40:02 +01:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( IllegalAccessException ignored )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( IllegalArgumentException ignored )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( InvocationTargetException ignored )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void setItemType( TileEntity te, ItemStack input )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( day_BarrelClass.isInstance( te ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-02-15 07:40:02 +01:00
|
|
|
day_item.set( te, input == null ? null : input.copy() );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-02-15 07:40:02 +01:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( IllegalArgumentException ignored )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( IllegalAccessException ignored )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void barrelSetCount( TileEntity te, int max )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( day_BarrelClass.isInstance( te ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-02-15 07:40:02 +01:00
|
|
|
day_setItemCount.invoke( te, max );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-02-15 07:40:02 +01:00
|
|
|
|
|
|
|
te.markDirty();
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( IllegalAccessException ignored )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( IllegalArgumentException ignored )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( InvocationTargetException ignored )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public IMEInventory getFactorizationBarrel( TileEntity te )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
|
|
|
return new FactorizationBarrel( this, te );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public boolean isBarrel( TileEntity te )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
2014-11-04 02:07:36 +01:00
|
|
|
return day_BarrelClass.isAssignableFrom( te.getClass() );
|
2014-02-15 07:40:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void grinderRecipe( ItemStack in, ItemStack out )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2014-11-04 02:07:20 +01:00
|
|
|
Class<?> c = Class.forName( "factorization.oreprocessing.TileEntityGrinder" );
|
2014-02-15 07:40:02 +01:00
|
|
|
Method m = c.getMethod( "addRecipe", Object.class, ItemStack.class, float.class );
|
2014-03-19 03:55:49 +01:00
|
|
|
|
|
|
|
float amt = out.stackSize;
|
|
|
|
out.stackSize = 1;
|
|
|
|
|
|
|
|
m.invoke( c, in, out, amt );
|
2014-02-15 07:40:02 +01:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( Throwable t )
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
|
|
|
// AELog.info( "" );
|
|
|
|
// throw new RuntimeException( t );
|
|
|
|
}
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void init() throws Throwable
|
|
|
|
{
|
|
|
|
day_BarrelClass = Class.forName( "factorization.weird.TileEntityDayBarrel" );
|
|
|
|
|
|
|
|
day_getItemCount = day_BarrelClass.getDeclaredMethod( "getItemCount" );
|
|
|
|
day_setItemCount = day_BarrelClass.getDeclaredMethod( "setItemCount", int.class );
|
|
|
|
day_getMaxSize = day_BarrelClass.getDeclaredMethod( "getMaxSize" );
|
|
|
|
day_item = day_BarrelClass.getDeclaredField( "item" );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void postInit()
|
|
|
|
{
|
|
|
|
AEApi.instance().registries().externalStorage().addExternalStorageInterface( new FactorizationHandler() );
|
|
|
|
}
|
2014-02-15 07:40:02 +01:00
|
|
|
}
|