Search in sources :

Example 6 with ProgException

use of mcjty.rftoolscontrol.logic.running.ProgException in project RFToolsControl by McJty.

the class ProcessorTileEntity method getIngredients.

public int getIngredients(IProgram program, Inventory inv, Inventory cardInv, ItemStack item, int slot1, int slot2) {
    IStorageScanner scanner = getScannerForInv(inv);
    IItemHandler handler = getHandlerForInv(inv);
    if (item.isEmpty()) {
        item = getCraftResult(program);
    }
    if (item.isEmpty()) {
        throw new ProgException(EXCEPT_MISSINGCRAFTRESULT);
    }
    IItemHandler cardHandler = getItemHandlerAt(cardInv);
    ItemStack card = findCraftingCard(cardHandler, item);
    if (card.isEmpty()) {
        throw new ProgException(EXCEPT_MISSINGCRAFTINGCARD);
    }
    CardInfo info = this.cardInfo[((RunningProgram) program).getCardIndex()];
    IItemHandler itemHandler = getItemHandler();
    int slot = slot1;
    List<ItemStack> ingredients;
    if (CraftingCardItem.fitsGrid(card) && (slot2 - slot1 >= 8)) {
        // We have something that fits a crafting grid and we have enough room for a 3x3 grid
        ingredients = CraftingCardItem.getIngredientsGrid(card);
    } else {
        ingredients = CraftingCardItem.getIngredients(card);
    }
    boolean strictnbt = CraftingCardItem.isStrictNBT(card);
    int failed = 0;
    for (ItemStack ingredient : ingredients) {
        int realSlot = info.getRealSlot(slot);
        if (!ingredient.isEmpty()) {
            ItemStack stack = InventoryTools.extractItem(handler, scanner, ingredient.getCount(), true, false, strictnbt, ingredient, null);
            if (!stack.isEmpty()) {
                ItemStack remainder = itemHandler.insertItem(realSlot, stack, false);
                if (!remainder.isEmpty()) {
                    InventoryTools.insertItem(handler, scanner, remainder, null);
                }
            } else {
                failed++;
            }
        }
        slot++;
    }
    return failed;
}
Also used : ProgException(mcjty.rftoolscontrol.logic.running.ProgException) IItemHandler(net.minecraftforge.items.IItemHandler) IStorageScanner(mcjty.rftools.api.storage.IStorageScanner) ItemStack(net.minecraft.item.ItemStack)

Example 7 with ProgException

use of mcjty.rftoolscontrol.logic.running.ProgException in project RFToolsControl by McJty.

the class ProcessorTileEntity method setValueInToken.

public void setValueInToken(IProgram program, int slot) {
    CardInfo info = this.cardInfo[((RunningProgram) program).getCardIndex()];
    int realSlot = info.getRealSlot(slot);
    ItemStack stack = getItemHandler().getStackInSlot(realSlot);
    if (stack.isEmpty() || !(stack.getItem() instanceof TokenItem)) {
        throw new ProgException(EXCEPT_NOTATOKEN);
    }
    if (!stack.hasTagCompound()) {
        stack.setTagCompound(new NBTTagCompound());
    }
    Parameter lastValue = program.getLastValue();
    if (lastValue == null) {
        stack.getTagCompound().removeTag("parameter");
    } else {
        NBTTagCompound tag = ParameterTools.writeToNBT(lastValue);
        stack.getTagCompound().setTag("parameter", tag);
    }
}
Also used : ProgException(mcjty.rftoolscontrol.logic.running.ProgException) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

Example 8 with ProgException

use of mcjty.rftoolscontrol.logic.running.ProgException in project RFToolsControl by McJty.

the class ProcessorTileEntity method getItemFromCard.

public ItemStack getItemFromCard(IProgram program) {
    Parameter lastValue = program.getLastValue();
    if (lastValue == null) {
        throw new ProgException(EXCEPT_MISSINGLASTVALUE);
    }
    ItemStack itemStack = TypeConverters.convertToItem(lastValue);
    if (itemStack.isEmpty()) {
        throw new ProgException(EXCEPT_NOTANITEM);
    }
    if (itemStack.getItem() instanceof CraftingCardItem) {
        return CraftingCardItem.getResult(itemStack);
    }
    if (itemStack.getItem() instanceof TokenItem && itemStack.hasTagCompound()) {
        NBTTagCompound tag = itemStack.getTagCompound().getCompoundTag("parameter");
        if (tag.hasNoTags()) {
            return ItemStack.EMPTY;
        }
        Parameter parameter = ParameterTools.readFromNBT(tag);
        if (parameter == null || !parameter.isSet()) {
            return ItemStack.EMPTY;
        }
        return TypeConverters.convertToItem(parameter);
    }
    return ItemStack.EMPTY;
}
Also used : ProgException(mcjty.rftoolscontrol.logic.running.ProgException) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) CraftingCardItem(mcjty.rftoolscontrol.items.craftingcard.CraftingCardItem)

Example 9 with ProgException

use of mcjty.rftoolscontrol.logic.running.ProgException in project RFToolsControl by McJty.

the class CraftingStationTileEntity method craftOk.

public ItemStack craftOk(ProcessorTileEntity processor, String ticket, ItemStack stack) {
    CraftingRequest foundRequest = null;
    for (CraftingRequest request : activeCraftingRequests) {
        if (ticket.equals(request.getTicket())) {
            foundRequest = request;
            break;
        }
    }
    if (foundRequest != null) {
        markDirty();
        foundRequest.decrTodo();
        if (foundRequest.getTodo() <= 0) {
            foundRequest.setOk(System.currentTimeMillis() + 1000);
        } else {
            processor.fireCraftEvent(ticket, foundRequest.getStack());
        }
        if (!stack.isEmpty()) {
            Inventory inventory = getInventoryFromTicket(ticket);
            if (inventory != null) {
                IItemHandler handlerAt = processor.getItemHandlerAt(inventory);
                if (handlerAt == null) {
                    throw new ProgException(ExceptionType.EXCEPT_INVALIDINVENTORY);
                }
                return ItemHandlerHelper.insertItem(handlerAt, stack, false);
            } else {
                return ItemHandlerHelper.insertItem(getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null), stack, false);
            }
        }
    }
    return stack;
}
Also used : ProgException(mcjty.rftoolscontrol.logic.running.ProgException) IItemHandler(net.minecraftforge.items.IItemHandler) Inventory(mcjty.rftoolscontrol.api.parameters.Inventory) DefaultSidedInventory(mcjty.lib.container.DefaultSidedInventory)

Example 10 with ProgException

use of mcjty.rftoolscontrol.logic.running.ProgException in project RFToolsControl by McJty.

the class ProcessorTileEntity method checkIngredients.

public boolean checkIngredients(IProgram program, @Nonnull Inventory cardInv, ItemStack item, int slot1, int slot2) {
    if (item.isEmpty()) {
        item = getCraftResult(program);
    }
    if (item.isEmpty()) {
        throw new ProgException(EXCEPT_MISSINGCRAFTRESULT);
    }
    IItemHandler cardHandler = getItemHandlerAt(cardInv);
    ItemStack card = findCraftingCard(cardHandler, item);
    if (card.isEmpty()) {
        throw new ProgException(EXCEPT_MISSINGCRAFTINGCARD);
    }
    CardInfo info = this.cardInfo[((RunningProgram) program).getCardIndex()];
    IItemHandler itemHandler = getItemHandler();
    int slot = slot1;
    List<ItemStack> ingredients;
    if (CraftingCardItem.fitsGrid(card) && (slot2 - slot1 >= 8)) {
        // We have something that fits a crafting grid and we have enough room for a 3x3 grid
        ingredients = CraftingCardItem.getIngredientsGrid(card);
    } else {
        ingredients = CraftingCardItem.getIngredients(card);
    }
    int failed = 0;
    for (ItemStack ingredient : ingredients) {
        int realSlot = info.getRealSlot(slot);
        ItemStack localStack = itemHandler.getStackInSlot(realSlot);
        if (!ingredient.isEmpty()) {
            if (!ingredient.isItemEqual(localStack)) {
                return false;
            }
            if (ingredient.getCount() != localStack.getCount()) {
                return false;
            }
        } else {
            if (!localStack.isEmpty()) {
                return false;
            }
        }
        slot++;
    }
    return true;
}
Also used : ProgException(mcjty.rftoolscontrol.logic.running.ProgException) IItemHandler(net.minecraftforge.items.IItemHandler) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ProgException (mcjty.rftoolscontrol.logic.running.ProgException)18 ItemStack (net.minecraft.item.ItemStack)12 GenericEnergyReceiverTileEntity (mcjty.lib.entity.GenericEnergyReceiverTileEntity)8 CraftingStationTileEntity (mcjty.rftoolscontrol.blocks.craftingstation.CraftingStationTileEntity)8 MultiTankTileEntity (mcjty.rftoolscontrol.blocks.multitank.MultiTankTileEntity)8 NodeTileEntity (mcjty.rftoolscontrol.blocks.node.NodeTileEntity)8 WorkbenchTileEntity (mcjty.rftoolscontrol.blocks.workbench.WorkbenchTileEntity)8 TileEntity (net.minecraft.tileentity.TileEntity)8 IItemHandler (net.minecraftforge.items.IItemHandler)8 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)5 BlockPos (net.minecraft.util.math.BlockPos)5 IStorageScanner (mcjty.rftools.api.storage.IStorageScanner)4 NBTTagString (net.minecraft.nbt.NBTTagString)3 DefaultSidedInventory (mcjty.lib.container.DefaultSidedInventory)2 EnergyTools (mcjty.lib.varia.EnergyTools)2 ICompiledOpcode (mcjty.rftoolscontrol.api.code.ICompiledOpcode)2 CompiledCard (mcjty.rftoolscontrol.logic.compiled.CompiledCard)2 CompiledEvent (mcjty.rftoolscontrol.logic.compiled.CompiledEvent)2 CompiledOpcode (mcjty.rftoolscontrol.logic.compiled.CompiledOpcode)2 Nullable (javax.annotation.Nullable)1