Special Handlers are now properly wrapped in IMEMonitors for Storage Bus to function properly.

This commit is contained in:
AlgorithmX2
2014-05-03 19:21:33 -05:00
parent 21e40a5fb3
commit e1c6b18399
11 changed files with 234 additions and 22 deletions
+1 -1
View File
@@ -342,7 +342,7 @@ public class AdaptorIInventory extends InventoryAdaptor
public ItemSlot next()
{
is.slot = x;
is.itemStack = i.getStackInSlot( x++ );
is.setItemStack( i.getStackInSlot( x++ ) );
return is;
}
+147
View File
@@ -0,0 +1,147 @@
package appeng.util.inv;
import java.util.Iterator;
import net.minecraft.item.ItemStack;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.config.FuzzyMode;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.util.InventoryAdaptor;
import appeng.util.item.AEItemStack;
public class IMEAdaptor extends InventoryAdaptor
{
IMEInventory<IAEItemStack> target;
BaseActionSource src;
public IMEAdaptor(IMEInventory<IAEItemStack> input, BaseActionSource src) {
target = input;
this.src = src;
}
IItemList<IAEItemStack> getList()
{
return target.getAvailableItems( AEApi.instance().storage().createItemList() );
}
@Override
public Iterator<ItemSlot> iterator()
{
return new IMEAdaptorIterator( getList() );
}
public ItemStack doRemoveItemsFuzzy(int how_many, ItemStack Filter, IInventoryDestination destination, Actionable type, FuzzyMode fuzzyMode)
{
IAEItemStack reqFilter = AEItemStack.create( Filter );
if ( reqFilter == null )
return null;
IAEItemStack out = null;
for (IAEItemStack req : getList().findFuzzy( reqFilter, fuzzyMode ))
{
if ( req != null )
{
req.setStackSize( how_many );
out = target.extractItems( req, type, src );
if ( out != null )
return out.getItemStack();
}
}
return null;
}
public ItemStack doRemoveItems(int how_many, ItemStack Filter, IInventoryDestination destination, Actionable type)
{
IAEItemStack req = null;
if ( Filter == null )
{
IItemList<IAEItemStack> list = getList();
if ( !list.isEmpty() )
req = list.getFirstItem();
}
else
req = AEItemStack.create( Filter );
IAEItemStack out = null;
if ( req != null )
{
req.setStackSize( how_many );
out = target.extractItems( req, type, src );
}
if ( out != null )
return out.getItemStack();
return null;
}
@Override
public ItemStack removeItems(int how_many, ItemStack Filter, IInventoryDestination destination)
{
return doRemoveItems( how_many, Filter, destination, Actionable.MODULATE );
}
@Override
public ItemStack simulateRemove(int how_many, ItemStack Filter, IInventoryDestination destination)
{
return doRemoveItems( how_many, Filter, destination, Actionable.SIMULATE );
}
@Override
public ItemStack removeSimilarItems(int how_many, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination)
{
if ( filter == null )
return doRemoveItems( how_many, null, destination, Actionable.MODULATE );
return doRemoveItemsFuzzy( how_many, filter, destination, Actionable.MODULATE, fuzzyMode );
}
@Override
public ItemStack simulateSimilarRemove(int how_many, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination)
{
if ( filter == null )
return doRemoveItems( how_many, null, destination, Actionable.SIMULATE );
return doRemoveItemsFuzzy( how_many, filter, destination, Actionable.SIMULATE, fuzzyMode );
}
@Override
public ItemStack addItems(ItemStack A)
{
IAEItemStack in = AEItemStack.create( A );
if ( in != null )
{
IAEItemStack out = target.injectItems( in, Actionable.MODULATE, src );
if ( out != null )
return out.getItemStack();
}
return null;
}
@Override
public ItemStack simulateAdd(ItemStack A)
{
IAEItemStack in = AEItemStack.create( A );
if ( in != null )
{
IAEItemStack out = target.injectItems( in, Actionable.SIMULATE, src );
if ( out != null )
return out.getItemStack();
}
return null;
}
@Override
public boolean containsItems()
{
return !getList().isEmpty();
}
}
+39
View File
@@ -0,0 +1,39 @@
package appeng.util.inv;
import java.util.Iterator;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
public class IMEAdaptorIterator implements Iterator<ItemSlot>
{
Iterator<IAEItemStack> stack;
ItemSlot slot = new ItemSlot();
int offset = 0;
public IMEAdaptorIterator(IItemList<IAEItemStack> availableItems) {
stack = availableItems.iterator();
}
@Override
public boolean hasNext()
{
return stack.hasNext();
}
@Override
public ItemSlot next()
{
IAEItemStack item = stack.next();
slot.setAEItemStack( item );
slot.slot = offset++;
return slot;
}
@Override
public void remove()
{
throw new RuntimeException( "Not Implemented!" );
}
}
+28 -1
View File
@@ -1,11 +1,38 @@
package appeng.util.inv;
import net.minecraft.item.ItemStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.util.item.AEItemStack;
public class ItemSlot
{
public int slot;
public ItemStack itemStack;
// one or the other..
private IAEItemStack aeitemstack;
private ItemStack itemStack;
public void setItemStack(ItemStack is)
{
aeitemstack = null;
itemStack = is;
}
public void setAEItemStack(IAEItemStack is)
{
aeitemstack = is;
itemStack = null;
}
public ItemStack getItemStack()
{
return itemStack == null ? (aeitemstack == null ? null : (itemStack = aeitemstack.getItemStack())) : itemStack;
}
public IAEItemStack getAEItemStack()
{
return aeitemstack == null ? (itemStack == null ? null : (aeitemstack = AEItemStack.create( itemStack ))) : aeitemstack;
}
}