Applied-Energistics-2-tiler.../src/main/java/appeng/util/InventoryAdaptor.java
Sebastian Hartte 633ea48d42 Cleaned up unused Mod integrations other than for mods that are likely to be integrated soon.
Introduced an easier Facade class to access mod integration abstractions (called Integrations). Removed the link between IntegrationType and integration abstraction. Integrations are now explicitly instantiated inside of IntegrationNode.
2016-11-06 01:03:02 +01:00

124 lines
4.2 KiB
Java

/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2015, 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>.
*/
package appeng.util;
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;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.FuzzyMode;
import appeng.util.inv.AdaptorIInventory;
import appeng.util.inv.AdaptorItemHandler;
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;
/**
* Universal Facade for other inventories. Used to conveniently interact with various types of inventories. This is not used for
* actually monitoring an inventory. It is just for insertion and extraction, and is primarily used by import/export buses.
*/
public abstract class InventoryAdaptor implements Iterable<ItemSlot>
{
// returns an appropriate adaptor, or null
public static InventoryAdaptor getAdaptor( final Object te, final EnumFacing d )
{
if( te == null )
{
return null;
}
if ( te instanceof ICapabilityProvider )
{
ICapabilityProvider capProvider = (ICapabilityProvider) te;
// Attempt getting an IItemHandler for the given side via caps
IItemHandler itemHandler = capProvider.getCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, d );
if( itemHandler != null && itemHandler.getSlots() > 0 )
{
return new AdaptorItemHandler( itemHandler );
}
}
if( te instanceof EntityPlayer )
{
return new AdaptorIInventory( new AdaptorPlayerInventory( ( (EntityPlayer) te ).inventory, false ) );
}
else if( te instanceof ArrayList )
{
@SuppressWarnings( "unchecked" )
final ArrayList<ItemStack> list = (ArrayList<ItemStack>) te;
return new AdaptorList( list );
}
else if( te instanceof TileEntityChest )
{
return new AdaptorIInventory( Platform.GetChestInv( te ) );
}
else if( te instanceof ISidedInventory )
{
final ISidedInventory si = (ISidedInventory) te;
final int[] slots = si.getSlotsForFace( d );
if( si.getSizeInventory() > 0 && slots != null && slots.length > 0 )
{
return new AdaptorIInventory( new WrapperMCISidedInventory( si, d ) );
}
}
else if( te instanceof IInventory )
{
final IInventory i = (IInventory) te;
if( i.getSizeInventory() > 0 )
{
return new AdaptorIInventory( i );
}
}
return null;
}
// 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();
}