Search in sources :

Example 1 with GetFirstStackStartingFromSlotResult

use of am2.utility.GetFirstStackStartingFromSlotResult in project ArsMagica2 by Mithion.

the class FlickerOperatorItemTransport method moveItem.

private boolean moveItem(World worldObj, IInventory inventory, TileEntityCrystalMarker crystalMarkerTE, TileEntityFlickerHabitat habitat, int toMove) {
    boolean itemFound = false;
    ItemStack orgStack = null;
    int currentSlot = 0;
    GetFirstStackStartingFromSlotResult result = InventoryUtilities.getFirstStackStartingFromSlot(inventory, orgStack, currentSlot, crystalMarkerTE.getFacing());
    orgStack = result.stack;
    currentSlot = result.slot;
    while (orgStack != null) {
        if (orgStack != null && InputCanMove(crystalMarkerTE, orgStack, inventory)) {
            ItemStack stackCopy = orgStack.copy();
            int amountToMove = Math.min(toMove, stackCopy.stackSize);
            ItemStack mergeStack = stackCopy.splitStack(amountToMove);
            if (FindOutput(worldObj, habitat, mergeStack, inventory)) {
                //if a valid item was found in input, and a valid output for it was found remove the item from the source
                InventoryUtilities.deductFromInventory(inventory, orgStack, amountToMove - mergeStack.stackSize);
                itemFound = true;
                break;
            } else {
                currentSlot++;
            }
        } else {
            currentSlot++;
        }
        result = InventoryUtilities.getFirstStackStartingFromSlot(inventory, orgStack, currentSlot, crystalMarkerTE.getFacing());
        orgStack = result.stack;
        currentSlot = result.slot;
        if (currentSlot == -1) {
            orgStack = null;
        }
    }
    return itemFound;
}
Also used : GetFirstStackStartingFromSlotResult(am2.utility.GetFirstStackStartingFromSlotResult) ItemStack(net.minecraft.item.ItemStack)

Aggregations

GetFirstStackStartingFromSlotResult (am2.utility.GetFirstStackStartingFromSlotResult)1 ItemStack (net.minecraft.item.ItemStack)1