Applied-Energistics-2-tiler.../util/inv/IMEAdaptorIterator.java

57 lines
1 KiB
Java
Raw Normal View History

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;
boolean hasNext;
final IMEAdaptor parent;
final int containerSize;
public IMEAdaptorIterator(IMEAdaptor parent, IItemList<IAEItemStack> availableItems) {
stack = availableItems.iterator();
containerSize = parent.maxSlots;
this.parent = parent;
}
@Override
public boolean hasNext()
{
hasNext = stack.hasNext();
return offset < containerSize || hasNext;
}
@Override
public ItemSlot next()
{
slot.slot = offset++;
if ( parent.maxSlots < offset )
parent.maxSlots = offset;
if ( hasNext )
{
IAEItemStack item = stack.next();
slot.setAEItemStack( item );
return slot;
}
slot.setItemStack( null );
return slot;
}
@Override
public void remove()
{
throw new RuntimeException( "Not Implemented!" );
}
}