Search in sources :

Example 1 with WorkbenchTileEntity

use of mcjty.rftoolscontrol.blocks.workbench.WorkbenchTileEntity in project RFToolsControl by McJty.

the class ProcessorTileEntity method pushItemsWorkbench.

public boolean pushItemsWorkbench(IProgram program, @Nonnull BlockSide workbench, ItemStack item, int slot1, int slot2) {
    if (item.isEmpty()) {
        item = getCraftResult(program);
    }
    if (item.isEmpty()) {
        throw new ProgException(EXCEPT_MISSINGCRAFTRESULT);
    }
    TileEntity te = getTileEntityAt(workbench);
    if (!(te instanceof WorkbenchTileEntity)) {
        throw new ProgException(EXCEPT_NOTAWORKBENCH);
    }
    IItemHandler cardHandler = getItemHandlerAt(te, EnumFacing.EAST);
    ItemStack card = findCraftingCard(cardHandler, item);
    if (card.isEmpty()) {
        throw new ProgException(EXCEPT_MISSINGCRAFTINGCARD);
    }
    if (!CraftingCardItem.fitsGrid(card)) {
        throw new ProgException(EXCEPT_NOTAGRID);
    }
    CardInfo info = this.cardInfo[((RunningProgram) program).getCardIndex()];
    IItemHandler itemHandler = getItemHandler();
    IItemHandler gridHandler = getItemHandlerAt(te, EnumFacing.UP);
    List<ItemStack> ingredients = CraftingCardItem.getIngredientsGrid(card);
    boolean success = true;
    for (int i = 0; i < 9; i++) {
        ItemStack stackInWorkbench = gridHandler.getStackInSlot(i);
        ItemStack stackInIngredient = ingredients.get(i);
        if (!stackInWorkbench.isEmpty() && stackInIngredient.isEmpty()) {
            // Can't work. There is already something in the workbench that doesn't belong
            success = false;
        } else if (stackInWorkbench.isEmpty() && !stackInIngredient.isEmpty()) {
            // Let's see if we can find the needed ingredient
            boolean found = false;
            for (int slot = slot1; slot <= slot2; slot++) {
                int realSlot = info.getRealSlot(slot);
                ItemStack localStack = itemHandler.getStackInSlot(realSlot);
                if (stackInIngredient.isItemEqual(localStack)) {
                    localStack = itemHandler.extractItem(realSlot, stackInIngredient.getCount(), false);
                    gridHandler.insertItem(i, localStack, false);
                    found = true;
                    break;
                }
            }
            if (!found) {
                success = false;
            }
        } else if (!stackInWorkbench.isEmpty() && !stackInIngredient.isEmpty()) {
            // See if the item matches and we have enough
            if (!stackInIngredient.isItemEqual(stackInWorkbench)) {
                success = false;
            } else if (stackInIngredient.getCount() > stackInWorkbench.getCount()) {
                success = false;
            }
        }
    }
    return success;
}
Also used : ProgException(mcjty.rftoolscontrol.logic.running.ProgException) GenericEnergyReceiverTileEntity(mcjty.lib.entity.GenericEnergyReceiverTileEntity) CraftingStationTileEntity(mcjty.rftoolscontrol.blocks.craftingstation.CraftingStationTileEntity) WorkbenchTileEntity(mcjty.rftoolscontrol.blocks.workbench.WorkbenchTileEntity) NodeTileEntity(mcjty.rftoolscontrol.blocks.node.NodeTileEntity) MultiTankTileEntity(mcjty.rftoolscontrol.blocks.multitank.MultiTankTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) IItemHandler(net.minecraftforge.items.IItemHandler) ItemStack(net.minecraft.item.ItemStack) WorkbenchTileEntity(mcjty.rftoolscontrol.blocks.workbench.WorkbenchTileEntity)

Aggregations

GenericEnergyReceiverTileEntity (mcjty.lib.entity.GenericEnergyReceiverTileEntity)1 CraftingStationTileEntity (mcjty.rftoolscontrol.blocks.craftingstation.CraftingStationTileEntity)1 MultiTankTileEntity (mcjty.rftoolscontrol.blocks.multitank.MultiTankTileEntity)1 NodeTileEntity (mcjty.rftoolscontrol.blocks.node.NodeTileEntity)1 WorkbenchTileEntity (mcjty.rftoolscontrol.blocks.workbench.WorkbenchTileEntity)1 ProgException (mcjty.rftoolscontrol.logic.running.ProgException)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1 IItemHandler (net.minecraftforge.items.IItemHandler)1