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>.
|
|
|
|
*/
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
package appeng.util;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.inventory.IInventory;
|
|
|
|
import net.minecraft.inventory.ISidedInventory;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.tileentity.TileEntityChest;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2014-12-29 21:59:05 +01:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.config.FuzzyMode;
|
2014-08-12 18:58:24 +02:00
|
|
|
import appeng.core.AppEng;
|
|
|
|
import appeng.integration.IntegrationType;
|
|
|
|
import appeng.integration.abstraction.IBetterStorage;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.util.inv.AdaptorIInventory;
|
|
|
|
import appeng.util.inv.AdaptorList;
|
|
|
|
import appeng.util.inv.AdaptorPlayerInventory;
|
|
|
|
import appeng.util.inv.IInventoryDestination;
|
|
|
|
import appeng.util.inv.ItemSlot;
|
|
|
|
import appeng.util.inv.WrapperMCISidedInventory;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
public abstract class InventoryAdaptor implements Iterable<ItemSlot>
|
|
|
|
{
|
|
|
|
|
|
|
|
// returns an appropriate adaptor, or null
|
2015-04-03 08:54:31 +02:00
|
|
|
public static InventoryAdaptor getAdaptor( Object te, ForgeDirection d )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( te == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
return null;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-02-03 12:04:13 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
IBetterStorage bs = (IBetterStorage) ( AppEng.instance.isIntegrationEnabled( IntegrationType.BetterStorage ) ? AppEng.instance.getIntegration( IntegrationType.BetterStorage ) : null );
|
2015-02-03 12:04:13 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( te instanceof EntityPlayer )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return new AdaptorIInventory( new AdaptorPlayerInventory( ( (EntityPlayer) te ).inventory, false ) );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( te instanceof ArrayList )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-12-21 19:08:05 +01:00
|
|
|
@SuppressWarnings( "unchecked" )
|
2015-04-03 08:54:31 +02:00
|
|
|
final ArrayList<ItemStack> list = (ArrayList<ItemStack>) te;
|
2014-12-21 19:08:05 +01:00
|
|
|
|
|
|
|
return new AdaptorList( list );
|
2014-08-12 18:58:24 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( bs != null && bs.isStorageCrate( te ) )
|
2014-08-12 18:58:24 +02:00
|
|
|
{
|
|
|
|
return bs.getAdaptor( te, d );
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( te instanceof TileEntityChest )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-09-28 20:56:16 +02:00
|
|
|
return new AdaptorIInventory( Platform.GetChestInv( te ) );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( te instanceof ISidedInventory )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
ISidedInventory si = (ISidedInventory) te;
|
2014-07-23 18:47:59 +02:00
|
|
|
int[] slots = si.getAccessibleSlotsFromSide( d.ordinal() );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( si.getSizeInventory() > 0 && slots != null && slots.length > 0 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-07-23 18:47:59 +02:00
|
|
|
return new AdaptorIInventory( new WrapperMCISidedInventory( si, d ) );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( te instanceof IInventory )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
IInventory i = (IInventory) te;
|
|
|
|
if( i.getSizeInventory() > 0 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-07-23 18:47:59 +02:00
|
|
|
return new AdaptorIInventory( i );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
// return what was extracted.
|
|
|
|
public abstract ItemStack removeItems( int amount, ItemStack filter, IInventoryDestination destination );
|
|
|
|
|
|
|
|
public abstract ItemStack simulateRemove( int amount, ItemStack filter, IInventoryDestination destination );
|
|
|
|
|
|
|
|
// return what was extracted.
|
|
|
|
public abstract ItemStack removeSimilarItems( int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination );
|
|
|
|
|
|
|
|
public abstract ItemStack simulateSimilarRemove( int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination );
|
|
|
|
|
|
|
|
// return what isn't used...
|
|
|
|
public abstract ItemStack addItems( ItemStack toBeAdded );
|
|
|
|
|
|
|
|
public abstract ItemStack simulateAdd( ItemStack toBeSimulated );
|
|
|
|
|
|
|
|
public abstract boolean containsItems();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|