Search in sources :

Example 1 with TileAdvancedCraftingTable

use of buildcraft.silicon.TileAdvancedCraftingTable in project LogisticsPipes by RS485.

the class AssemblyAdvancedWorkbench method importRecipe.

@Override
public boolean importRecipe(TileEntity tile, ItemIdentifierInventory inventory) {
    if (!(tile instanceof TileAdvancedCraftingTable)) {
        return false;
    }
    TileAdvancedCraftingTable bench = (TileAdvancedCraftingTable) tile;
    ItemStack result = bench.getOutputSlot().getStackInSlot(0);
    if (result == null) {
        return false;
    }
    inventory.setInventorySlotContents(9, result);
    // Import
    for (int i = 0; i < bench.getCraftingSlots().getSizeInventory(); i++) {
        if (i >= inventory.getSizeInventory() - 2) {
            break;
        }
        final ItemStack newStack = bench.getCraftingSlots().getStackInSlot(i) == null ? null : bench.getCraftingSlots().getStackInSlot(i).copy();
        inventory.setInventorySlotContents(i, newStack);
    }
    // Compact
    for (int i = 0; i < inventory.getSizeInventory() - 2; i++) {
        final ItemIdentifierStack stackInSlot = inventory.getIDStackInSlot(i);
        if (stackInSlot == null) {
            continue;
        }
        final ItemIdentifier itemInSlot = stackInSlot.getItem();
        for (int j = i + 1; j < inventory.getSizeInventory() - 2; j++) {
            final ItemIdentifierStack stackInOtherSlot = inventory.getIDStackInSlot(j);
            if (stackInOtherSlot == null) {
                continue;
            }
            if (itemInSlot.equals(stackInOtherSlot.getItem())) {
                stackInSlot.setStackSize(stackInSlot.getStackSize() + stackInOtherSlot.getStackSize());
                inventory.setInventorySlotContents(i, stackInSlot);
                inventory.clearInventorySlotContents(j);
            }
        }
    }
    for (int i = 0; i < inventory.getSizeInventory() - 2; i++) {
        if (inventory.getStackInSlot(i) != null) {
            continue;
        }
        for (int j = i + 1; j < inventory.getSizeInventory() - 2; j++) {
            if (inventory.getStackInSlot(j) == null) {
                continue;
            }
            inventory.setInventorySlotContents(i, inventory.getIDStackInSlot(j));
            inventory.clearInventorySlotContents(j);
            break;
        }
    }
    return true;
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) TileAdvancedCraftingTable(buildcraft.silicon.TileAdvancedCraftingTable) ItemStack(net.minecraft.item.ItemStack) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack)

Aggregations

TileAdvancedCraftingTable (buildcraft.silicon.TileAdvancedCraftingTable)1 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)1 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)1 ItemStack (net.minecraft.item.ItemStack)1